<p>Here are answers to your two questions. The details will depend upon which solver you are using:</p>

<ul>
<li><p>Ensuring that $w$ and $x$ are assigned values before $y$ and $z$ can often be done programmatically by expressing the variable ordering used by the solver. That is, specifying which variables the solver tries to find values for first. This is possible, for example, in the <a href="http://www.emn.fr/z-info/choco-solver/">choco</a> solver (which is a constraint satisfaction problem (CSP) solver not one for LP or MILP), though I'm sure other solvers offer this possibility too.</p></li>
<li><p>The <a href="http://www.gnu.org/software/glpk/">GNU Linear Programming Kit</a> actually has an <code>if-then-else</code> construct for expressing conditionals. Look for "conditional" in the <a href="http://www.dep.ufmg.br/professores/miranda/EPD065/lang.pdf">manual</a>. You could wrap the clauses you are interested in in such a statement: <code>if U1 + U2 &lt; T2 then y = 0 and z = 0 else true</code>. (Note that I haven't actually tried this, so the syntax may be wrong.)</p></li>
<li><p>An alternative answer to the second question takes advantage of the fact that $U1$, $U2$ and $T1$ are constants. Simply, have two variants of the LP problem, one for when $U1 + U2 &lt; T1$ and one for when $U1 + U2 \ge T1$. </p></li>
</ul>

CC BY-SA 2.5
2010-11-02T11:11:56.277Z
Thanks for the options. I will go with option 3 for now.
Bala
CC BY-SA 2.5
2010-11-01T09:23:43.030Z
2010-11-01T09:31:55.123Z
2010-11-01T09:31:55.123Z
Dave Clarke
<p>I have the following LP:</p>

<pre>
/* Objective function */
min: 1 w + 2 x + 0.5 y + z;

/* Variable bounds */
w + x &lt;= T1;
w + y = U1;
x + z = U2;
T1 = 50;
U1 = 70;
U2 = 25;

</pre>

<p>In this case U1 + U2 > T1 and the optimal solution is y = 70 and z = 25. I want to enforce the condition that w and x variables be assigned values before assigning values to y and z. If U1 + U2 &lt; T1, then I want only w and x to have values and y = z = 0. Is there a way to enforce such a constraint in an LP or an MILP?</p>

CC BY-SA 2.5
2010-11-01T07:42:54.140Z
not sure why the downvote: it's a reasonable, albeit narrow question in LPs
Suresh Venkat
<linear-programming>
LP formulation for if-conditions
Bala
# LP formulation for if-conditions

(Asked by: username_0 on 2010-11-01)

I have the following LP:

/* Objective function */
min: 1 w + 2 x + 0.5 y + z;

/* Variable bounds */
w + x <= T1;
w + y = U1;
x + z = U2;
T1 = 50;
U1 = 70;
U2 = 25;


In this case U1 + U2 > T1 and the optimal solution is y = 70 and z = 25. I want to enforce the condition that w and x variables be assigned values before assigning values to y and z. If U1 + U2 < T1, then I want only w and x to have values and y = z = 0. Is there a way to enforce such a constraint in an LP or an MILP?

**Tags:** linear-programming

> **Comments:**
> **username_1**: not sure why the downvote: it's a reasonable, albeit narrow question in LPs  

---

## 1 answers

### Answer by username_2 on 2010-11-01. Score: 11 | Accepted answer

Here are answers to your two questions. The details will depend upon which solver you are using:

* Ensuring that $w$ and $x$ are assigned values before $y$ and $z$ can often be done programmatically by expressing the variable ordering used by the solver. That is, specifying which variables the solver tries to find values for first. This is possible, for example, in the [choco](http://www.emn.fr/z-info/choco-solver/) solver (which is a constraint satisfaction problem (CSP) solver not one for LP or MILP), though I'm sure other solvers offer this possibility too.
* The [GNU Linear Programming Kit](http://www.gnu.org/software/glpk/) actually has an `if-then-else` construct for expressing conditionals. Look for "conditional" in the [manual](http://www.dep.ufmg.br/professores/miranda/EPD065/lang.pdf). You could wrap the clauses you are interested in in such a statement: `if U1 + U2 < T2 then y = 0 and z = 0 else true`. (Note that I haven't actually tried this, so the syntax may be wrong.)
* An alternative answer to the second question takes advantage of the fact that $U1$, $U2$ and $T1$ are constants. Simply, have two variants of the LP problem, one for when $U1 + U2 < T1$ and one for when $U1 + U2 \ge T1$.

> **Comments:**
> **username_0**: Thanks for the options. I will go with option 3 for now.  

---

