Questions tagged [indicator-constraints]

For questions on constraints controlled by binary variables.

Filter by
Sorted by
Tagged with
19 votes
6 answers
7k views

When to use indicator constraints versus big-M approaches in solving (mixed-)integer programs

Various optimization modeling languages and solvers allow for both indicator constraints (see for example here, here and here) and traditional binary variable and big-M approaches can be used to model ...
AndyT's user avatar
  • 193
13 votes
1 answer
838 views

Representing an indicator function: binary variables and "indicator constraints"

I want to represent the indicator function: $$ \mathbb{1}_{(y=j)}$$ where $y$ is a non negative, integer variable. My attempt is as follows: define a binary variable: $$ z_j =\begin{cases} 1 \qquad\...
Libra's user avatar
  • 937
7 votes
2 answers
368 views

how can I modify my LP to activate the most constraints possible?

Suppose I have a linear program (LP) that has many optimal solutions. Of those optima, I want to find the optimum that activates (aka, "pegs" or "bumps") the largest number of ...
Brannon's user avatar
  • 892
6 votes
2 answers
488 views

Is this constraint with an indicator function nonlinear?

We have two variables $x\geq0$ and $y\in\mathbb{Z}^{0+}$. We have this constraint in our model $$x = \sum_{i = 0}c_i \mathbb{1}_{\{y=i\}}$$ where $c_i$ is a parameter and $\mathbb{1}_{A} = 1$ if $A$ ...
user avatar
6 votes
1 answer
774 views

How are indicator constraints implemented? [duplicate]

I wonder how systems like CPLEX, GUROBI, etc implement indicator constraints. Do they just implement Big M equivalents? If yes, what is then the justification for using them? Edit The question does ...
Clement's user avatar
  • 2,180
5 votes
4 answers
875 views

Rewriting if-then constraints of binary summations

Suppose both $x_{i,j}^{ab}$ and $y_{i,j}^a$ are binaries. Then how can I rewrite the following if-then in linear form? $\sum_b x_{i,j}^{ab} \ge 1 \implies \sum_{i,j} y_{i,j}^a = 0$ I was thinking of ...
linkho's user avatar
  • 177
5 votes
2 answers
525 views

How to convert this if-then constraint to MIP constraint?

How to convert this if-then constraint to MIP constraint? $\text{if } a \geq 0 \text{ then } b=K_1 \text{ else(a <0 ) } \ b =K_2$
SAH's user avatar
  • 294
5 votes
1 answer
590 views

Model "if and only if" indicator constraints in Linear programming

Apologies if this question has been asked, but I haven't been able to find it. I'm modelling something with Gurobi and want to do the following: \begin{align}\text{cond} < \dfrac{1}{3} &\iff x =...
J. Dionisio's user avatar
5 votes
1 answer
150 views

Binary variable to indicate zero probabilities

I have a finite probability distribution $p_1, p_2, \ldots, p_n$ (but these are variables of an optimization problem). Moreover, we have monotonicity, $p_1 \geq p_2 \geq \cdots \geq p_n$. Assume we ...
independentvariable's user avatar
4 votes
2 answers
307 views

Model "If, then" constraint

How to model the following "If, then" type constraint? If $\sum\limits_{i \in I}x_i = 0$ then $\sum\limits_{j \in J}x_{j} = n$ where $x$ are binary variables, $n$ is a known parameter and $...
Farouk Hammami's user avatar
4 votes
3 answers
744 views

Faster implementation of "or" constraints in ILP

I have implemented a set of "or" constraints in my ILP using binary decision variables (as in this method). It works fine for smaller problems, but when I try to increase the number of ...
Animik's user avatar
  • 141
4 votes
3 answers
888 views

How to couple a binary variable to a continuous variable to indicate values greater 0

I have a continuous variable $x_t$. A binary variable $b_t$ should be coupled to $x_t$ such that $b_t$ has the value $1$ if $x_t$ has a value greater than $0$ and $b_t$ has the value $0$ if $x_t$ has ...
PeterBe's user avatar
  • 1,632
4 votes
2 answers
524 views

Formulating the conditional constraint

