Lecture8 Notes
Lecture8 Notes
Topic:
Domains:
Explicit:
Domains:
Constraints:
Implicit:
Explicit:
9
Faculty of computer and information sciences
Mansoura University
Information System Department
Example 1: Map-Coloring
General-purpose CSP algorithms use the graph structure to speed
up search. E.g., Tasmania is an independent sub-problem!
Example: Cryptarithmetic
Variables: F; T; U; W; R; O; 𝑋1 ; 𝑋2 ; 𝑋3 .
Domains: {0; 1; 2; 3; 4; 5; 6; 7; 8; 9}.
Constraints: Alldiff (F,T,U,W,R,O)
— O + O = R + 10. 𝑋1
— 𝑋1 + W + W = U + 10. 𝑋2
Solution: T = 9, W = 3, O = 8,
— 𝑋2 + T + T = O + 10. 𝑋3 F = 1, U = 7, R = 6
— 𝑋3 = F, 𝑇 ≠ 0, 𝐹 ≠ 0
Discrete Variables
Finite domains
Size d means O(d n) complete assignments
e.g., Boolean CSPs, including Boolean satisfiability (NP-
complete)
Infinite domains (integers, strings, etc.)
e.g., job scheduling, variables are fixed start/end times
for each job
Continuous variables
e.g., start/end times for Hubble Telescope
observations.
Varieties of Constraints
Unary constraints involve a single variable (equivalent to
reducing domains), e.g.:
Backtracking Search
Given a formulation of CSPs as search problems, any of the search
algorithms from Chapters 3 and 4 can solve CSPs.
22
Faculty of computer and information sciences
Mansoura University
Information System Department
Assign {WA=red}
Effects on other variables connected by constraints with WA
NT can no longer be red
SA can no longer be red
Assign {Q=green}
Effects on other variables connected by constraints with WA
NT can no longer be green
NSW can no longer be green
SA can no longer be green
MRV heuristic will automatically select NT and SA next, why?
If V is assigned blue
Effects on other variables connected by constraints with WA
SA is empty
NSW can no longer be blue
FC has detected that partial assignment is inconsistent with the constraints
and backtracking can occur.
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}
[4-Queens slides copied from B.J. Dorr CMSC 421 course on AI]
October 13, 2015 TLo (IRIDIA) 28
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}
X1 X2
1 2 3 4 {1,2,3,4} { , ,3,4}
1
2
3
4
X3 X4
{ ,2, ,4} { ,2,3, }
X1 X2
1 2 3 4 {1,2,3,4} { , ,3,4}
1
2
3
4
X3 X4
{ ,2, ,4} { ,2,3, }
X1 X2
1 2 3 4 {1,2,3,4} { , ,3,4}
1
2
3
4
X3 X4
{ , , , } { ,2,3, }
X1 X2
1 2 3 4 { ,2,3,4} {1,2,3,4}
1
2
3
4
X3 X4
{1,2,3,4} {1,2,3,4}
X1 X2
1 2 3 4 { ,2,3,4} { , , ,4}
1
2
3
4
X3 X4
{1, ,3, } {1, ,3,4}
X1 X2
1 2 3 4 { ,2,3,4} { , , ,4}
1
2
3
4
X3 X4
{1, ,3, } {1, ,3,4}
X1 X2
1 2 3 4 { ,2,3,4} { , , ,4}
1
2
3
4
X3 X4
{1, , , } {1, ,3, }
X1 X2
1 2 3 4 { ,2,3,4} { , , ,4}
1
2
3
4
X3 X4
{1, , , } {1, ,3, }
X1 X2
1 2 3 4 { ,2,3,4} { , , ,4}
1
2
3
4
X3 X4
{1, , , } { , ,3, }
X1 X2
1 2 3 4 { ,2,3,4} { , , ,4}
1
2
3
4
X3 X4
{1, , , } { , ,3, }
Terminates!
Forward checking propagates information from assigned to
unassigned variables, but doesn't provide early detection for all
failures:
NT Q
WA
SA
NSW
V
Consistent
Faculty of computer and information sciences
Mansoura University
Information System Department