How to write noonlinear equality constraints in ga?

1 vue (au cours des 30 derniers jours)
Maryam
Maryam le 13 Déc 2018
Hello,
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);
((-1)*MDLAC)];
end
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;
or
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 =
FitnessFcn(state.Population(initScoreProvided+1,:));
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] =
ga(@obj_func_3D,3,[],[],[],[],lb,ub,@mycon,options)
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot
continue.
I will appreciate it so much if you could help me through this. Thank you.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by