Questions tagged [logical-constraints]

For questions about constraints that can be expressed in (usually propositional) logic.

Filter by
Sorted by
Tagged with
3 votes
2 answers
338 views

How to model a binary variable?

I am trying to find a constraint for the following relationship, but am failing a bit at it right now. I want to find a linear constraint that does the following. The binary variable $switch_{ot}$ is ...
mingabua's user avatar
5 votes
4 answers
829 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
  • 163
1 vote
1 answer
49 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
4 votes
3 answers
480 views

How can I formulate this 'if-then' constraint problem?

I have five integer variables, and I need to write some constraints on them: $x_0$ , $[x_1, x_2, x_3, x_4 ]$. $1 \leq x_i \leq 3$ if $x_0 =1$ then no constraint on $[x_1, x_2, x_3, x_4 ]$ if $x_0 =...
Optimization team's user avatar
2 votes
1 answer
38 views

A tighter relaxation of the mix logical constraints

Suppose the following logical form there exists. $$Iff: (x_{j,m} \land x_{k,m}) \implies ((C_{j} \leq S_{k}) \lor (C_{k} \leq S_{j}))$$ This is well-known as a no_overlap_constraint in the parallel ...
A.Omidi's user avatar
  • 7,569
3 votes
2 answers
326 views

How to model C1 = C2 implies b1 = b2

Suppose $C_1 \ge 0$, $C_2 \ge 0$ are continuous variables and $b_1$, $b_2$ are binary variables. How could I model the following? $C_1 = C_2 \implies b_1 = b_2$, the opposite does not hold.
Clement's user avatar
  • 2,132
2 votes
2 answers
349 views

Representing "and"/"or" relationships into constraints

How do I represent the following constraints in terms of equations? For each i, either (1) holds or (2) holds- $$ x_{1}^i \geq x_{2}^i \quad and \quad x_{3}^i \geq x_{4}^i \quad {(1)} $$ $$ x_{1}^i \...
T_k's user avatar
  • 77
3 votes
1 answer
61 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
  • 28.1k
3 votes
3 answers
214 views

Equivalence between constraints in ILP

Let's have binary variables $x$ and $y$. I'd like to define a helping binary variable $z$ such that $$ z = 1 \; \;\; \mathrm{iff} \; \; \; x + y = 2.$$ If I wanted to express the equivalence between ...
tomashauser's user avatar
2 votes
0 answers
54 views

The linearization of the logical constraints

I know the logical constraints can be linearized by either the logical representation of whose relation, (for pure binary variables e.g. CNF/DNF) or for general form by using Big-M formulation. As I ...
A.Omidi's user avatar
  • 7,569
4 votes
2 answers
283 views

The linearization of the (Iff-and-only-Iff) expression

I am trying to linearize the following expression without using the Big-M formulation, but I cannot convert it. I am willing to know if there exists an efficient way to do that? $$ Iff \quad (w=1) \...
Mr. Blue's user avatar
0 votes
1 answer
57 views

Maximization problem with preferences on variables

Consider the following trivial, theoretical model: $$ \max x+2y+3z \qquad s.t. $$ $$ x \leq b_x $$ $$ y \leq b_y $$ $$ z \leq b_z $$ $$ x+y+z = 1 $$ $$ x,y,z \in \{0, 1\} $$ and $b_x$, $b_y$ and $b_z$ ...
Libra's user avatar
  • 927
2 votes
2 answers
214 views

Linearizing a disjunctive expression into MILP

I want to linearize the following disjunctive form. $$\left[\begin{gathered}w_{1}\\x \geq a\end{gathered}\right] \vee \left[\begin{gathered}w_{2}\\x \geq b\end{gathered}\right]$$ where $w_1$ and $w_2$...
A.Omidi's user avatar
  • 7,569
3 votes
3 answers
567 views

Modelling if elif else conditions as MIP

I have 4 variables. Xl6, Xs6, Pl6, Ps6. I have a constant C as well. Xl6 and Xs6 are binary whereas Pl6 and Ps6 are integers. Also, all variables can take only positive values. I have to implement ...
mufassir's user avatar
  • 181
3 votes
3 answers
264 views

Set null the next set of N values

I'm dealing with a problem I already modelled by using linear programming. The already existing constraints set at 1 groups of contiguous variables (for ex: ...
devOn's user avatar
  • 33
-1 votes
2 answers
84 views

How to apply smooth approximation to non-linear complementarity constraints?

