How can I set linear constraints in ga algorithm

4 views (last 30 days)
Hi, I want to solve an optimization problem with nonlinear objective function and nonlinear constraints.
The variables are binary integers so I decided to use 'ga' function. When I set the population type as bitstring I could not give linear constraints to the function. For example, I have 50 variables and I divide them into 5 groups each containing 10 variables. Each group must contain one 1 and nine 0 values. That is, if x1=1, the x2:x10 should be zero.
On the other hand when I use intcon and do not set population type, the function ignores mutation, crossover and creation function, and the problem finds a local solution.
How can i combine these two options to solve the problem?

Answers (2)

Alan Weiss
Alan Weiss on 19 Dec 2017
I wonder if using intlinprog with an iterative nonlinear solver along these lines would be successful. Otherwise, you are right that mixed-integer ga does not accept equality constraints. You could try to fake it along the lines of this example, but I don't know how well it would work. You could also try to use bitstring population along with custom mutation and crossover functions that keep your linear constraints satisfied, and a custom creation function that gives feasible population with respect to linear constraints. But that is not so easy to do.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Comments
Engin Berk Özmen
Engin Berk Özmen on 19 Dec 2017
When the variables are integer (intcon is used), the solution is local optimum. Mutation and crossover functions cannot be applied, so not enough population can be generated.solver finds different solutions when the code runs again.
Alan Weiss
Alan Weiss on 19 Dec 2017
In that case, I suggest that you take a much larger population size.
options = optimoptions('ga','PopulationSize',2500);
[x,fval,exitflag,output] = ga(...,options)
For 50 variables I think that a population of 2500 is not unreasonable. 1e4 might be even better. Be warned, the solver will be slow.
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.


Matt J
Matt J on 19 Dec 2017
Edited: Matt J on 19 Dec 2017
From each of your 5 groups, use the equality constraints to eliminate one of the variables. Then you can get rid of your equality constraints altogether. For example, replace x1 with 1-sum(x2:x10) everywhere in your code.
Note that you must likewise transform your plain upper and lower bounds to more complicated inequality constraints. For example 0<=x1<=1 now becomes
0<=sum(x2:x10)<=1
  1 Comment
Engin Berk Özmen
Engin Berk Özmen on 19 Dec 2017
When we use bitstring as population type, all of the constraints supplied by the user are ignored. Therefore, during the generation this constraint must be satisfied. I guess I should use custom functions.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!