MATLAB Answers


How to write noonlinear equality constraints in ga?

Asked by Maryam on 13 Dec 2018
I am trying to write a "ga" code in matlab. The code without constraint does work correctly. I need to define a constraint as follow:
function [c,ceq] = mycon(~)
global MDLAC
ceq = [];
c = [(MDLAC - 1);
which "MDLAC", defines as:
MDLAC = ((abs(delta_f'*round_f))^2)/((delta_f'*delta_f)*(round_f'*round_f));
"delta_f" is a vector consists of numbers, and "round_f" consists of numbers and variables.
Now my problem is that I cannot use both parts of "C" in constraint function. In other words if in constraint function I define "C" as follow:
c = MDLAC - 1;
c =(-1)*MDLAC);
the code runs perfectly, but when I use it as I mentioned earlier in this note (as a combination of two terms) the code gives me an error as follow:
Unable to perform assignment because the left and right sides have a different
number of elements.
Error in augLagFun>augLagScalarFun (line 155)
[cin(:),ceq(:)] = feval(nonlcon,points,conFcnArg{:});
Error in augLagFun (line 24)
lagrangeFval = augLagScalarFun(points,objfun,nonlcon,augLagStruct, ...
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore =
Error in gacon (line 39)
state = makeState(GenomeLength,SubFitness,Iterate,subtype,options);
Error in ga (line 405)
[x,fval,exitFlag,output,population,scores] =
gacon(FitnessFcn,nvars, ...
Error in complete_code_3D_2 (line 318)
[x, fval,exitflag,output,population] =
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot
I will appreciate it so much if you could help me through this. Thank you.


Sign in to comment.

0 Answers