I want to develop a model extension of capacitated location problem. The variables are a binary $x_i$ and a continuous $Q_i$. The following condition must be satisfied: if $x_i = 0$, $Q_i$ must be ...
Bobby Kurniawan's user avatar
4 votes
1 answer
583 views

Indicator function in math programming

Let $x$ be an integer variable that takes the values $1$, $2$ or $3$. Let $y_1$ and $y_2$ be binary variables. I want to express the two following logical constraints: if $x=2$ then $y_1=1$ if $x=3$ ...
Miquel's user avatar
  • 143
4 votes
1 answer
260 views

Switching of decision variables to be equal to a certain decision variable according to a binary (indicator) variable

I would like to seek some advice on modeling the following: I have two integer decisions variables, $x, x'$, that are either equal or greater than zero and either of them is to be equated to a third ...
Mike's user avatar
  • 707
4 votes
1 answer
292 views

Can you calculate the mean of some MIP variables using linear constraints?

got a lingering question from a graduate course in integer programming that's been bugging me ever since. Is it possible to find the mean of some variables in a MIP without resorting to quadratic ...
gjgutier545's user avatar
3 votes
2 answers
611 views

If-then constraint with continuous variables

I was usually using if-then constraints with integer variables but ended up using continuous variables and got confused. I have variables $x_{ij}\in\mathbb{R}_{\geq 0}$, and would like to force the ...
tcokyasar's user avatar
  • 1,239
3 votes
3 answers
1k views

Converting if conditions to linear constraints

