Tinelli 05
Tinelli 05
Spring 2019
a These notes were originally developed by Stuart Russell and are used with permission. They are
copyrighted material and may not be used in other course settings outside of the University of Iowa in their
current or modified form without the express written consent of the copyright holders.
CSP:
state is defined by variables Xi with values from domain Di
goal test is a set of constraints specifying
allowable combinations of values for subsets of variables
Northern
Territory
Western Queensland
Australia
South
Australia
New South Wales
Victoria
Tasmania
Northern
Territory
Western Queensland
Australia
South
Australia
New South Wales
Victoria
Tasmania
NT
Northern Q
Territory
Western Queensland
Australia WA
South
Australia
SA NSW
New South Wales
Victoria
V
Victoria
Tasmania
Continuous variables
• e.g., start/end times for Hubble Telescope observations
• linear constraints solvable in polynolmial time by linear
programming methods
CS:4420 Spring 2019 – p.7/34
Varieties of constraints
Unary constraints involve a single variable
e.g., SA 6= g
T WO F T U W R O
+ T WO
F O U R
X3 X2 X1
Variables: F, T, U, W, R, O, X1 , X2 , X3
Domain: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Constraints: alldiff (F, T, U, W, R, O)
O + O = R + 10 · X1
...
Q1 = 1 Q2 = 3
Variables Q1 , Q2 , Q3 , Q4
Domains Di = {1, 2, 3, 4}
Constraints Qi 6= Qj (cannot be in same row)
|Qi − Qj | 6= |i − j| (cannot be on same diagonal)
Translate each constraint into set of allowable values for its variables
E.g., values for (Q1 , Q2 ) are (1, 3) (1, 4) (2, 4) (3, 1) (4, 1) (4, 2)
CS:4420 Spring 2019 – p.10/34
Real-world CSPs
Assignment problems
e.g., who teaches what class
Timetabling problems
e.g., which class is offered when and where?
Hardware configuration
Transportation scheduling
Factory scheduling
Floorplanning
Degree heuristic:
choose the variable with the most constraints on remaining vars
Northern
Territory
Western Queensland
Australia
South
Australia
New South Wales
Victoria
WA NT Q NSW V SA T
Northern
Territory
Western Queensland
Australia
South
Australia
New South Wales
Victoria
Tasmania
WA NT Q NSW V SA T
Northern
Territory
Western Queensland
Australia
South
Australia
New South Wales
Victoria
Tasmania
WA NT Q NSW V SA T
Northern
Territory
Western Queensland
Australia
South
Australia
New South Wales
Victoria
Tasmania
WA NT Q NSW V SA T
Northern
Territory
Western Queensland
Australia
South
Australia
New South Wales
Victoria
WA NT Q NSW V SA T
WA NT Q NSW V SA T
WA NT Q NSW V SA T
WA NT Q NSW V SA T
WA NT Q NSW V SA T
Ex.
D(X) = {1, 2, 3} C1 = (X > 0) X node-consist. with C1
D(X) = {1, 2, 3} C2 = (X > 5) X not node-consist. with C2
Ex.
D(X) = D(Y ) = D(Z) = {1, 2, 3}
Ex.
D(X) = D(Y ) = D(Z) = {1, 2, 3, 4}
NT
Q
WA
SA NSW
V
Victoria
E.g., n = 80, d = 2, c = 20
Theorem: If the constraint graph has no loops, the CSP can be solved
in O(n d2 ) time
A E
B D A B C D E F
C F
NT NT
Q Q
WA WA
SA NSW NSW
V
Victoria V
Victoria
T T
• Symmetry breaking
To apply to CSPs:
allow states with unsatisfied constraints
operators reassign variable values
number of constraints
R=
number of variables
CPU
time
R
critical
ratio