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!

3
  • 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. Commented Sep 28, 2016 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. Commented Sep 28, 2016 at 14:01
  • Start with this. Indicator-constraints and big-M approaches are both explained. Commented Sep 28, 2016 at 14:02

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer. I just now trying to apply your format to the actual code, but I dont fully understand the function of the big_M's.
The big-M's are large constants needed to turn equations on or off.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.