Linear programming with conditional constraints

29 views (last 30 days)
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

Answers (3)

Alan Weiss
Alan Weiss on 15 Dec 2020
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 Comments
NN
NN on 6 Oct 2021
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

Sign in to comment.


Matt J
Matt J on 5 Oct 2021
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 on 5 Oct 2021
Edited: Matt J on 5 Oct 2021
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.

Community Treasure Hunt

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

Start Hunting!