AI-Constraint Satisfaction Problems (1)
AI-Constraint Satisfaction Problems (1)
Shumet Tadesse
Department of Computer Science
July 2022
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Outline
2 Backtracking Search
3 Forward Checking
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 2 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Outline
2 Backtracking Search
3 Forward Checking
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 2 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Outline
2 Backtracking Search
3 Forward Checking
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 2 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Outline
2 Backtracking Search
3 Forward Checking
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 2 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Outline
2 Backtracking Search
3 Forward Checking
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 3 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Map-Coloring
• This is a famous example in AI and is often used to illustrate
CSPs.
• Suppose we have a map of a country, like the map of Australia
as shown below.
− The country is divided into a number of regions.
• The problem is how we can colour each region of the country
using a limited number of colours (in this case 3, RGB) so that
no two adjacent regions have the same colour.
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 5 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Example: Map-Coloring
• Variables: WA, NT, Q, NSW, V, SA, T
• Domains Di = red, green, blue
• Constraints: adjacent regions must have different colors, e.g.
WA NT, or (WA,NT) in
{(red, green), (red, blue), (green, red), (green, blue), (blue, red),
(blue,green)}
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 6 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Example: Map-Coloring
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 7 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Constraint Graph
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 8 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Varieties of CSPs
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 9 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Varieties of CSPs
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 10 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Real-world CSPs
• Timetable scheduling
− E.g., Which class is offered when and where? Who teaches
what class?
• Transportation scheduling
− Assignment of vehicle to drivers/jobs
• Factory scheduling
− Assignment of staff to jobs/machines, deadlines, etc.
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 11 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Outline
2 Backtracking Search
3 Forward Checking
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 13 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Backtracking Search
• The term backtracking search is used for a depth-first search
that:
− chooses values for one variable at a time and
− backtracks when a variable has no legal values left to assign.
• Variable assignments are commutative, i.e.,
[ WA = red followed by NT = green ] is the same as
[ NT = green followed by WA = red ]
Backtracking Example
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 14 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 15 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 16 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 17 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Outline
2 Backtracking Search
3 Forward Checking
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 19 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Forward Checking
• Idea: keep track of remaining legal values for unassigned
variables.
• Terminate search when any variable has no legal values.
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 20 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Forward Checking
• 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
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 21 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Forward Checking
• 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.
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 22 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Outline
2 Backtracking Search
3 Forward Checking
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 23 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 24 / 25
Constraint Satisfaction Problems (CSPs) Backtracking Search Forward Checking Local search for CSPs
Exercises
Consider the map of Ethiopia for the problem of map coloring.
Shumet Tadesse (Dept. of Computer Science) Chapter 3 - Part II: CSPs July 2022 25 / 25