$P =$ $ x, if U \geq U^{max} $ $ y, if U^{up} < U < U^{max} $ $ z, if U^{down} < U < U^{up} $ $ \alpha, if U^{min} < U < U^{down} $ $ \beta, if U \leq U^{min} $ Where $P$, and $U$ ...
Ghulam Mohy-ud-din's user avatar
2 votes
1 answer
119 views

Piecewise constraint using big-M notation

I have a piecewise constraint that I am having a hard time converting using big-M modelling. The context is a gym owner that is updating membership costs subject to churn restrictions. The owner can ...
akkha's user avatar
  • 43
4 votes
1 answer
333 views

How can I transform this logical if-then constraint? [duplicate]

I want to know how to transform this logical if-then constraint? If $B=1$,then $A \ge C$, else $A=0$, where $A$ and $B$ are decision variables and $C$ are constants. $B$ is binary variable and $A\ge 0$...
Alan Zhang's user avatar
1 vote
1 answer
162 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
5 votes
3 answers
195 views

MIP constraint with sum of decision variables having certain value : $\sum_{i=1}^nx_i = 2 \implies \delta = 1$

I want to formulate a MIP constraint such that : $$\sum_{i=1}^nx_i = 2 \implies \delta = 1$$ $x_i, \delta \in \{0, 1\}$. My problem is that delta should be one when this sum is exactly 2 and not ...
tonythestark's user avatar
2 votes
1 answer
390 views

If/then constraint formulation

Let's assume we have event $i=1,2,\cdots,k$, denoted as $\text{event}_i$. We know for a fact that $\text{event}_i$ is smaller then $\text{event}_{i+1}$ i.e., $\text{event}_i \leq \text{event}_{i+1}$. ...
OpenAtTheClose's user avatar
2 votes
1 answer
118 views

Conditional constraint for binary

