Reputation:
I am trying to solve an optimization problem using the MATLAB ga() function.
I will try to be as brief as possible. It is basically a least-squares fitting problem, where I manipulate some inputs to try and match a target function. The problem has 40 variables. There are bound constraints, linear equalities, linear inequalities, and nonlinear constraints.
Before I was letting MATLAB choose the initial population, but the results were poor. I felt this was due to a lack of diversity in MATLAB's choices. So I coded a function that would create an initial population that satisfied all of the constraints except for the nonlinear constraints (these are calculated post-simulation).
I Googled and found only one question on the MATLAB Central Exchange which pertained to this same topic, and it was from 2007 and never resolved.
Here is the section of the code that might have a problem. I am sorry that it is so big, but I think it is laid out quite logically. I am using ga(problem), and the bulk of this code is simply listing all of the constraints.
ineq_con_tau_LB = [zeros(1,nInjections) zeros(1,nInjections) tau_LB/60/1e6 tau_LB/60/1e6 tau_LB/60/1e6 0]
ineq_con_tau_UB = [zeros(1,nInjections) zeros(1,nInjections) 0 0 -tau_UB/60/1e6 0]
problem_structure.Aineq = [ineq_con_tau_LB; ineq_con_tau_UB];
problem_structure.bineq = [nInjections*CP.reactorVolume;-nInjections*CP.reactorVolume];
eq_con_antisolvent = [ones(1,nInjections) zeros(1,nInjections) -1 0 0 0];
eq_con_puresolvent = [zeros(1,nInjections) ones(1,nInjections) 0 -1 0 0];
problem_structure.Aeq = [eq_con_antisolvent; eq_con_puresolvent];
problem_structure.beq = [0 0]';
%Upper and lower bounds.
Atotal_min = 10; Atotal_max = 1000;
Stotal_min = 10; Stotal_max = 1000;
Vfeed_min = 10; Vfeed_max = 1000;
ypercent_min = 0.02;
ypercent_max = 0.07;
problem_structure.lb = [ zeros(1,nInjections) zeros(1,nInjections) Atotal_min Stotal_min Vfeed_min ypercent_min];
problem_structure.ub = [repmat(inf,1,nInjections) repmat(inf,1,nInjections) Atotal_max Stotal_max Vfeed_max ypercent_max];
problem_structure.nonlcon = @constr;
problem_structure.nvars = 2*nInjections + 4;
problem_structure.fitnessfcn = @objfun;
problem_structure.intcon = [];
populationsize = 5;
gapop = dissolution_optimization_initialpop(populationsize,nInjections,problem_structure.Aineq, ...
problem_structure.bineq, ...
problem_structure.lb(:), ...
problem_structure.ub(:), ...
tau_LB, ...
tau_UB, ...
ypercent_min, ...
ypercent_max);
problem_structure.options = gaoptimset('Generations', 25,...
'PopulationSize',populationsize, ...
'InitialPopulation',gapop, ...
'OutputFcn', @sse_outputfcn, ...
'MutationFcn', {@mutationadaptfeasible});
problem_structure.options
save('gapop_save','gapop')
[x,fval,exitflag,output] = ga(problem_structure)
Any help that can be provided is greatly appreciated. Please help! :(((
Upvotes: 0
Views: 911
Reputation:
Thank you for your help.
I actually fixed this myself a while ago, and you are correct. The initial population did not follow the constraints.
Or, rather, they did not obey them at the precision the matlab GA wanted them to. The constraints were satisfied to within 1e-15. But that still was not good enough and MATLAB would reject those samples unless the equalities were dead-on "0".
Upvotes: 0
Reputation: 31
If this is happening, the first thing to do is check and make sure that the initial population is not violating the bounds, linear, or equality constraints. Matlab will ignore members of the initial population that do not satisfy these constraints.
Andrew
Upvotes: 1