Integer constrained ga generates initial population violate linear constraints

2 views (last 30 days)
I am using ga to solve a problem with linear constraints and integer variables. However, besides the [0 0 0] I assigned into the initial population, the rest of randomly generated ones in the initial population would ignore the constraints. Since I have only inequality linear constraints, it should have no problem to satisfy them even with integer variables. Anyone has a clue what is the problem?
Cap = 90;
Low = 60;
demand_predict = [76, 74, 78];
nvar = 3;
A = [-1, -1, -1; 2, 0, 0; 0, 2, 0; 0, 0, 2;...
-2, 0, 0; 0, -2, 0; 0, 0, -2];
b = [0; Cap-demand_predict(1); Cap-demand_predict(2); Cap-demand_predict(3);...
-Low+demand_predict(1); -Low+demand_predict(2); -Low+demand_predict(3)];
Aeq = [];
beq = [];
lb = [-10 -10 -10];
ub = [10 10 10];
nonlcon =[];
IntCon = 1:nvar;
InitialPop = [0 0 0];
objfunc = @(y)objfunc_stochastic(y, parameter1, parameter2);
options = gaoptimset('PopulationSize',5,'Generations',10,'InitialPopulation', InitialPop,'UseParallel','Always','PlotFcns',@gaplotbestf);
[y,fval,exitflag,output,population] = ga(objfunc, nvar, A, b, [], [], lb, ub, [], IntCon, options);
For example, I can see [8 6 -2] be generated, which violates the second constraint.

Answers (1)

Matt J
Matt J on 27 Jun 2014
Edited: Matt J on 27 Jun 2014
For example, I can see [8 6 -2] be generated, which violates the second constraint.
Generated yes, but returned as a solution? I imagine GA gives itself the freedom to generate points that violate A*x<=b, but then discard them once it discovers that they don't satisfy the constraints.
Incidentally, the constraints A(2:end,:)<=b(2:end) are all simple bound constraints. It makes more sense to lump them in with lb, ub. If you do, I think you will find that GA does not generate points outside those bounds. In other words, it is easier for GA to confine the population evolution a priori to simple bounds. So, by giving GA better information about which constraints are bounds and which are more complicated, you help it do an appropriately narrower search.
  2 Comments
Kang-Ching Chu
Kang-Ching Chu on 27 Jun 2014
Edited: Matt J on 27 Jun 2014
Thank for your answer.
I also just realized that I should use ub and lb for the constraints 2:end, that is a much better way to do this.
I did not get a chance to see if it returns a solution with variables that violate constraints, since my objective function cannot be evaluated if y does not fit the constraints.
I am a little bit surprised if it generate points (initially or by mutation/corssover) that violate constraints and discards them after fitness evaluation. Since it is a waste to compute fitness with those points, and in this MATLAB document ( http://www.mathworks.com/help/gads/examples/constrained-minimization-using-the-genetic-algorithm.html ), it says: "The way the ga satisfies the linear and bound constraints is to use mutation and crossover functions that only generate feasible points."
Matt J
Matt J on 27 Jun 2014
Edited: Matt J on 27 Jun 2014
since my objective function cannot be evaluated if y does not fit the constraints.
Easy enough to fix that.
I am a little bit surprised if it generate points (initially or by mutation/corssover) that violate constraints and discards them after fitness evaluation. Since it is a waste to compute fitness with those points,
You haven't said what evidence you see that this is occurring. If it is occurring, however, I would be surprised also.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!