We have to select warehouses for serving customers
We have to select warehouses for serving customers
N
warehouses and M
customersi
should be served by a single warehousei
has a demand di
j
has a limited capacity ci
ti,j
for serving customer i
from warehouse j
Goal: find the assignment that minimizes the cost
How do we model the problem?
How do we model the problem?
A first alternative
xi∈{0..n−1},∀i=0..m−1
How does it fare with the constraints?
"Each customer i
should be served by a single warehouse"
"Each customer i
should be served by a single warehouse"
"Each warehouse j
has a limited capacity ci
"
"Each customer i
should be served by a single warehouse"
"Each warehouse j
has a limited capacity ci
"
We can tackle the problem by changing the representation...
Second alternative: "inverted" approach
We can tackle the problem by changing the representation...
Second alternative: "inverted" approach
We can tackle the problem by changing the representation...
Third alternative: binary model
xi,j∈{0,1},∀i=0..m−1,j=0..n−1
The typical modeling approach in Integer Linear Programming
How does it fare with the constraints?
"Each customer i
should be served by a single warehouse"
∑j=0..n−1xi,j=1,∀i=0..m−1
"Each warehouse j
has a limited capacity ci
"
∑i=0..m−1dixi,j≤cj,∀j=0..n−1
There is a travel cost ti,j
for serving customer i
from warehouse j
min
We managed to model the problem! But:
We managed to model the problem! But:
Is there another alternative?
We manage to model the problem! But:
Is there another alternative?
x_i \in \{0..n-1\}
variablesd_i
for warehouse j
if x_i = j
t_{i,j}
for warehouse j
if x_i = j
We could achieve both goals by treating constraints as expressions:
z = (x_i = j)
Intuitively:
z = 1
iff the constraint x_i = j
is satisfiedz = 0
iff the constraint is not satisfiedOur notation:
(c)
between brackets is reifiedA meta-constraint is a constraint over reified constraints
Example: warehouse capacity as a meta-constraint:
\sum_{i=0..m-1} d_i \, (x_i = j) \leq c_j, \quad \forall j = 0..n-1
Example: assignment costs using reified constraints:
\min\ f(x) = \sum_{j = 0..n-1} \sum_{i = 0..m-1} t_{i,j} \, (x_i = j)
Essentially:
How does it work in practice?
GAC for reified constraints:
The (original) domain D(c)
of a reified constraint is always \{0, 1\}
1
in D(c)
has a support iff c
can be feasible0
in D(c)
has a support iff c
can be infeasibleGAC for reified constraints:
The (original) domain D(c)
of a reified constraint is always \{0, 1\}
1
in D(c)
has a support iff c
can be feasible0
in D(c)
has a support iff c
can be infeasibleExamples:
Consider the constraint x \leq y
:
x \in \{0, 1\}, y \in \{0, 1\} \longrightarrow D(x \leq y) = \{0, 1\}
x \in \{1\}, y \in \{0\} \longrightarrow D(x \leq y) = \{0\}
x \in \{0, 1\}, y \in \{1\} \longrightarrow D(x \leq y) = \{1\}
Filtering Rules
Let (c)
be the reification of constraint c
. Start by filtering c
. Then:
\longrightarrow 1 \notin D(c)
c
is resolved \longrightarrow 0 \notin D(c)
c_j = \prod_{x_i \in X(c_j)} D(x_i)
i.e. if all the possible assignments are feasible.
Filtering Rules
Let (c)
be the reification of constraint c
. Start by filtering c
. Then:
\longrightarrow 1 \notin D(c)
c
is resolved \longrightarrow 0 \notin D(c)
Some comments:
The first rule is simple to implement
Filtering Rules
Let (c)
be the reification of constraint c
. Start by filtering c
. Then:
\longrightarrow 1 \notin D(c)
c
is resolved \longrightarrow 0 \notin D(c)
Some comments:
For the second, we need to check whether c
is resolved:
(c)
c
once all variables are boundIn practice, the approach is typically used for =, \neq, <, \leq, >, \geq
Meta-constraints are extremely powerful modeling tools
However, they are not always the best choice:
And the last point deserves some discussion...
Consider the following expression:
2\, (x = 0) + 3\, (x = 1)
With x \in \{0, 1\}
Consider the following expression:
2\, (x = 0) + 3\, (x = 1)
With x \in \{0, 1\}
D(x = 0) = D(x = 1) = \{0, 1\}
\begin{align}
& lb = 2\times 0 + 3\times 0 = 0 \\
& ub = 2\times 1 + 3\times 1 = 5
\end{align}
0
and 5
But the true bounds are 2
and 3
In a few chapters we will see how to address this
We need to schedule a meeting:
When can the meeting take place?
We need to schedule a meeting:
When can the meeting take place?
M, Tu, W, Th, Fr \in \{0, 1\}
(M \vee W \vee Th)
\wedge (\neg W)
\wedge (\neg F)
\wedge (\neg Tu \wedge \neg Th)
= 1
We need to schedule a meeting:
When can the meeting take place?
M = 1
, Tu, W, Th, F = 0
Our problem is an instance of the:
It's a special type of CSP:
\in \{0, 1 \}
)\text{logical expression} = 1
"Remember a SAT instance is in the form:
\text{logical expression} = 1
We need support for logical expressions/constraints
All logical expressions can be obtained starting from three operators:
\wedge, \vee, \neg
Other operators are not strictly necessary, but useful in practice:
\Rightarrow, \Leftrightarrow, \oplus (xor)
So, those are the constraints that we should add
All logical expressions can be obtained starting from three operators:
\wedge, \vee, \neg
Other operators are not strictly necessary, but useful in practice:
\Rightarrow, \Leftrightarrow, \oplus (xor)
So, those are the constraints that we should add
Let's consider a "Not" constraint:
z = \neg x
Let's consider a "Not" constraint:
z = \neg x
And the following expression/constraint over binary variables:
z = (1 - x)
Let's consider a "Not" constraint:
z = \neg x
And the following expression/constraint over binary variables:
z = (1 - x)
They have the same semantic
z = 1
iff x = 0
z = 0
iff x = 1
Let's consider a "Not" constraint:
z = \neg x
And the following expression/constraint over binary variables:
z = (1 - x)
And we get GAC filtering!
0 \in D(z)
has a support iff 1 \in D(x)
1 \in D(z)
has a support iff 0 \in D(x)
The filtering rules for x are analogous
Take-home message:
z = \neg x
is not necessaryz = (1 - x)
The two are totally equivalent (for binary variables)
Let's see if it works with other logical expressions...
Let's consider an "and" constraint:
z = x \wedge y
Let's consider an "and" constraint:
z = x \wedge y
And the arithmetic expression (
z = x \, y
So, we can use the product to model the "and" operator
Alternative: use z = \min(x, y)
Let's consider an "or" constraint:
z = x \vee y
Let's consider an "or" constraint:
z = x \vee y
And the arithmetic expression (
z = \max(x, y)
So, we can use max to model the "or" operator
So, we have an arithmetic equivalent for all basic operators
We can get the other logical operators by combining the basic ones:
x \Rightarrow y
is equivalent to \neg x \vee y
x \Leftrightarrow y
is equivalent to (x \wedge y) \vee (\neg x \wedge \neg y)
x \oplus y
is equivalent to (\neg x \wedge y) \vee (x \wedge \neg y)
It's bit verbose, though. E.g.:
x \Leftrightarrow y
becomes \max(x\,y, (1-x)\, (1-y))
Can we find a more compact formulation?
Let's consider an "implication" constraint:
z = (x \Rightarrow y)
Let's consider an "implication" constraint:
z = (x \Rightarrow y)
And the expression (over binary variables):
z = (x \leq y)
It's a meta constraint!
\leq
" constraint\Rightarrow
" operator
Let's consider the equivalence constraint:
z = (x \Leftrightarrow y)
Let's consider the equivalence constraint:
z = (x \Leftrightarrow y)
And consider the meta-constraint (over binary variables):
z = (x = y)
=
" constraint\Leftrightarrow
" operator
Let's consider the exclusive-or constraint:
z = (x \oplus y)
Let's consider the exclusive-or constraint:
z = (x \oplus y)
And consider the meta-constraint (over binary variables):
z = (x \neq y)
\neq
" constraint\oplus
" operator
\Rightarrow
, \Leftrightarrow
, \oplus
\Rightarrow
, \Leftrightarrow
, \oplus
!Reified constraints shine when used in logical expressions
Some examples:
"If x = 1
, then y
must be positive"
(x = 1) \leq (y > 0)
"x
and y
are either both non-negative or both negative"
(x \geq 0) = (y \geq 0)
"Variable x
is either less then -1 or greater than 1"
(x < -1) \neq (x > 1)
Although this is not necessarily a good idea:
And the last point deserves (again) some discussion...
A meta-constraint is in fact a network of constraints:
A meta-constraint is in fact a network of constraints:
Classical example:
(x = 1) \neq (x = 2), \quad \text{with } x \in \{0, 1, 2\}
x = 1
, x = 2
and (x = 1) \neq (x = 2)
are GAC with domain \{0,1\}
x = 0
is not feasibleLet's consider a simple production scheduling problem:
O
of orders i \prec j
between some ordersP
i
has a deadline d_i
r_i
if an order is processed by the deadlineWhich variables? Start times!
s_i \in \{0..eoh\}
With eoh = |O|
How do we model the resources?
s_i \neq s_j \quad \forall i, j \in O, i < j
How do we model the precedences?
s_i < s_j \quad \forall (i,j) \in P
And what about the revenues?
They define our cost function:
\max z = \sum_{i \in O} r_i
(s_i \leq d_i)
And what about the revenues?
They define our cost function:
\max z = \sum_{i \in O} r_i
(s_i \leq d_i)
So, our full model is:
\begin{align}
\max z = \ & \sum_{i \in O} r_i (s_i \leq d_i) \\
\text{subject to: } & s_i \neq s_j & \forall i, j \in O, i < j \\
& s_i < s_j & \forall (i,j) \in P \\
& s_i \in \{0..eoh\} & \forall i \in O
\end{align}
We need to schedule activities in an industrial workshop.
m
activities, to be performed in sequencen
jobs to be scheduledj
-th activity in the i
-job is called a_{i,j}
a_{i,j}
has non-negative duration d_{i,j}
m
machinesm
activities requires a different machinea_{i,j}
requires machine m(a_{i,j})
Objective: complete all jobs as soon as possible
Which variables? Start times!
Which variables? Start times!
s_{i,j} \in \{0..eoh\}, \quad \forall i = 0..n-1, j = 0..m-1
With \displaystyle eoh = \sum_{\substack{i = 0..n-1\\ j = 0..m-1}} d_{i,j}
Ordering constraints for each job:
s_{i,j} + d_{i,j} \leq s_{i,j+1} \quad \forall i = 0..n-1, j = 0..m-2
Cost function: minimize the makespan (maximum end time)
\min z = \max_{i = 0..n-1} \left(s_{i,m-1} + d_{i,m-1} \right)
The tricky part is handling the resources...
\neq
constraintsLet's parse "cannot run in parallel" for a_{i,j}
and a_{h,k}
The tricky part is handling the resources...
\neq
constraintsLet's parse "cannot run in parallel" for a_{i,j}
and a_{h,k}
a_{i,j}
ends before a_{h,k}
startsa_{h,k}
ends before a_{i,j}
startsThis can be stated using meta constraints:
(s_{i,j} + d_{i,j} \leq s_{h,k}) \vee (s_{h,k} + d_{h,k} \leq s_{i,j})
For all i,j,h,k
such that m(i,j) = m(h,k)
So we get a first model for the job-shop scheduling problem:
\begin{align}
\min z =\, & \max_{i = 0..n-1} \left( s_{i,m-1} + d_{i,m-1}\right)\\
\text{subject to:}\ & s_{i,j} + d_{i,j} \leq s_{s,j+1}
\hspace{48mm}
\forall i = 0..n-1,\ j = 0..m-2\\
& (s_{i,j} + d_{i,j} \leq s_{h,k}) \vee (s_{h,k} + d_{h,k} \leq s_{i,j})
\quad
\begin{aligned}\forall &i,j,h,k : i < h\\
&m(i,j) = m(h,k)
\end{aligned}\\
& s_{i,j} \in \{0..eoh\}
\hspace{58mm} \forall i = 0..n-1,\ j = 0..m-1
\end{align}
Where the \vee
expression will be modeled using a \max
.
We will return to the JSSP again in the course