You are on page 1of 10

Miniguide for Building Constraints in Mathematical Linear Model

Phan Nguyen Ky Phuc

October 14, 2021

Contents

1 Open Facility Decision 2

2 Binary Inference 2

3 Inference Condition 2

4 Max Constraint 3

4.1 Max Constraint: X = max(A, 0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

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

4.3 Extension of Max Constraint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

5 Min Constraint 4

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

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

6 And Condition 5

7 Or Condition 5

8 XOR Condition 5

9 Imply Condition 6

10 Z=X × Y Constraint 6

11 Conflicted Condition when Starting and Finishing Time are parameters 6

12 Conflicted Condition when Starting and Finishing Times are Variables 7

13 Another Approach For Handling Conflict Constraint 7

14 Absolute Values for Binary Variables 8

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

15 Piece-wise Linear Constraints 8

16 Belong to The Range Constraints 9

17 Belong to the range constraint: Discrete case 9

18 Other Inference 9

19 Jobs Use Multiple Resources 10

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 Binary Inference

If X = 1 then Y = 1: Y ≥ X
If X = 1 then Y = 0: Y ≤ 1 − X
If X = 0 then Y = 0: Y ≤ X
If X = 0 then Y = 1: Y ≥ 1 − X

3 Inference Condition

The inference condition is under the form:

• If (X = 1) then A ≤ B:
BigM × (X − 1) + A ≤ B

• If (X = 0) then A ≥ B:
BigM × X + A ≥ B

• If (X = 1) then A = B 
BigM × (X − 1) + A ≤ B
BigM × (1 − X) + A ≥ B

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

4 Max Constraint

4.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

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



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

4.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 )

4.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:

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

!
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

5 Min Constraint

5.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

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

Consider the following constraints:

X = min(A, B)

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

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

6 And Condition

Given Xi , Y are binary variable Y relates to Xi through AND 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 − n + 1
i i

7 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

8 XOR Condition

Y = X1 XOR X2 


 Y ≥ X1 + X2 − 1


≥ 1 − X1 − X2

Y


 Y ≤ 1 − X1 + X2


≤ 1 − X2 + X1

Y

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

X Y ¬X Z=X→Y ¬X ∪ Y
1 1 1 1 1
0 0 1 1 1
0 1 1 1 1
1 0 0 0 0

9 Imply Condition



 Z ≥1−X

Z≥Y


Z ≤ 1 − X + Y

10 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)

11 Conflicted Condition when Starting and Finishing Time are pa-


rameters

Parameters
sj : starting time of job j
fj : finishing time of job j
Ejm = {0, 1}. Ejm = 1 if job j is possible to be assigned to machine m; otherwise Ejm = 0
Cjk = {0, 1}. Cjk = 1 if job j and job k cannot be assigned to the same machine m due to overlap constraint;
otherwise Cjk = 0
Decision variables
Xjm = {0, 1}. Xjm = 1 if job j is assigned to machine m; otherwise Xjm = 0
Constraints

Ejm Xjm + Ekm Xkm ≤ 2 − Cjk , ∀i, j, m


X
Xjm = 1, ∀i
m

Xjm ≤ Ejm , ∀j, m

Note
In general, we need only consider variables Xjm which having Ejm = 1
Let E be the set which containing tuples of possible assignment < j, m > of job j to machine m
Let C be the set which containing tuples of conflict jobs < j, k > due to overlap
Constraints

X<j,m> + X<k,m> ≤ 2 − C<j,k> , ∀ < j, m >, < k, m >∈ E, ∀ < j, k >∈ C


X
X<j,m> = 1, ∀j
m

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

12 Conflicted Condition when Starting and Finishing Times are


Variables

Parameters
Ejm = {0, 1}. Ejm = 1 if job j is possible to be assigned to machine m; otherwise Eim = 0
Variables
sj : starting time of job j
fj : finishing time of job j
Xjm = {0, 1}. Xjm = 1 if job j is assigned to machine m, otherwise Xjm = 0
Rkj = {0, 1}. Rkj = 1 if job k finishes before job j starts, i.e. fk ≤ sj , otherwise Rkj = 0

BigM × (Rkj − 1) + fk ≤ sj
BigM × Rkj + fk ≥ sj
To avoid the overlap, following constraint is applied

Ejm Xjm + Ekm Xkm ≤ 1 + Rkj + Rjk ∀j, k, m


Xim ≤ Ejm ∀j, m

If both Rkj and Rjk are zero then only one Xjm or Xkm are allowed

13 Another Approach For Handling Conflict Constraint

Index
i: index of job
j: index of job
m: index of machine
Parameters
BigM : Very large number
P roim : be the processing time if job i on machine m
Setkjm : be the setup time of job j on on machine m if job k is an immediate precedence job of job j on
machine m
Enim = {0, 1}. 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 = {0, 1}. Xim = 1 if job i is assigned to machine m; otherwise Xim = 0
Ykj = {0, 1}. Ykj = 1 if job j is the immediate successor job of job k on the same machine, otherwise Ykj = 0
sj starting time of job j
fj finishing time of job j

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

Ykj + Yjk ≤ 1, ∀k, j


Xjm + Xkm − Ykj − Yjk ≤ 1, ∀i, j, m
Xkm + Xjn + Ykj + Yjk ≤ 2, ∀j, k, m, n
M
X
sj + P rojm Xjm = fj , ∀j, m
m=1
M
X
fk + Xim Setkjm − BigM (1 − Ykj ) ≤ sj , ∀k, j, m
m=1

14 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

15 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.
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

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

16 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

17 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
Vt binary variable, Vt = 1 if t ≤ D − 1, otherwise; Vt = 0
Rt binary variable, Rt = 1 if S ≤ t ≤ D − 1, otherwise; Rt = 0

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

18 Other Inference

Given A ≥ 0 and α is constant. Assume that the following inferences should be satisfied
If X = 1 then A ≥ α
If X = 0 then A = 0
These constraints can be expressed as 
A ≥ α × X
A ≤ BigM × X

Another way 
α ≤ A + BigM (1 − X)
A ≤ BigM × X

If Lower Bound and Upper Bound for A can be estimated, i.e. A ∈ [LBA ; U BA ] and A − α ∈ [LBA −
α; U BA − α]
In this case the constraints can be rewritten as

(α − LB ) × (1 − X) + A − α ≥0
A
U B × X ≥A
A

Guide to Construct Linear Constraint Page 9


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

In case BigM coefficient can affect the computation time, this analysis can be used to estimate the values
of some BigM

19 Jobs Use Multiple Resources

Given the following data

Table 1: Job Parameters

Job 1 2 3 4 5
wj 1 1 2 3 3
sj 0 4 3 7 6
fi 5 6 8 12 10
Resources {1,3} {2,3} {2,3} {1} {3}

Parameters
wj weight of job j
sj starting time of job j
fj finishing time of job j
Ojt parameters, if sj ≤ t ≤ fj then Ojt = 1 otherwise Ojt = 0
Rjs number of resource s using by job j
Ns be the maximum number of resource s
Decision variable
Xj if job j is selected
Mathematical model
J
X
max wj Xj
j=1

Constraints:
I
X
Oit × Ris × Xi ≤ Ns , ∀t, s
i=1

Guide to Construct Linear Constraint Page 10

You might also like