12
$\begingroup$

For continuous variables $x$ and $y$, the constraints are:

if x >= 0 and x < 1 then y <= 10 and
if x >= 1 and x < 2 then y <= 5 and

(up to the ten lines of inequalities)

if x >= 2 then y <= 2

The problem is on modeling nonlinear behaviour of gas storage pumping efficiency, which decreases for high load in case of very large gas storages (decrease is seen for storages with capacity above 5 million cubic meters). I have to write these constrains using MIP (or LP) formulation. I can use SOS1/SOS2 variables in GAMS with cplex/gurobi solvers.

$\endgroup$
5
  • 1
    $\begingroup$ Similar question at: stackoverflow.com/questions/41009196/… $\endgroup$
    – Stradivari
    Commented Oct 19, 2019 at 11:28
  • $\begingroup$ @Stradivari its similar, but my problem somehow simpler (only one variable between 'if' and 'then') and more structured (each equation is slightly modified repetition of previous one) $\endgroup$
    – Qbik
    Commented Oct 19, 2019 at 15:09
  • $\begingroup$ X-posted: math.stackexchange.com/q/3399937/339790 $\endgroup$ Commented Oct 19, 2019 at 15:16
  • $\begingroup$ @Qbik, if you could define an upper/lower bound or initial value for your problem variables then, with if-then or if-else GAMS functions, you would go ahead. What you are looking for might be like this: variable x,y; equation e; e.. y =e= ifthen(x<1,(1+x)/2,sqrt(abs(x))); x.fx = -1; model m /all/; solve m minimizing x using dnlp; $\endgroup$
    – A.Omidi
    Commented Oct 19, 2019 at 19:32
  • $\begingroup$ @abbas omidi dnlp is overkill $\endgroup$
    – Qbik
    Commented Oct 20, 2019 at 12:54

1 Answer 1

9
$\begingroup$

Let's just consider one constraint, since they all have the same form:

if x >= 0 and x < 1 then y <= 10 and

First, you really can't test for $x<1$, with a strict inequality. The best you can do is something like $x \le 1-\delta$, for small $\delta$. So I'll assume you're taking that approach.

Introduce a new binary variable $z$ that equals 1 if the "if" condition ($x \ge 0$ and $x\le \delta$) holds. To do this, you can use two more binary variables: $w_1=1$ if $x\ge 0$ and $w_2 = 1$ if $x \le \delta$. See this Q&A for a discussion of how to set those variables: In an integer program, how I can force a binary variable to equal 1 if some condition holds?

Then you can set $z$ using:

$$\begin{align*} z & \le w_1 \\ z & \le w_2 \\ z & \ge w_1 + w_2 - 1 \end{align*}$$

Finally, you can enforce the implication "if $z=1$ then $y\le 10$" using the discussion here: In an integer program, how can I “activate” a constraint only if a decision variable has a certain value?

Other related posts:

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.