Dear Community,
I am trying to solve an optimization problem (below) with the optimization variable x which elements can be either 0 or 1.
I have a parameter A that has the same length as x and which elements are also either 0 or 1. I would like to "freeze" the element values of x for which the elements of A are 0, which could be written that way:
for k=1:numel(A); if A==0; x=0; end
What I mean with "freezing" is that I would like the elements for which x is set to zero to be excluded from the optimization and remain at the value of 0.
However I am confused about how to formulate this condition and integrate it into the code.
Any help appreciated!
fun=@(x)(sum(XObjInvestcosts(x)));
nonlcon=@(x)YConstraintCO2(x);
x0=[0 0];
lb=[0 0];
ub=[1 1];
nvars=2;
Intcon=1:2;
A=[];
b=[];
Aeq=[];
beq=[];
INIPOP=[0 0];
options = optimoptions('ga','MaxGenerations',15,'MaxStallGenerations',Inf,'PlotFcn',@gaplotbestf,'InitialPopulationMatrix',INIPOP);
[x,Fval,exitFlag,Output] = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,Intcon,options) ;