MATLAB Answers

feval distorted in ga after using nonlinearconstr

18 views (last 30 days)
Tsuwei Tan
Tsuwei Tan on 25 Feb 2021
Commented: Tsuwei Tan on 28 Mar 2021 at 16:59
I am using Genetic Algoritm
to find the global min with nvar=6. and the options includes a nonlinear constraint function called ssp_constraint. U and ssp are passing parameters.
function [c, ceq]=ssp_constraint(x,U,ssp)
% c is inequality and ceq is equality
[minin, I]=min(SSP_r);
% c=[I-40;1485-minin];
% True of False
The issue is if I have two inequality constraints instead of one in this ssp_constraint function, in my case , change
then the fval from ga is skewed to a negative value and contiune to search; my objective function cost_fun is written to spit out a positive value, and latter generation should approach from some positve vale to zero.
I am using a High Performace Computer to conduct parallell computation, the options in ga is
options = optimoptions('ga','UseParallel', true, 'UseVectorized', false,...
I write a fucntion ga_save_each_gen to save each generation
function [state,options,optchanged]=ga_save_each_gen(options,state,flag)
savefolder='result' ; % Save to the subfolder
if isfolder(savefolder)==0; mkdir(savefolder); end
%ga does not accept changes in options, and ignores optchanged.
save(['./' savefolder '/gen_' num2str(Generation_gen,'%.4d') '.mat'],'Score_gen','Population_gen','Generation_gen')
So I should see the saved variable Score_gen which is a vector with the size (63,1) at seach saved gen_xxxx.mat
Please advise what I did wrong? Thank you!
  1 Comment
Tsuwei Tan
Tsuwei Tan on 27 Feb 2021
It seems to me that
[mini, Index ]=min(any_input);
that Index output is not allowed inside the non linear constraint function.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 27 Feb 2021
The main thing I see that looks out of place is that is the role of SSP_restored_1st15day. If it is a variable, I cannot see where it is defined, but regardless it certainly doesn't depend on the input unknown vector x. If the constraints are not a function of x, that can have crazy effects.
Incidentally also, the constraint
is linear. ga() would deal with linear constraints more effectively if you used the A,b,Aeq,beq inputs to handle them.
  1 Comment
Tsuwei Tan
Tsuwei Tan on 28 Mar 2021 at 16:59
When IntCon is nonempty, Aeq and beq must be an empty entry ([]), and nonlcon must return empty for ceq. For more information on integer programming, see Mixed Integer ga Optimization.
Finally figure out why.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!