Condition on optimization variable

8 ビュー (過去 30 日間)
Lenilein
Lenilein 2020 年 1 月 23 日
回答済み: Lenilein 2020 年 1 月 24 日
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) ;

採用された回答

Lenilein
Lenilein 2020 年 1 月 24 日
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;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by