Clear Filters
Clear Filters

MATLAB ga() genetic algorithm not changing part of the decision vector

4 views (last 30 days)
Hi fellow Matlabbers,
I am solving an optimization problem with the genetic algorithm, ga().
I will try to keep my explanation simple.
There are 9 variables. The first 5 have no equality or inequality constraints; only bound constraints. That last 4 however, do have constraints. They are meant to be fractions of a given quantity. As such, their constraints are:
1. They must sum to 1.
2. They are bounded between 0 and 1.
3. As a separate matter, they are monotonically decreasing.
I have implemented the problem using the optimization problem structure:
bmps.solver = 'ga'; bmps.Aineq = [0 0 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 0 0; ...
0 0 0 0 0 -1 1 0 0; ...
0 0 0 0 0 0 -1 1 0; ...
0 0 0 0 0 0 0 -1 1];
bmps.bineq = [0 0 0 0 0 0 0 0 0]';
Matlab wants the linear inequality constraints to be of the form Aineq*x <= bineq, so this is how I have expressed wanted x(6) through x(9) to be monotonically decreasing.
Thee first 5 variables have no linear equality constraint. The last 4, which are antisolvent must sum to 1.
bmps.Aeq = [0 0 0 0 0 1 1 1 1];
bmps.beq = [1];
The bounds on the first 5 variables are arbitrary; don't worry about them. The last 4 are fractions of 1, and so are bounded between 0 and 1.
bmps.lb = [1 1 1 1 100 0 0 0 0];
bmps.ub = [5 5 5 5 500 1 1 1 1];
There is no nonlinear or integer constraints.
bmps.nonlcon = [];
bmps.intcon = [];
Here are other fields of the problem structure:
bmps.nvars = 9;
bmps.fitnessfcn = @(x) bimodal_obj_fun(x);
popsize = 100;
For my initial population of the 6th through 9th variables, I use the same vector:
[0.4 0.3 0.2 0.1]
The options structure is:
bmps.options = gaoptimset('Generations', 100,...
'PopulationSize', popsize,...
'InitialPopulation',initialpop,...
'OutputFcn', @mb_outputfcn, ...
'MutationFcn', @mutationadaptfeasible);
The problem is that these values never change. Every sample in every generation has no trouble manipulating the 1st through 5th variables, but the 6th through 9th always stay the same.
Can anyone suggest why this is?
Thanks, and all the best,
-Brad

Answers (1)

Alan Weiss
Alan Weiss on 28 Oct 2013
The main problem is your initial population. You gave all identical values for the last four components in your entire initial population. That is why nothing changes.
Another problem, not so bad, is the first six row of your A and b matrices. Get rid of them. They don't do anything but make the solver work harder checking nothing.
I suggest that you give no initial population at all. Then I think ga will work decently.
But if you really want to solve an optimization problem, as opposed to experimenting with algorithms, I suggest you try patternsearch instead of ga. If your problem is smooth (differentiable objective function) then I think fmincon would be even better. For either fmincon or patternsearch, you can take random initial points if you like.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Products

Community Treasure Hunt

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

Start Hunting!