Linear programming with conditional constraints

7 ビュー (過去 30 日間)
Blenda Moreira
Blenda Moreira 2020 年 12 月 14 日
コメント済み: NN 2021 年 10 月 6 日
Hello,
I'm trying to figure out a way to formulate a linear program to solve an optimization problem with the following constraints:
x1 = 10*e1 if e1>=0
x1 = 0,1*e1 if e1<0
x1 and e1 are variables of the problem.
All the other constraints are regular linear expressions.
Is it possible to model with a linear programming solution?
Is it possible to solve using linprog or intlinprog? If so, how can I do this?
Thanks

回答 (3 件)

Alan Weiss
Alan Weiss 2020 年 12 月 15 日
I think that you can do this with mixed-integer linear programming. Create auxiliary binary variables y1 and y2. These variables track whether e1 is positive or not. Assume that M is an upper bound on abs(e1). Include the constraints
e1 <= M*y1; % This enforces y1 = 1 whenever e1 > 0
e1 + M*y2 >= 0; % This enforces y2 = 1 whenever e1 < 0
y1 + y2 = 1;
So now you have y1 as the indicator that e1 > 0 and y2 as the indicator that e1 < 0.
I am not sure at this point how to include y1 and y2 into your problem formulation, but maybe you can figure it out from here.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  14 件のコメント
NN
NN 2021 年 10 月 6 日
Ok
NN
NN 2021 年 10 月 6 日
I have used debugger and getting this error for the line
prob.constraints.batt1= PbattV <= 16500*y1V; % This enforces y1 = 1 whenever PbattV > 0
prob.constraints.batt2= PbattV + 16500V*y2V >= 0; % This enforces y2 = 1 whenever PbattV< 0
prob.constraints.batt3= y1V + y2V == 1;
  • Unrecognized method, property, or field 'constraints' for class 'optim.problemdef.OptimizationProblem'.
Is there any formatting problem ?
Thanks

サインインしてコメントする。


Matt J
Matt J 2021 年 10 月 5 日
All the other constraints are regular linear expressions.
If that's true then just divide the problem into two subproblems, one with the constraints,
x1 = 10*e1
e1>=0
and the other with the constraints,
x1 = 0.1*e1
e1<=0
Whichever of these two linear sub-programs gives you the most optimal objective value is the solution that you accept.

Matt J
Matt J 2021 年 10 月 5 日
編集済み: Matt J 2021 年 10 月 5 日
Asume a bound e1<=M, and introduce additional binary variables b1 and b2 with the constraints.
%(1)
e1 <= M*b1; %This enforces b1 = 1 whenever e1 > 0
e1 + M*b2 >= 0; % This enforces b2 = 1 whenever e1 < 0
b1 + b2 = 1;
10*e1 <= x1, x1 <= 10*e1 + 9.9*M*b2 %(2)
0.1*e1 <= x1, x1 <= 0.1*e1 + 9.9*M*b1 %(3)
When 0<=e1<=M, the above reduces to,
  1. b1=1, b2=0,
  2. x1=10*e1,
  3. 0.1*e<=x1<=0.1*e1 +9.9*M
Note that (2) is what is required and (3) does not conflict with (2) on 0<=e1<=M
Similarly when -M<=e1<=0,
  1. b1=0, b2=1,
  2. 10*e1 <= x1 <= 10*e1 + 9.9*M
  3. x1=0.1*e1
Here, (3) is the required condition and (2) does not conflict with (3) on the interval -M<=e1<=0.

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by