Reputation: 53
I am using genalg package for Genetic Algorithm. The gene is binary is nature and the result will specify
The length of the gene is 269 and it is difficult to understand which is difficult to comprehend. Is there a way to extract the result from this and have it in a data frame?
cat(summary.rbga(GAmodel))
GA Settings
Type = binary chromosome
Population size = 100
Number of Generations = 100
Elitism = TRUE
Mutation Chance = 0
Search Domain
Var 1 = [,]
Var 0 = [,]
GA Results
Best Solution : 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0
I want to convert the Best Solution to a data frame, so that I can actually look up which are the items that I need to pick.
class(GAmodel) = "rbga"
Upvotes: 3
Views: 1895
Reputation: 61
For a minimization optimization solved to variable GAModel
bestSolution<-GAmodel$population[which.min(GAmodel$evaluations),]
This pulls the index of the best chromosome from GAmodel$evaluations, based on the fitness function. Using the index, it then returns the full chromosome from the last population which was evaluated.
Upvotes: 6
Reputation: 63
Well there's certainly an issue with the output of genalg, here's how I managed to extract the best solution:
Upvotes: 1