Linear programming with conditional constraints
29 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (3)
Alan Weiss
el 15 de Dic. de 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 comentarios
NN
el 6 de Oct. de 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
Matt J
el 5 de Oct. de 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.
0 comentarios
Matt J
el 5 de Oct. de 2021
Editada: Matt J
el 5 de Oct. de 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,
- b1=1, b2=0,
- x1=10*e1,
- 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,
- b1=0, b2=1,
- 10*e1 <= x1 <= 10*e1 + 9.9*M
- x1=0.1*e1
Here, (3) is the required condition and (2) does not conflict with (3) on the interval -M<=e1<=0.
0 comentarios
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!