Condition on optimization variable
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Lenilein
am 23 Jan. 2020
Beantwortet: Lenilein
am 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) ;
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Genetic Algorithm finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!