Lec5 AI
Lec5 AI
Problems (CSP)
Artificial Intelligence
Dr. Manel Mrabet
References
• Stuart Russell and Peter Norvig; "Artificial Intelligence: A Modern
Approach", Prentice Hall, Latest Edition
• Constraint satisfaction problems, University of Berkeley
• 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
• A solution to a CSP is
• A complete assignment that satisfies all the constraints
Dr. Manel Mrabet
Example: Map-Coloring
WA
Variables: Constraints:
DEMNORSY M≠0, S ≠0 (unary constaraints)
Y=D+E or Y=D+E-10 , etc
D ≠E, D ≠M, D ≠N
Domains:
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
We need:
Initial state: none of the variables has a value
(color)
Successor function: assign a value to an
unassigned variable that does not conflict with
previously assigned variables.
fail if no legal assignments (not fixable!)
Goal: all variables have a value and none of the
constraints is violated.
Dr. Manel Mrabet
Constraint graph
NT Q
WA
NSW
SA
T
Dr. Manel Mrabet
Varieties of CSPs
Discrete variables
• finite domains:
• n variables, domain size d O(dn) complete assignments
• e.g., Boolean CSPs, incl. Boolean satisfiability (NP-complete)
• infinite domains:
• integers, strings, etc.
• e.g., job scheduling, variables are start/end days for each job
• need a constraint language, e.g., StartJob1 + 5 ≤ StartJob3
Continuous variables
• e.g., start/end times for Hubble Space Telescope observations
• linear constraints solvable in polynomial time by linear
programming
Dr.Walid Aydi
Backtracking search
Dr.Walid Aydi
Example of a csp
A B
E
C
F G
A B
{violet, brown, red}
E
C {violet, brown,
red}
D {violet, brown,
red}
H
{violet, brown, red}
F G {violet, brown, red}
{violet, brown, red}
A B
E
C
F G
1 = red
2 = violet
3 = BROWN
A B
E
C
F G
1 = red
2 = violet
3 = BROWN
A B
E
C
F G
1 = red
2 = violet
3 = BROWN
A B
E
C
F G
1 = red
2 = violet
3 = BROWN
A B
E
C
F G
1 = red
2 = violet
3 = BROWN
A B
E
C
F G
1 = red
2 = violet
3 = BROWN
A B
E
C
F G
1 = red
2 = violet
3 = BROWN
A B
E
C
F G
1 = red
2 = violet
3 = BROWN
A B
E
C
F G
1 = red
2 = violet
3 = BROWN
A B
E
C
F G
1 = red
2 = violet
3 = BROWN
A B
E
C
F G
1 = red
2 = violet
3 = BROWN
A B
E
C
F G
1 = red
2 = violet
3 = BROWN
A B
E
C
H Solution !!!!
F G
1 = red
2 = violet
3 = BROWN
Dr.Walid Aydi
Detailed Example of MRV
MRV=3 MRV=2
MRV=3 MRV=3 MRV=3
MRV=3 MRV=3
MRV=3 MRV=3
Dr. Manel Mrabet
Detailed Example of MRV
Dr.Walid Aydi
Detailed Example of MRV
MRV=2 MRV=1
MRV=3 MRV=3
MRV=3 MRV=3
MRV=3 MRV=3
Dr. Manel Mrabet
Detailed Example of MRV
Dr.Walid Aydi
Detailed Example of MRV
MRV=2 MRV=1
MRV=1
MRV=3 MRV=2
MRV=3 MRV=2
MRV=3 MRV=3
Dr. Manel Mrabet
Detailed Example of MRV
Dr.Walid Aydi
Degree Heuristic (DH)
(Caveat for tests, quizzes, and exams)
• This example works DH as a tie-breaker for MRV,
which is its usual role in practice.
Dr.Walid Aydi
Detailed Example of DH
(As a tie-breaker after MRV)
Dr.Walid Aydi
Detailed Example of DH
(As a tie-breaker after MRV)
• Initially, all regions have MRV = 3
• SA has DH=5 (e.g., SA=blue)
• Do Forward Checking (next topic)
MRV=3 MRV=2
DH=3 MRV=3 DH=2 MRV=2
DH=3 DH=2
MRV=3
MRV=3 MRV=3 MRV=2 MRV=2
DH=5
DH=2 DH=3 DH=1 DH=2
MRV=3 MRV=2
DH=2 DH=1
Dr.Walid Aydi
Detailed Example of DH
(As a tie-breaker after MRV)
MRV=2
DH=2 MRV=2 MRV=1
DH=2 DH=1
MRV=2 MRV=2 MRV=1 MRV=2
DH=1 DH=2 DH=0 DH=2
MRV=3 MRV=2
DH=2 DH=1
Dr.Walid Aydi
Detailed Example of DH
(As a tie-breaker after MRV)
• WA and Q have MRV = 1, Q has DH = 1
• Choose Q and assign it (i.e., Q=red)
• Do Forward Checking (next topic)
MRV=1
DH=1
MRV=1 MRV=2 MRV=1 MRV=1
DH=0 DH=2 DH=0 DH=1
MRV=3 MRV=2
DH=2 DH=1
Dr.Walid Aydi
least constraining value heuristic