About the initial population in Genetic Algorithm Toolbox
3 views (last 30 days)
Show older comments
I have a problem in generating an initial population which meets the constraints in using the Genetic Algorithm Toolbox.
The test problem is as follows:
There are two integral variables x1 and x2. Both of them can only be 0 or 1. The objective function is: z=x1+x2.The constraint is x1+x2<2.
The codes are:
options=gaoptimset('InitialPopulation',[1 0]); A = [ 1 1]; b = 1; lb = zeros(2,1); ub=ones(2,1); intcon=[1 2]; [x,fval,exitflag] = ga(@test,2,A,b,[],[],lb,ub,[],intcon,options);
%******************************************************************** function [y]=test(X) y=-X(1)-X(2); end
To check the initial population generated by the ga toolbox, one line(bold) is added in the file of makeState.m:
% If InitialPopulation is partly empty we will use the creation function to % generate population (CreationFcn can utilize InitialPopulation) if sum(options.PopulationSize) ~= size(options.InitialPopulation,1) % If initial population is empty and we know one feasible individual then % assign it to InitialPopulation if ~isempty(Iterate.x) && isempty(options.InitialPopulation) options.InitialPopulation(1,:) = Iterate.x'; fprintf('makeState: InitialPopulation is not used, Iterate.x\n'); end fprintf('makeState: InitialPopulation is partially used, feval\n'); state.Population = feval(options.CreationFcn,GenomeLength,FitnessFcn,options,options.CreationFcnArgs{:}); assignin('base','InitialPopulationSet',state.Population); % evalin('base','InitialPopulationSet=state.Population');
However, I found a problem with the initial population when x1,x2 are integers(intcon=[1 2]). Some of them do not meet the constraint of x1+x2<2 InitialPopulationSet =
1 0
0 0
0 0
1 0
* 1 1*
1 0
0 0
* 1 1*
0 0
1 0
0 1
1 1
0 1
0 1
0 0
......
When I set intcon=[], which means the constrint of integer is released for x1 and x2, all the initial population meet the constraints: InitialPopulationSet =
1.0000 0
0 0
1.0000 0
0 1.0000
0.2381 0.7619
0.5074 0.4926
0.7263 0.2737
0.3194 0
0 0.2737
1.0000 0
0.2910 0.3516
0.8405 0.0000
0.3612 0.6388
0.5074 0.4926
0.0000 0.0000
......
Can anybody help me to explain why does this situation happen? If the place where I obtain the initial population is wrong, where can I get it correctly?
Thank you very much!
Tony
0 Comments
Answers (0)
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!