Constraint+Satisfaction+Problem II
Constraint+Satisfaction+Problem II
LECTURE # 08
TUESDAY, FEBRUARY 14, 2017
SPRING 2016
FAST – NUCES, FAISALABAD CAMPUS
Zain Iqbal
Zain.iqbal@nu.edu.pk
Agenda
Job-Shop Scheduling
Forward Checking
Constraint Propagation
• Node consistency
• Arc consistency
• Path consistency
• K-consistency
• Global contraints
Intelligent Backtracking
• Constraint Learning
Job-Shop Scheduling
Small part of the car assembly, consisting of 15 tasks
X = {AxleF , AxleB, WheelRF ,WheelLF ,WheelRB,WheelLB,
NutsRF ,NutsLF , NutsRB, NutsLB, CapRF , CapLF , CapRB,
CapLB, Inspect} .
Precedence constraints
• AxleF + 10 ≤ WheelRF ; AxleF + 10 ≤ WheelLF
• AxleB + 10 ≤ WheelRB; AxleB +10 ≤ WheelLB
• WheelRF + 1 ≤ NutsRF ; NutsRF + 2 ≤ CapRF ;
• WheelLF + 1 ≤ NutsLF ; NutsLF +2 ≤ CapLF ;
• WheelRB + 1 ≤ NutsRB; NutsRB + 2 ≤ CapRB;
• WheelLB + 1 ≤ NutsLB; NutsLB + 2 ≤ CapLB
Inspect we add a constraint of the form X +dX ≤ Inspect
Done in 30 min So Di = {1, 2, 3, . . . , 27} .
3
Heuristic 4: Forward checking
• Idea:
• Keep track of remaining legal values for unassigned
variables
• Terminate search when any variable has no legal values
4
Forward checking
• Idea:
• Keep track of remaining legal values for unassigned
variables
• Terminate search when any variable has no legal
values
5
Forward checking
• Idea:
• Keep track of remaining legal values for unassigned
variables
• Terminate search when any variable has no legal values
6
Forward checking
• Idea:
• Keep track of remaining legal values for unassigned variables
• Terminate search when any variable has no legal values
7
Example: 4-Queens Problem
X1 X2
{1,2,3,4} {1,2,3,4}
1 2 3 4
1
2
3
4 X3 X4
{1,2,3,4} {1,2,3,4}
8
Example: 4-Queens Problem
X1 X2
{1,2,3,4} {1,2,3,4}
1 2 3 4
1
2
3
4 X3 X4
{1,2,3,4} {1,2,3,4}
9
Example: 4-Queens Problem
X1 X2
{1,2,3,4} { , ,3,4}
1 2 3 4
1
2
3
4 X3 X4
{ ,2, ,4} { ,2,3, }
10
Example: 4-Queens Problem
X1 X2
{1,2,3,4} { , ,3,4}
1 2 3 4
1
2
3
4 X3 X4
{ ,2, ,4} { ,2,3, }
11
Example: 4-Queens Problem
X1 X2
{1,2,3,4} { , ,3,4}
1 2 3 4
1
2
3
4 X3 X4
Backtrack!!!
{ , , , } { ,2,3, }
12
Example: 4-Queens Problem
X1 X2
{ ,2,3,4} {1,2,3,4}
1 2 3 4
1
2
3
4 X3 X4
{1,2,3,4} {1,2,3,4}
13
Example: 4-Queens Problem
X1 X2
{ ,2,3,4} { , , ,4}
1 2 3 4
1
2
3
4 X3 X4
{1, ,3, } {1, ,3,4}
14
Example: 4-Queens Problem
X1 X2
{ ,2,3,4} { , , ,4}
1 2 3 4
1
2
3
4 X3 X4
{1, ,3, } {1, ,3,4}
15
Example: 4-Queens Problem
X1 X2
{ ,2,3,4} { , , ,4}
1 2 3 4
1
2
3
4 X3 X4
{1, , , } {1, ,3, }
16
Example: 4-Queens Problem
X1 X2
{ ,2,3,4} { , , ,4}
1 2 3 4
1
2
3
4 X3 X4
{1, , , } {1, ,3, }
17
Example: 4-Queens Problem
X1 X2
{ ,2,3,4} { , , ,4}
1 2 3 4
1
2
3
4 X3 X4
{1, , , } { , ,3, }
18
Example: 4-Queens Problem
X1 X2
{ ,2,3,4} { , , ,4}
1 2 3 4
1
2
3
4 X3 X4
{1, , , } { , ,3, }
19
20
Constraint propagation
• Forward checking only looks at variables connected to current value in
constraint graph.
21
Node Consistency
22
Arc consistency
• Simplest form of propagation makes each arc consistent
• X Y is consistent iff
for every value x of X there is some allowed y
consistent arc.
inconsistent arc.
remove blue from source consistent arc.
24
Arc consistency
25
Arc consistency
• Simplest form of propagation makes each arc consistent
• X Y is consistent iff
for every value x of X there is some allowed y
• Since we only remove values from domains when they can never be part of a
solution, an empty domain means no solution possible at all back out of that
branch.
• Forward checking is simply sending messages into a variable that just got its
value assigned. First step of arc-consistency.
27
AC-3 Algorithm
29
K-consistency
• Arc consistency does not detect all inconsistencies:
Partial assignment {WA=red, NSW=red} is
inconsistent.
• Stronger forms of propagation can be defined using
the notion of k-consistency.
• A CSP is k-consistent if for any set of k-1 variables
and for any consistent assignment to those
variables, a consistent value can always be assigned
to any kth variable.
E.g. 1-consistency or node-consistency
E.g. 2-consistency or arc-consistency
E.g. 3-consistency or path-consistency
30
Strongly k-consistent
• A graph is strongly k-consistent if
It is k-consistent and
Is also (k-1) consistent, (k-2) consistent, … all the way
down to 1-consistent.
• This is ideal since a solution can be found in time
instead of
• YET no free lunch: any algorithm for establishing
n-consistency must take time exponential in n, in
the worst case it will require exponential space n.
31
Further improvements
Checking special constraints
Checking Alldif(…) constraint
• E.g. {WA=red, NSW=red}
Checking Atmost(…) constraint
• E.g. Atmost(10, P1, P2, P3, P4).
• Domain {2, 3, 4, 5, 6}, the values 5 and 6 can be deleted
• Checking bounds propagation(…)
Bounds propagation for larger value domains
Bounds propagation for Smaller value domains
• E.g. Flight Passenger D1 = [0, 165] and D2 = [0, 385] .
OR
• F1 + F2 = 420. D1 = [35, 165] and D2 = [255, 385] .
32
Intelligent backtracking:
looking backward
33
Intelligent backtracking
Standard form is chronological backtracking i.e. try
different value for preceding variable.
More intelligent, backtrack to conflict set.
• Set of variables that caused the failure or set of previously
assigned variables that are connected to X by constraints.
• Back-jumping moves back to most recent element of the
conflict set.
• Forward checking can be used to determine conflict set.
34
Example-Map Coloring
When we try the next variable, SA, we see that every value violates a constraint. We
back up to T and try a new color for Tasmania!-But its Silly
Where to backtrack?
37
Reading Material
• Russell & Norvig: Chapter # 7
• David Poole: Chapter # 4
38