I have an optimization problem and I want to convert the following if conditions to linear constraints: If $(y_1 > U_1)$ and $(m_1)$ and $(E_1)$ then $x_1=1$ If $(y_2 > U_2)$ and $(m_2)$ and $(...
hamta's user avatar
  • 77
3 votes
1 answer
86 views

How to enforce logical implication $\sum_j a_j x_j \le b \implies \sum_j c_j x_j \le d$

Some modeling languages and solvers support indicator constraints of the form $$y=\hat{y} \implies \sum_j a_j x_j \le b,$$ where $y$ is a binary decision variable and $\hat{y}\in\{0,1\}$ is a constant....
RobPratt's user avatar
  • 30.4k
3 votes
1 answer
177 views

If-then condition formulation to avoid variable multiplication

I'm trying to formulate the following logic: If $y_i =1$, then $c_i \leq x_i$ If $y_i =0$, then $c_i \leq 0$ Where $y_i$, $c_i$, and $x_i$ are decision variables. The easy way would be to write: $$c_i ...
Daniel Baquero's user avatar
3 votes
2 answers
468 views

Mocking up conditional statements in LP

I would like to know how if condition statements in linear programming can be reformulated using indicator constraints, and hence solved as a mixed integer linear program. Specifically: 1. Is it ...
Sam's user avatar
  • 161
3 votes
1 answer
291 views

Piecewise function with two variables

I have a square like region centered at the origin, which is divided into 4 sub-regions. Region 1 can formed from by the diagonal of a square, $x + y \leq 0$. Region 2 is formed by joining the center ...
Kumar's user avatar
  • 153
3 votes
1 answer
73 views

Logical equivalencies to modeling an indicator decision variable in transportation problem

I am formulating a model that seeks to minimize the cost of shipping goods from factories to warehouses, where the cost of shipping is independent of the type or amount of goods being shipped (except ...
user620842's user avatar
3 votes
1 answer
470 views

Portfolio optimization with indicator function constraint in CVXPY

I have the following portfolio optimization problem that I want to solve using CVXPY: \begin{align}\min_w&\quad w^\top\Pi\\\text{s.t.}&\quad\sum_{i=1}^nw_i=1\\&\quad w^\top\Sigma w\le\...
Paolo Baudissone's user avatar
3 votes
1 answer
543 views

How to fomulate the following conditional constraint in MILP?

How can I formulate the following conditional constraint to a linear constraint using indicator variables? Please note that all variables are continuous and $c \ge 0$ $\text{1: if} \ c=0 \ \& \ ...
SAH's user avatar
  • 294
3 votes
2 answers
312 views

How to model logic constraint: $y=1$ if $a\le x\le b$ and $y=0$ otherwise?

I am trying to formulate indicator-type of constraints. $y$ is binary $0$ or $1$ and $x$ is a continuous variable. $$ y = \begin{cases} 1, & \text{ if } a \leq x \leq b \\ 0, & \...
GuanghuiLiu's user avatar
3 votes
1 answer
208 views

Conditional constraint with a strict inequality

It's almost this question: Formulating the conditional constraint But there they have non-strict inequality. I have $x_i$ a boolean decision var and $Q_i$ as a nonnegative integer decision variable ...
athing's user avatar
  • 143
3 votes
1 answer
302 views

gurobi bigM constraint vs. epsilon

I am new to mathematical programming and I am trying to implement case specific constrains in Gurobi with Python. I am wondering about how I can implement my constraints in the fastest or most common ...
Mike's user avatar
  • 147
3 votes
1 answer
159 views

How to optimize with "if" constraints

The minimizing problem is the following : $$ \underset{w}{\operatorname{argmin}} \sum_{i=1}^{n}\left[w_{i}\times (\frac{Vw}{\sigma})_{i} - b_{i}\right]^{2}$$ with $V$ a $n\times n$ matrix (covariance ...
FredNgu's user avatar
  • 157
3 votes
1 answer
102 views

Modelling Question

Let $W^C_t$, $W_t$ be binary variables and $p$ an integer variable with $1 \leq p \leq 3$ The variables are related through the following equation: $$W^C_t = \sum_{\theta=1}^{p} W_{t-\theta}$$ I can ...
Clement's user avatar
  • 2,180
2 votes
2 answers
417 views

Using indicator constraint with two variables

I want to use the sum of two binary decision variables (when their sum equals to one) as the condition of Model.AddGenConstrIndicator https://www.gurobi.com/documentation/current/refman/...
Saeid Ghafouri's user avatar
2 votes
1 answer
136 views

Robust way to implement $(x=0) \Rightarrow (y=0)$, with $x$ nonnegative and $y$ binary

I am formulating a MILP in which there is a continuous variable x and a binary variable $y$. In the program formulation there are the following constraints: $Ay\leq x \leq By$ (with $0\leq A\leq B$). ...
Meth's user avatar
  • 424
2 votes
1 answer
245 views

Linearize sum of continuous and boolean variable

For maximizing the objective function $\sum_i{d_i y_i}+ A x - B \cdot \mathbb{I}_{x>0}$, how can I linearize $ A x - B \cdot \mathbb{I}_{x>0}$ term where $d_i, A$ and $B$ are positive constants ...
Al Guy's user avatar
  • 123
2 votes
1 answer
229 views

MILP constrained by the minimum number of satisfied constraints

I have an MILP where we have $$ t_k = \sum_i P_i\cdot C_{ik} : P_i\ \in \{0,1\}, C_{ik} \in I^+ $$ and our model is constrained by the number of times $t_k$ is bigger than a certain value $T_k$. $$ \...
Hisham Al Kayed's user avatar
2 votes
1 answer
66 views

Reformulating to locate the second largest decision variable of a set of decision variables

Consider a set of $A_{vn}$ decision variables such that $A_{v1},A_{v2},\cdots,A_{vn}<A$. While this is the standard formulation finding the maximum value of $A_{vn}$, I would also like to find the ...
Mike's user avatar
  • 707
2 votes
1 answer
97 views

Formulation for choosing how many items to manufacture

I am working on a scheduler for a manufacturing plant. I have currently set it up so the decision variables are set up as binary variables: $x_{m,p,s}$ = 1 if machine m is running part p on shift s ...
Dano's user avatar
  • 55
2 votes
1 answer
181 views

CPLEX Indicator Constraints in Java API

I'm using the Java API of CPLEX (12.6.1 version) to solve a MILP problem. This is how I create 'normal' constraints: ...
rainbow's user avatar
  • 307
2 votes
1 answer
104 views

Formulating indicator constraint set

I am having difficulty formulating the indicator constraints for the following: Consider a set of $A_{n}$ decision variables such that $A_{1},A_{2},⋯,A_{n}<A$. While all of them are integers that ...
Mike's user avatar
  • 707
2 votes
1 answer
191 views

How to transform these conditional constraints to linear integer ones in a more efficient way?

The conditional constraints A and B can be transformed to a set of linear integer constraints as follows: A) $\text{if} \ x_1=0 \ \text{then} \ d_1=1 \ \text{else} \ d_1= 0\\ x_1\in {\rm I\!R}^{\geq ...
SAH's user avatar
  • 294
2 votes
0 answers
122 views

Indicator function for integer variable with inequality constraint

I have $n$ integer variables $\vec{x}$ with the following integer programming problem. $$ COST = \sum^{n-1}_{i = 0} a_i x_i + \sum^{n-1}_{j=0} b_j I(x_j > 0) $$ Here, $a_i, b_j \in \mathbb{R}_+$ ...
Omar Shehab's user avatar
1 vote
2 answers
154 views

Matrix lookup modelling variants

As part of a bigger model I have a matrix of variables $x_{ij} \geq 0$ and a "selector" set of variables $y_j \in \{0,1\}, \sum_j y_j = 1$. From $x_{ij}$ I'd like to get the variables of ...
Christian's user avatar
  • 113
1 vote
1 answer
39 views

if else condition with multiple criteria in MIP

I have problem like below Decision variable x1 >= 0 But it depends on selection variable s1 as binary variable If s1 = 0 then x1= 0 and if s1 = 1 then x1>0 how I can write this as constraint for ...
IEOR's user avatar
  • 13
1 vote
2 answers
243 views

Modeling the product of two variables

Suppose we have two continuous nonnegative variables $X_{1}$ and $X_{2}$ both bounded by the number $M$ from above. I would like to model the following: If $X_{1} > 0$ then $X_{2} = 0$ If $X_{2} &...
Clement's user avatar
  • 2,180
1 vote
1 answer
119 views

How to model this chain of logical implication II

I would like to seek some advice on modeling the following (chain of) logical implication: For instance $\omega_{xz}$ might indicate precedence, i.e., $x$, $z$ being the nodes $x$ and $z$, ...
Mike's user avatar
  • 707
1 vote
2 answers
418 views

Switching of decision variables to be larger than or equal to a decision variable according to an indicator variable value

I would like to seek some advice on modeling the following: I have two integer decisions variables, $x, x'$, that are either equal or greater than zero and either of them is greater than or equal to a ...
Mike's user avatar
  • 707
1 vote
2 answers
176 views

How to express this constraint efficiently?

Let, $\mathcal{C}=\{1,2,\cdots,C\}$, $\mathcal{U}=\{1,2,\cdots,U\}$ $\mathcal{S}_u$ is a subset of $\mathcal{C}$ with $u\in \mathcal{U}$ $d_{u,c}$ is a binary variable with $u=1,2,\cdots,U$ and $c=1,2,...
KGM's user avatar
  • 2,211
1 vote
1 answer
135 views

How to model this chain of logical implication

I would like to seek some advice on modeling the following (chain of) logical implication: For instance $\omega_{xy}$ might indicate precedence, i.e., $x$, $y$ being the nodes $x$ and $y$, ...
Mike's user avatar
  • 707
1 vote
1 answer
54 views

Assistance in formulating implication constraints for inequalities

I would like to seek some advice on modeling the following logical implications, where $\delta$ is a binary variable, $D_{j}$ and $A_{j}$ are nonnegative discrete variables, and $p_{j}$ are ...
Mike's user avatar
  • 707
1 vote
1 answer
75 views

Mixed Integer programming, the big M

In the constraints below, why have they used the big M? What do we look for in order to identify the big M in other questions?
uni_lad's user avatar
  • 37
1 vote
1 answer
180 views

How to write this logical expression with Gurobi + Java, or express it as a big-m formulation

I am trying to write the following expression in Gurobi+Java or Gurobi+python, if it is more practical It could be expressed as a big-M formulation. \begin{equation} \label{const4} \text{D}_{uv} = ...
Hernan19's user avatar