Condition on optimization variable
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lenilein
el 23 de En. de 2020
Respondida: Lenilein
el 24 de En. de 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 comentarios
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Genetic Algorithm en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!