How could I make a Boolean chromosome with Genetic algorithm
1 view (last 30 days)
Show older comments
Ibrahim Ibrahim
on 10 Sep 2015
Commented: Walter Roberson
on 10 Sep 2015
How could I make the fitness function for the GA individuals vector or chromosome.
How could I make the result of the GA equal to ''1 or 0''.
How could I add or returned the fitness value to the GA in order to get goodness.
0 Comments
Accepted Answer
Walter Roberson
on 10 Sep 2015
The fitness function should seldom return 0 or 1; it should return a value which increases as the proposed X gets further away from optimum.
To have a boolean variable, set its minimum to 0, its maximum to 1, and include it in the IntCon (integer constraints) list.
2 Comments
Walter Roberson
on 10 Sep 2015
Example:
function fitness = myfitness(X)
Xnum = X(1:2); %some of the variables are continuous
Xlog = logical(X(3:5)); %some of the variables are logical
%now build some potential contributions that might be turned on or off
parts = [Xnum(1).^2 - Xnum(2).^3, ...
cos(Xnum(1)) * abs(gamma(Xnum(2))), ...
abs(sqrt(Xnum(2)) ];
activeparts = parts(Xlog); %extract the parts corresponding to variables turned on
fitness = sqrt( sum(activeparts.^2) ); %combine the contributions somehow
This make some calculations, decides which parts it wants to use according to the boolean inputs, extracts those contributions, and then combines the contributions. The sqrt() of the sum() of squares is not the only valid way to combine the contributions: I just picked some formula for the example.
More Answers (0)
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!