{( red, green ),( red, blue ),( green, red ),( green, blue ),( blue , red ),( blue, green )}
Possible solution:
{
WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = red
}
Constraint Graph:
Example: Scheduling Problem
Scheduling a car assembly in 30 minutes - Every task is a variable
Xi
.
We have
15
Tasks / Variables
X={ Axle
F
, Axle
B
, Wheel
RF
, Wheel L
F
, Wheel
RB
, Wheel L
B
, Nuts
RF
,NutsL
F
,Nuts
RB
,NutsL
B
,Cap
RF
,CapL
F
,Cap
RB
,CapL
B
, Inspect }
The values
vi
are the time at which a task starts.
Di={1,2,3,…,27}
Precedence constraints: (linear constraints)
T1+d1≤T2when task1 takes d1 minutes to complete and must be executed before task2.
Axle
F
+10≤ Wheel
RF
; Axle
B
+10≤ Wheel
RB
; Axle
F
+10≤ WheelL
F
Axle
B
+10≤ WheelL
B
Wheel
RF
+1≤Nuts
RF
; WheelL
F
+1≤NutsL
F
; Wheel
RB
+1≤Nuts
RB
; WheelL
B
+1≤NutsL
B
;Nuts
RF
+2≤Cap
RF
NutsL
F
+2≤CapL
F
Nuts
RB
+2≤Cap
RB
NutsL
B
+2≤CapL
B
Also for every single variable
X
we add another constraint:
X+dX≤ Inspect
We also have a
disjunctive constraint
(Axle
F
+10≤Axle
B
)∨(Axle
B
+10≤Axle
F
)
Example: Cryptarithmetic CSP
Usually involve higher order constraints.
The goal is to find the right digits so that the sum is arithmetically correct. (no leading zeroes allowed).
TWO+TWOF O U R
Possible solution:
938+938=1876
X={F,T,U,W,R,O,X1,X2,X3}
D={0,1,2,3,4,5,6,7,8,9}
Constraints:
Each letter stands for a different digit:
Alldiff(F,T,U,W,R,O)
The
X1,X2,X3
variables stand for the digit that gets carried over into the next column by the addition.
All constraints can be shown in a
constraint hypergraph
:
top square box: alldiff constraint
middle square box: addition constraints
(hereCiis used instead ofXifor the carry digit)
How it should be read
We start off from the top square box. Each edge leads to a letter. Each letter can have a value from our domain under the
condition that they are all different.
Then each of the letters have a sum that sets the carry bit or is influenced by a previous carry bit.
Each edge just connects variables to their constraints or contraints with eachother.