How to avoid unnecessary optimvar variable declarations in Problem Based Optimization Models?

조회 수: 11 (최근 30일)
Hi, I have the following piece of code:
X = optimvar('X',{Nodes,Nodes,Trees},'LowerBound',0,'UpperBound',1,'Type','integer');
Y = optimvar('Y',{Nodes,Trees},'LowerBound',0,'UpperBound',1,'Type','integer');
for k = 1:K
for i = 1:n
X(i,i,k).UpperBound = 0;
for j = i + 1:n
X(j,i,k).UpperBound = 0;
end
end
end
I want the decision variable X(i,j,k) be created only for i < j for example. Or some parameter C(i,j) > 0. What is the best way to do that in order to avoid loops.
Best Regards Ramiro
  댓글 수: 1
Matt J
Matt J 2018년 2월 23일
I would hope that you don't have to care. There's a chance that the problem-based optimization engine is smart enough to pre-detect extra variables for which LowerBound=UpperBound and do the appropriate problem simplification for you internally.

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2018년 2월 23일
편집: Matt J 2018년 2월 23일
Or some parameter C(i,j) > 0.
X = optimvar('X',[1,nnz(C>0)], 'LowerBound',0,'UpperBound',1,'Type','integer')
but you would have to reformulate the objective and other constraints to accomodate the linear indexing.

Community Treasure Hunt

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

Start Hunting!

Translated by