Genetic Algorithm with Custom Functions

3 次查看(过去 30 天)
Iro
Iro 2014-4-4
编辑: Iro 2014-4-4
Hi,
I am using GA with Custom functions for Population Creation , FitnessFcn , CrossOver and Mutation . I run it either from the GA app or the command line, by setting the population size, the nr of generations, and elite and Crossover fraction.
The individuals that myCreatePop function gives are nxn matrices which have 0 and 1 as elements. This makes me put this nxn product as the number of variables (This is correct, right?). The functions of myCreatePop , myMutationFcn and myCrossoverFcn apply a condition for every parent or kid (offspring or mutated), for this individual to be accepted and counted in the output of each function. This condition is that the graph represented by this matrix is not disconnected (nr of components=1).
myFitnessFcn returns a vector with the scores of each individual matrix.
When it comes to Scaling and Selection , I use ' Proportional ' and ' Roulette ' respectively from the default functions.
One of the problems I have when I run GA is when it comes to plotting (' Conversion from cell to double is not possible ') which for now I have skipped solving by unchecking the plot boxes in GA app.
The other problem is when my algorithm selects the parents for myCrossoverFcn and myMutationFcn their sum does not match the population size which I want to be constant over the generations. This means that If I have a PopSize=10 , Elite count=2 , CrossOver fraction =0.5 , I want my new generation to have the 2 best parents remaining, and then 4 crossover offsprings and 4 kids coming from mutated parents. Instead what I get is a total nKids=12, of which 8 appear in myCrossOverFcn Output and 4 in my myMutationFcn output.
Moreover, when the Algorithm moves to the evaluation of the new generation individuals, it comes up with 14 of them (I guess it is then that it adds the 2 elites).
When I tried the same with CrossOver Fraction=0.8 , I got 12 CrossOver Offsprings, and 2 Mutation kids, and then a total of 16 individual to be evaluated in the new generation.
At this point (after myFitnessFcn returns the scores vector of the first generation), I get the error: 'Subscripted assignment dimension mismatch.'
Is there anyting I am missing wrt to CrossOver Fraction ? And how can I manipulate these parameters in order to have a constant population size (with elites included)?
Thanks!

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by