Linear programming with conditional constraints

조회 수: 30 (최근 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 CenterFile Exchange에서 Solver 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