You are on page 1of 9

Miniguide for Building Constraints in Mathematical Linear Model

Phan Nguyen Ky Phuc

February 3, 2021

Contents

1 Open Facility Decision 2

2 Inference Condition 2

3 Max Constraint 2

3.1 Max Constraint: X = max(A, 0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

3.2 Max Constraint: X = max(A,B) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

3.3 Extension of Max Constraint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

4 Min Constraint 4

4.1 The min constraint: X=min(A,0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

4.2 The Min Constraint: X=min(A,B) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

5 And Condition 4

6 Or Condition 5

7 Z=X × Y Constraint 5

8 Conflicted Condition 5

9 Conflicted Condition when Starting and End Times are Variables 6

10 Another Approach For Handling Conflict Constraint 7

11 Absolute Values for Binary Variables 8

12 Piece-wise Linear Constraints 8

13 Belong to The Range Constraints 9

14 Belong to the range constraint: Discrete case 9

1
Ho Chi Minh City International University Deterministic Models in Operation Research
Industrial Systems Engineering Department Lecturer: Phan Nguyen Ky Phuc

1 Open Facility Decision

Let:
Cj : be the capacity regarding to facility j
BigM : be the very large number
Oj : be the binary decision variable, Oj = 1 if the facility j is opened; otherwise Oj = 0
It is often that, there are at least one of 2 following constraints

X
() ≤ Cj × Oj
i
X
() ≤ BigM × Oj
i

2 Inference Condition

The inference condition is under the form:

• If (X = T RU E) then A ≤ B

• If (X = F ALSE) then A ≥ B

• If (X = T RU E) then A = B

If (X = T RU E) then A ≤ B
A ≤ B + BigM (1 − X)

If (X = F ALSE) then A ≥ B
A ≥ B − BigM × X

If (X = T RU E) then A = B 
A ≤ B + BigM (1 − X)
A ≥ B − BigM (1 − X)

3 Max Constraint

3.1 Max Constraint: X = max(A, 0)

Consider the following constraint:

X = max(A, 0)

where X, A are variables. This constraint can be transformed to linear form:


Let Y be the index variable: 
1 , if A ≥ 0
Y =
0 , if A ≤ 0

The constraints between A and Y can be expressed as:



A ≥ BigM × (Y − 1)
A ≤ BigM × Y

Guide to Construct Linear Constraint Page 2


Ho Chi Minh City International University Deterministic Models in Operation Research
Industrial Systems Engineering Department Lecturer: Phan Nguyen Ky Phuc

Now the constraints between X = max(A, 0) can be transformed as linear :



0 ≤ X ≤ 0 + BigM × Y
A ≤ X ≤ A + BigM × (1 − Y )

3.2 Max Constraint: X = max(A,B)

Consider the following constraints:

X = max(A, B)

where X, A, B are variables. This constraint can be transformed to linear form as follow:
Let Y be the index variable: 
1 , if (A − B) ≥ 0
Y =
0 , if (A − B) ≤ 0

The constraints between (A − B) and Y can be expressed as:



(A − B) ≥ BigM × (Y − 1)
(A − B) ≤ BigM × Y

Now the constraints X = max(A, B) can be transformed to linear form as :



B ≤ X ≤ B + BigM × Y
A ≤ X ≤ A + BigM × (1 − Y )

3.3 Extension of Max Constraint

Given a threshold R for a resource , if the usage of this resource is higher than R it will incur an extra cost
for each extra usage resource.
In short the following constraints need to be transform into linear constraint:
!
X
X = max Ci Yi − R, 0
i

Let Z be the index variable: 


1 , if (P C Y − R) ≥ 0
i i i
Z=
0 , if (P C Y − R) ≤ 0
i i i
P
The constraints between ( i Ci Yi − R) and Z can be expressed as:

(P C Y − R) ≥ BigM × (Z − 1)
i i i
(P C Y − R) ≤ BigM × Z
i i i

P
Now the constraints X = max ( i Ci Yi − R, 0) can be transformed to linear form as :

0 ≤ X ≤ 0 + BigM × Z
(P C Y − R) ≤ X ≤ (P C Y − R) + BigM × (1 − Z)
i i i i i i

Guide to Construct Linear Constraint Page 3


Ho Chi Minh City International University Deterministic Models in Operation Research
Industrial Systems Engineering Department Lecturer: Phan Nguyen Ky Phuc

4 Min Constraint

4.1 The min constraint: X=min(A,0)

Consider the following constraints:

X = min(A, 0)

where X, A are variables. This constraint can be transformed to linear as follow:


Let Y be the index variable: 
1 , if A ≥ 0
Y =
0 , if A ≤ 0

The constraints between A and Y can be expressed as:



A ≥ BigM × (Y − 1)
A ≤ BigM × Y

Now the constraints between X = min(A, 0) can be transformed to linear form:



0 ≥ X ≥ 0 − BigM × (1 − Y )
A ≥ X ≥ A − BigM × Y

4.2 The Min Constraint: X=min(A,B)

Consider the following constraints:

X = min(A, B)

where X, A, B are variables. This constraint can be transformed to linear form as follow:
Let Y be the binary variable: 
1 , if A − B ≥ 0
Y =
0 , if A − B ≤ 0

The constraints between (A − B) and Y can be expressed as:



(A − B) ≥ BigM × (Y − 1)
(A − B) ≤ BigM × Y

Now the constraint X = min(A, B) can be transformed to linear form:



B ≥ X ≥ B − BigM × (1 − Y )
A ≥ X ≥ A − BigM × Y

5 And Condition

Given Xi , Y are binary variable Y relates to Xi through AND operator

Y = X1 ∩ X2 ∩ X3 ... ∩ Xn

Guide to Construct Linear Constraint Page 4


Ho Chi Minh City International University Deterministic Models in Operation Research
Industrial Systems Engineering Department Lecturer: Phan Nguyen Ky Phuc

This constraint can be transformed to linear form as



Y ≤ X ,∀i, i = 1...n
i
Y ≥ P
i Xi − n + 1

6 Or Condition

Given Xi , Y are binary variable Y relates to Xi through OR operator

Y = X1 ∪ X2 ∪ X3 ... ∪ Xn

This constraint can be transformed to linear form as



Y ≥ X ,∀i, i = 1...n
i
Y ≤ P X
i i

7 Z=X × Y Constraint

Given X is binary variable, Y ≥ 0


This constraint can be transformed to linear form as



 Z ≤ BigM × X

Z ≤ Y + BigM × (1 − X)


Z ≥ Y − BigM × (1 − X)

8 Conflicted Condition

Example
Assume that there are 2 jobs i and j. These jobs must be finished in their time window [si ; ei ] and [sj ; ej ].
If their time windows are overlapped, so these jobs cannot be assigned to the same worker. These jobs are
called conflicted jobs. If [si ; ei ] and [sj ; ej ] are not decision variables so their conflict due to overlap can be
expressed through a parameters Cij .
Parameters
Eim be the enable matrix Eim = 1 if job i is possible to be assigned to worker m; otherwise Eim = 0
Cij be the conflict matrix Cij = 1 if job i and job j cannot be assigned to the same worker m due to overlap
constraint; otherwise Cij = 0
Decision variables
Xim be the binary variable; Xim = 1 if job i is assigned to worker m; otherwise Xim = 0
Basic constraints

Xim + Xjm ≤ 2 − Cij , ∀i, j, m


X
Xim = 1, ∀i
m

Xim ≤ Eim , ∀i, m

Guide to Construct Linear Constraint Page 5


Ho Chi Minh City International University Deterministic Models in Operation Research
Industrial Systems Engineering Department Lecturer: Phan Nguyen Ky Phuc

9 Conflicted Condition when Starting and End Times are Variables

Index
i: index of job
j: index of job
w: index of worker
Parameters
BigM : Very large number
Sijm :setup time for job j on machine mif job i is immediate precedence job of job j on machine m
Eniw : be the enable matrix Eniw = 1 if job i is able to be assigned to worker w;otherwise Enij = 0
Bw and Fw are two values identify the time window of worker w
Decision Variables
Xiw be the binary variable, Xiw = 1 if job i is assigned to worker w; otherwise Xiw = 0
si starting time of job i
ei finishing time of job i
Basically there are two cases when 2 jobs are overlapped:

• The first is the starting time of job i, si in the range of job j, [sj , ej ]

• The second is the ending time of job i, ei in the range of job j, [sj , ej ]

Following auxiliary variables will be used to consider the overlap constraint:

• uij be the binary variable uij = 1 if sj < si otherwise uij = 0

• vij be the binary variable vij = 1 if si < ej otherwise vij = 0

• rij be the binary variable rij = 1 if sj < si < ei otherwise rij = 0

Basic constraints include:


X
Xiw = 1, ∀i
w
X
ei = si + Xiw P roiw , ∀i
w

ei ≤ sj , ∀P reij = 1

For each uij , vij , pij , qij pair of constrains are used

uij = 1 if sj < si otherwise uij = 0

sj ≤ si + BigM × (1 − uij ), ∀i, j


sj ≥ si − BigM × uij , ∀i, j

vij = 1 if si < ej otherwise vij = 0

si ≤ ej + BigM × (1 − vij ), ∀i, j


si ≥ ej − BigM × vij , ∀i, j

Elimination condition

uij + uji = 1, ∀i, j, i 6= j


vij + vji = 1, ∀i, j, i 6= j

Guide to Construct Linear Constraint Page 6


Ho Chi Minh City International University Deterministic Models in Operation Research
Industrial Systems Engineering Department Lecturer: Phan Nguyen Ky Phuc

If uij = 1 and vij = 1, then rij = 1 otherwise rij = 0

rij ≤ uij , ∀i, j


rij ≤ vij , ∀i, j
rij ≥ uij + vij − 1, ∀i, j

The value of rij will create following constraints

Xiw ≤ Eniw , ∀i, w


Xiw + Xjw ≤ 2 − rij , ∀i, j, w

Furthermore if Xiw = 1 then si and ei must be in the range [Bw ; Fw ], this will create the following constraints

Bw + BigM × (Xiw − 1) ≤ si , ∀i, w


Bw + BigM × (Xiw − 1) ≤ ei , ∀i, w
si ≤ Fw + BigM × (1 − Xiw ), ∀i, w
ei ≤ Fw + BigM × (1 − Xiw ), ∀i, w

s1 e1

s2 e2

s1 e1

s2 e2

Figure 1: Possible overlap case

10 Another Approach For Handling Conflict Constraint

Index
i: index of job
j: index of job
m: index of machine
Parameters
BigM : Very large number

Guide to Construct Linear Constraint Page 7


Ho Chi Minh City International University Deterministic Models in Operation Research
Industrial Systems Engineering Department Lecturer: Phan Nguyen Ky Phuc

P roim : be the processing time if job i on machine m


Setijm : be the setup time of job j on on machine m if job i is an immediate precedence job of job j on
machine m
Enim : be the enable matrix Enim = 1 if job i is able to be assigned to worker w;otherwise Enij = 0
Bm and Fm are two values identify the time window of machine m
Decision Variables
Xim be the binary variable, Xim = 1 if job i is assigned to machine m; otherwise Xim = 0
Yij be the binary variable, Yij = 1 if job j is the immediate successor job of job i on the same machine,
otherwise Yij = 0
si starting time of job i
ei finishing time of job i

Yij + Yji ≤ 1, ∀i, j


Xim + Xjm − Yij − Yji ≤ 1, ∀i, j, m
Xim + Xjk + Yij + Yji ≤ 2, ∀i, j, m, k
M
X
si + P roim Xim = ei , ∀i, m
m=1
M
X
ei + Xim Setijm − BigM (1 − Yij ) ≤ sj , ∀i, j, m
m=1

11 Absolute Values for Binary Variables

Consider the case


X = |A − B|

where X, A, B are binary variables

X ≥A−B
X ≥B−A
X ≤A+B
X ≤2−A−B

12 Piece-wise Linear Constraints

Given several ranges [ai ; bi ] , i = 1...n and decision variable X, Y . If ai ≤ X ≤ bi then Y = fi (X)
Let ri be the index variable if X ∈ [ai ; bi ] then ri = 1 otherwise ri = 0.

Guide to Construct Linear Constraint Page 8


Ho Chi Minh City International University Deterministic Models in Operation Research
Industrial Systems Engineering Department Lecturer: Phan Nguyen Ky Phuc

Basic constraints include:

ai ≤ Xi + BigM × (1 − ri )
Xi ≤ bi + BigM × (1 − ri ) ∀i = 1...I
Xi ≤ BigM × ri ∀i = 1...I
I
X
ri = 1, ∀i = 1...I
i=1
X
Y = ri × fi (Xi ) ∀i = 1...I
i

Using Z = X × Y constraint the above can be transformed


X
Y = Zi ∀i = 1...I
i

Zi ≤ BigM × ri ∀i = 1...I
Zi ≤ fi (Xi ) + BigM × (1 − ri ) ∀i = 1...I
Zi ≥ fi (Xi ) − BigM × (1 − ri ) ∀i = 1...I

13 Belong to The Range Constraints

Let ri be the index variable if Xi ∈ [ai ; bi ] then ri = 1 otherwise ri = 0.

ai ≤ Xi + BigM × (1 − ri )
Xi ≤ bi + BigM × (1 − ri )
Xi ≤ BigM × ri

14 Belong to the range constraint: Discrete case

D departure time
S starting time
p processing time
Ut binary variable, Ut = 1 if t ≥ S, otherwise; Ut = 0
Dt binary variable, Dt = 1 if t ≥ D − 1, otherwise; Vt = 0

D ≥S+p
t ≥ S − BigM × (1 − Ut )
t ≤ S − 1 + BigM × Ut
t ≤ D − 1 + BigM × (1 − Vt )
t ≥ D − BigM × Vt

Guide to Construct Linear Constraint Page 9

You might also like