On expressing NRP constraints as SAT problems
Tommy Messelis*
Stefaan Haspeslagh
Patrick De Causmaecker
ASSO_KUL
Campus_Kortrijk
*tommy.messelis@kuleuven-kortrijk.be
Outline
positioning of this research / our motivation
Nurse Rostering Problem (NRP)
propositional SATisfiability problem (SAT)
translation scheme
conclusions
scope
performance prediction for real world scheduling andtimetabling
building empirical hardness models for variousestablished solution methods
mapping instance features
readily available / efficiently computable properties of theproblem instances
onto performance criteria
how good does an algorithm do, how much time does it need,what solution quality can it achieve given a fixed time
algorithm selection problem: how to choose the bestalgorithm for a given problem instance?
scope
feature set is extremely important for the quality of thepredictions
come up with very good features
expert knowledge
eliminate this expert by transforming the problem toanother (better studied) problem
use an existing feature set on this abstract representation
Nurse Rostering Problem
planning horizon: time units (corresponding to shifts)
e.g. 14 days, 3 shift structure (early/late/night)
total of 42 time units
set of nurses need to be assigned to these shifts
demands
minimum needed occupation for all time units
constraints
hard: cannot be violated
a nurse cannot work in 2 places at the same time
soft: can be violated at a certain cost
a nurse should not work more than 5 days in a row
find an assignment that satisfies all hard constraints and asmany soft constraints as possible
Nurse Rostering Problem
structural constraint types
consecutiveness
between
total
demands
equal to total constraints, but dealing with time unitsinstead of individual nurses
other constraints
nurse preferences, skill requirements, ...
Nurse Rostering Problem
Mon
Tue
Wed
Thu
Fri
Sat
Sun
Nurse1
E
E
E
E
E
L
L
Nurse2
L
L
L
L
L
N
N
Nurse3
N
N
E
L
E
...
demands
2
2
1
2
2
1
2
2
1
2
2
1
2
2
2
1
2
1
1
1
1
Example: incomplete roster
not all demands are (yet) satisfied
some nurses work already more than allowed
propositional SATisfiability
a logical formula on boolean variables in ConjunctiveNormal Form (CNF)
a CNF formula is a conjunction of clauses:
C C ... CN
each clause Ci is a disjunction of literals:
L L ... LM
each literal Lj is a boolean variable or its negation:
v10 or ¬v16
find a truth assignment for the set of boolean variablesso that the formula evaluates true
outline
so far
the nurse rostering problem
the propositional satisfiability problem
now
getting from the one problem into the other
from NRP to SAT
decision variables
for each time unit t and each nurse p a boolean variable vt,jthat indicates whether nurse p works shift t
problem constraints need to be imposed onto thesevariables, expressed using CNF clauses
Mon
Tue
Wed
time unit
1
2
3
4
5
6
7
8
9
Nurse1
v1,1
v2,1
v3,1
v4,1
v5,1
v6,1
v7,1
v8,1
v9,1
Nurse2
v1,2
v2,2
v3,2
v4,2
v5,2
v6,2
v7,2
v8,2
v9,2
Nurse3
v1,3
v2,3
v3,3
v4,3
v5,3
v6,3
v7,3
v8,3
v9,3
...
numberings
represent (multiple) time units by a number
a numbering defines the subject of a constraint
N1 will deal with working days
N2 looks only at early shifts
N3 handles only tuesdays
Mon
Tue
Wed
time unit
1
2
3
4
5
6
7
8
9
Numbering N1
1
1
1
2
2
2
3
3
3
Numbering N2
1
U
U
2
U
U
3
U
U
Numbering N3
U
U
U
1
1
1
U
U
U
...
numberings: notation
a solution (assignment of some shifts to a nurse)induces a set of numbers (called events)
an event sequence is a row of events, conserving thetimely order e1e2, ... , em  (e.g. 1,2,5,6,7)
an event sequence is contiguously ascending when forall j holds: ej – ej-1 = 1 (e.g. 1,2,3,4,5)
constraints can be expressed using event sets andevent sequences
example assignment
Numbering N1 induces the event set {1,2,3,4,5,7}
max_consecutive_working_days = 5
there is no contiguously ascending event sequence of length 6 : satisfied
Numbering N2 induces the event set {1,2,3,4,5}
max_total_early = 4
the event set should not contain more than 4 events : violated
 
Mon
Tue
Wed
Thu
Fri
Sat
Sun
time unit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
N1
1
1
1
2
2
2
3
3
3
4
4
4
5
5
5
6
6
6
7
7
7
N2
1
U
U
2
U
U
3
U
U
4
U
U
5
U
U
6
U
U
7
U
U
Nurse2
from numbers to clauses
for each number i, we introduce a new variable twhichindicates whether the number i occurs in the event set:
ti  v3i   v3i-1  v3i-2
or in CNF format, the conjunction of 4 clauses:
¬ti   v3i   v3i-1  v3i-2
ti   ¬v3i
ti   ¬v3i-1
ti   ¬v3i-2
for n numbers, we generate n variables and O(n) clauses
from numbers to clauses
consecutiveness constraints are easily represented by CNFclauses:
max_cons_working_days = 4
¬ti   ¬ti+1   ¬ti+2  ¬ti+3  ¬ti+4    for i  {1..(n-4)}
(in a row of 5 consecutive days, not all ti may be true)
min_cons_working_days = 2
ti   ¬ti+1   ti+2   for i  {1..(n-2)}
(in a row of 3 consecutive days, the middle ti may not be true without one ofthe border variables)
for n numbers, we generate O(n) clauses (no extra variables)
from numbers to clauses
between constraints are very similarO(n) clauses and no extra variables
total constraints are a bit harder
max_total = 6
no subset of variables ti of size 6 can have all variables set true
min_total = 4
no subset of variables ti of size n-4 can have all variables setfalse
leads to an exponential number of clauses: O(2n)
 we need a better representation with fewer clauses
total constraints
at least i events in the complete set
at least k left OR at least l right, forall k,l: k+l = i+1
instead of expressing the constraint in function of the complete set ofnumbers, we now use sets of half the size
doing this recursively, until the sets are of size 1, leads to an efficient schema(the variable tx represents exactly if the event x is present)
O(nlogn) variables and O(n2) clauses
1
2
3
4
5
6
7
8
9
10
11
12
13
14
8
9
10
11
12
13
14
1
2
3
4
5
6
7
4
12
conclusions
we represented the problem by boolean variables
we used numberings to express all kinds of constraints on thesolutions
each number introduced an extra variable and some clauses
in total n variables and 0(n) clauses
constraints on the numberings were then translated into CNF clauses
consecutiveness, between constraints
O(n) clauses, no extra variables
total constraints need special attention
O(nlogn) auxiliary variables and 0(n2) clauses
  the overall process of translating NRP instances into  CNF clauses needs O(nlogn) variables and O(n2)  clauses, which is an efficient translation schema
Thank you!
Questions?