0

I am trying to perform an optimization using Pyomo but I am struggling to define a constraint for a problem like this:

if Variable 1 > Parameter
    Variable 2 = Variable 1 - Parameter
else skip constraint (?)

if Parameter > Variable 1
    Variable 3 = Variable 4 -(Parameter - Variable 1)
else skip constraint (?)

Does this work somehow? About the skip constraint: I am not quite sure if that is even necessary.

Basically, I just want to express the relations between the Variables and the Parameters.

I have seen something similar here (Mixed integer programming: variable assignment per condition (if then else)) but I am not able to adjust it to my problem.

Thanks in advance!

Community
  • 1
  • 1
AWi
  • 1
  • 1
  • It's a bit unclear, what exactly you are trying to achive and it seems you are missing some basics. If you want to constraint some variable to some half-bound or a value depening on the value of another one, you need to add this constraint (which will be converted to linear equations) always to the model (or the solver is not able to reason about this). This means, that your **skip constraint** does not make any sense. This pseudocode looks more like Constraint-programming-based approaches than Mixed-integer programming. Split your task: add binary indicator-constraints and big-M values. – sascha Sep 28 '16 at 12:37
  • I basically just started working with constraints, etc. so I guess I want to include too much at once. Thanks, I will look into those two methods you mentioned. – AWi Sep 28 '16 at 14:01
  • Start with [this](http://download.aimms.com/aimms/download/manuals/AIMMS3OM_LinearProgrammingTricks.pdf). Indicator-constraints and big-M approaches are both explained. – sascha Sep 28 '16 at 14:02

1 Answers1

0

We know very little about the rest of the model, so my answer is in all likelihood much overkill.

x1>p => x2=x1-p can be expressed as:

y1=x1-p
-d*M <= y1 <= (1-d)*M
y1-d*M <= x2 <= y1+d*M
d in {0,1}

Here M is a large constant (we would need to find good values for these big-M's). Similar for the other condition.

In almost all cases we can use more knowledge of the rest of the model to simplify this (by a lot). So in practice you would not use my general formulation.

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39