Condition on optimization variable

9 views (last 30 days)
Lenilein
Lenilein on 23 Jan 2020
Answered: Lenilein on 24 Jan 2020
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]; % Start point (row vector)
lb=[0 0]; % lower bound for x
ub=[1 1]; % upper bound for x
nvars=2; % Number of variables
Intcon=1:2; % the variable x has to take integer values
A=[]; % Equality constraint
b=[]; % Equality constraint
Aeq=[]; % Inequality constraint
beq=[]; % Equality constraint
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) ;

Accepted Answer

Lenilein
Lenilein on 24 Jan 2020
After the little research I was able to figure out the solution:
I can define a new Matrix B=abs(A-1) which I then integrate as an inequality constraint as follows:
A=[B];
b=0;

More Answers (0)

Community Treasure Hunt

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

Start Hunting!