Could you please check where I might be wrong? Task is: If $z=1$, then either $x=1$ or $y=1$ My approach: If $z=1$, then $x+y=1$ $\implies x+y\le1$ $\implies x+y\ge1$ If $z=0$, then $x+y\ge0 - M\cdot(...
Bohdana Nevierova's user avatar
3 votes
2 answers
196 views

Can we use continuous variables instead of binary variables in this NLP problem?

The following problem is defined with binary variables $a_{i1}, a_{i2}, a_{i3}, k_1$ and $k_2$. Is it possible to avoid binary variables and to only work with continuous variables? How would we ought ...
Steven01123581321's user avatar
4 votes
3 answers
420 views

How to transform a logical constraint with integer variables?

Consider the binary variables $x_1, x_2 \in \{0,1\}$ and the integer variable $y \in \mathbb{Z}$ with $0 \leq y \leq 3$. I'd like to formulate the following logical constraint: $$ x_1 = 1 \wedge y \...
Ronaldinho's user avatar
2 votes
1 answer
170 views

Binary variable constraint for condition

I am trying to solve the following task: If $x=1$ or $y=0$ then $z=0$ My approach: If $z=0$ then $x+y \le 2 + Mz \implies x+y \le 2+2z \quad$ where $M = 2$ If $z=1$ then $x+y=1 \\ \implies x+y \le 1, ...
Bohdana Nevierova's user avatar
0 votes
1 answer
54 views

Conditional constraint for binary variables

I would appreciate any help to solve the following task: If $y=1$ then $x_i=1$ for at least $k$ of the possible indices $i\in\{1,\cdots,n\}$ where $k$ and $n$ are parameters, $x$ is a binary variable ...
Bohdana Nevierova's user avatar
2 votes
2 answers
73 views

How to model this?

$i$ is a set $1$ to $n$. $j$ is a set $1$ to $m$. $j$ and $k$ are from the same set such that $j\neq k$. $c_{ij}$ is a parameter. $x_{ij}$ and $y_{j}$ are binary variables. How to model: If $$c_{ij}\...
user avatar
5 votes
2 answers
238 views

Binary variable constraint

The task is to ensure that if $x_i = 1$ for at least $k$ of the possible indices $i$ in $\{1,...,n\}$ then $y = 1$, where $k$ and $n$ are parameters, $x$ is a binary variable vector with $n$ elements, ...
Bohdana Nevierova's user avatar
3 votes
1 answer
263 views

Binary variables constraint

What constraints would you write to ensure that if $x = 1$ then $y = 0$ where $x, y$ are binary variables? Until now I only learnt how to build the constraint with 3 binary variables, therefore the ...
Bohdana Nevierova's user avatar
4 votes
1 answer
69 views

Another difficult constraint for an ILP

How can I add to this ILP with all binary variables (again related to this question): $$\min \sum_{1\leq i<j\leq n-1-h} t_{i,j}$$ $$\sum_{i=1}^{n-1-h} a_{k,i} \ge \lfloor (n-1)/2\rfloor \qquad \...
BillyJoe's user avatar
  • 393
5 votes
3 answers
611 views

Constraint for two binary vectors to be different

If I have a matrix $A$ of binary variables $a_{i,j}$, $1 \le i \le n$, $1 \le j \le m$, how can I enforce in an Integer Linear Program with binary variables, the condition that every two columns must ...
BillyJoe's user avatar
  • 393
3 votes
2 answers
98 views

How to model if-then?

$i$ is a set $1$ to $n$. $j$ is a set $1$ to $m$. $j$ and $k$ are from the same set such that $j\neq k$. $c_{ij}$ is a parameter. $x_{ij}$ is a binary variable. How to model: If $$c_{ij}\cdot x_{ij} \...
user avatar
1 vote
3 answers
194 views

How to linearize this if-then constraint?

If $x \ge 1$ then $y = y + x$. And, if $x \le 0$ then $y = y$, where $x$ and $y$ are non-negative integer decision variables. I am using GLPK solver. How do I linearize this if-then constraint?
Ajinkya Bankar's user avatar
3 votes
2 answers
227 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
240 views

Unexpected runtime error

I have a model that contains the sets (both ordered and Days also circular): Days and Personnel, and I'm trying to make a restriction run exaclty once per Day for every member of Personnel. I'm using ...
Cyrus Roettern's user avatar
4 votes
1 answer
175 views

Creating constraints dynamically in pyomo abstract model

I have a networkX graph with few nodes and these nodes have attributes such as "demand". ...
Waqas Swati's user avatar
3 votes
2 answers
62 views

Constrained shift assignment problem using ilogcp solver can´t find an optimal solution

I´ve been trying to solve a contrained assignation problem given a set of constraints based in a real-world problem. I modeled the problem in AMPL as follows: ...
Cyrus Roettern's user avatar
1 vote
1 answer
178 views

PULP : Constraint violation - multiple of expected value

I am developing a linear programming model in PULP that sends material from Origin Facilities to Transfer and Final Treatment Facilities. The objective function is based on summing the transport and ...
rossb97's user avatar
  • 11
11 votes
0 answers
131 views

which method has been used to automatically reformulate logical constraints in a standard MIP solver?

There are many of the formulations to linearize logical constraints by introducing new auxiliary binary or any appropriate variables and adding the corresponding constraints to the model. It can be ...
A.Omidi's user avatar
  • 7,569
3 votes
1 answer
268 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
  • 133
3 votes
1 answer
239 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
135 views

Disjunctive Constraint , Using Binary Variable to Replace a If or condition

I am trying to use a binary variable based on an inequality. The value of binary variable $q $ is 1 or 0 based on the following equation. [ $q $ = \begin{cases} 0,& \text{if } b \geq \pi ,\\ 1,...
Danish Shaikh's user avatar
2 votes
3 answers
349 views

How to formulate if-then for two sums in an integer program

I have two sets of Boolean variables, $x_1, \dots, x_n$ and $y_1, \dots, y_m$ and a positive integer $b$. I would like to add the constraint: $$\text{If }\sum_i x_i = b \text{ then }\sum_i y_i > b$...
Simd's user avatar
  • 131
3 votes
3 answers
778 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
5 votes
1 answer
139 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
3 votes
1 answer
212 views

Disjunctive equality constraints: modelling

I have the following constraint in my model: $$x = 0 \lor \sum_{i=1}^n y_i = 3$$ where $x$ and $y_i$ are all binary variables. How this can be linearized by means of big-M notation? Should I include ...
ORLover's user avatar
  • 33
7 votes
4 answers
914 views

is prime? in Operations Research

Is there a way to linearize is prime? in Operations Research? is prime(n) being true if $n$ is a prime number or false otherwise....
JKHA's user avatar
  • 583
2 votes
1 answer
64 views

Ensure that scheduled repeating maintenance has to be completed

I'm trying to model the scheduling of maintenance in some machines, and was wondering how I could ensure that, if maintenance is planned to start in period $t$, then it has to be carried out until ...
J. Dionisio's user avatar
2 votes
1 answer
281 views

Gurobi add constraint which two variables cant be zero at the same time

I'm currently using Gurobi in python and trying to add a constraint that the variable will not equal to 0 at the same time, say a != 0 or b != 0, both a and b can ...
pigsun's user avatar
  • 145
3 votes
1 answer
371 views

Constraint on groups of variables

Assume a LP/MILP with a large number of variables. It is easy to formulate constraints to group variables such that each variable in a group takes the same value, if we know which variables are in a ...
Jonn's user avatar
  • 333