06__Constraint_Satisfaction_Problems
06__Constraint_Satisfaction_Problems
VERSION 1.1
1
Constraint Satisfaction Problems
Solving CSPs
Filtering
Variable ordering
Value ordering
Smart backtracking
TODAY ON AI Problem structure
Questions?
2
Constraint Satisfaction Problems
SECTION 01
3
ARTIFICIAL INTELLIGENCE Constraint Satisfaction problems (CSPs) 101
EXAMPLES
Map coloring! Assignment problems
Sudokus Transportation scheduling
Crossword puzzles Fault diagnosis
Job scheduling More…
Cryptarithmetic puzzles
N-Queens problems
Hardware configuration
4
ARTIFICIAL INTELLIGENCE Constraint Satisfaction problems (CSPs) 102
Discrete variables:
• Domains can be finite: a finite of size set of values or things (means complete
assignments). Examples are: Boolean values, specific meaningful numbers, set of
colors, etc.
• or infinite: integers or strings. Examples are: strings for a crossword puzzle, duration of
jobs in seconds, etc.
Continuous variables:
• Domains are infinite. Examples are: start/end times for Hubble Telescope observations
as they obey to astronomical time laws
5
ARTIFICIAL INTELLIGENCE Constraint Satisfaction problems (CSPs) 103
6
ARTIFICIAL INTELLIGENCE Constraint Satisfaction problems (CSPs) 104
EXAMPLE: COLORING AUSTRALIA
VARIABLES
Solutions are assignments that
WA, NT, Q, NSW, V, SA, T
satisfying all constraints:
DOMAINS
{ } WA NT Q
NSW V SA
CONSTRAINTS
NORTHERN Adjacent regions must T
TERRITORY have different colors:
QUEENSLAND
WESTERN
AUSTRALIA Implicit: WA SA,
SOUTH
AUSTRALIA WA NT, NT SA,
NEW SOUTH NT Q, Q SA, Q NSW,
WALES
NSW SA, NSW V, V
VICTORIA SA
Explicit: , ∈
,
etc.
TASMANIA
7
ARTIFICIAL INTELLIGENCE Constraint Satisfaction problems (CSPs) 105
EXAMPLES: SUDOKU
VARIABLES
Open squares
DOMAINS
{1, 2, 3, … 9}
CONSTRAINTS
RULES
8
Solving CSPs
SECTION 2
9
ARTIFICIAL INTELLIGENCE Solving CSPs 201
STANDARD SEARCH FORMULATION
The idea is to use standard search algorithms (DFS and BFS) to find a solution
that satisfies all the constraints.
STATES
The variables assigned with values so far
INITIAL STATE
All variable assignments are empty
SUCCESSOR FUNCTION
Assign a value to an unassigned variable
GOAL TEST
The current assignment is complete and satisfies all constraints
10
ARTIFICIAL INTELLIGENCE Solving CSPs 202
CHRONOLOGICAL BACKTRACKING SEARCH
IMPROVEMENT 1
Each step considers only one assignment at the time
IMPROVEMENT 2
Check constraints as the search continues. Consider only new assignments
which do not conflict previous assignments (incremental goal test)
11
ARTIFICIAL INTELLIGENCE Backtracking search 203
COLORING EXAMPLE
12
ARTIFICIAL INTELLIGENCE Backtracking search 204
PSEUDO-CODE
13
ARTIFICIAL INTELLIGENCE Backtracking search 205
IMPROVING BY BAILING OUT EARLIER
IMPROVEMENT 1
Taking divination class: filter out inevitable failures as early as possible
IMPROVEMENT 2
Do not choose poorly: choose carefully which variable for assignment
IMPROVEMENT 3
You should never, never doubt something that no one is sure of: choose judicially
what value to use
IMPROVEMENT 4
Where we're going we don't need... roads: choose judicially where to backtrack to
IMPROVEMENT 5
See the whole board: use the topology of the problem, or its structure, to assign
variables
14
Filtering
SECTION 03
15
ARTIFICIAL INTELLIGENCE Filtering
FORWARD CHECKING
Forward checking keeps track of the domains for the unassigned variables
and remove possible bad options right away
16
ARTIFICIAL INTELLIGENCE Filtering
ARC CONSISTENCY
17
ARTIFICIAL INTELLIGENCE Filtering
ARC CONSISTENCY: THE ALGORITHM
18
ARTIFICIAL INTELLIGENCE Filtering
ARC CONSISTENCY CANNOT RUN ALONE
19
Variable ordering
SECTION 04
20
ARTIFICIAL INTELLIGENCE Ordering
PICKING A VARIABLE
In order to prune even more illegal assignments, we also have to consider how
we choose the variables:
21
Value ordering
SECTION 05
22
ARTIFICIAL INTELLIGENCE Ordering 501
VALUE ORDERING: PICKING THE VALUE
Least Constraining Value (LCV): Once the variable is selected, choose the
value that rules out the fewest choices for the neighbors
23
Smart backtracking
SECTION 06
24
ARTIFICIAL INTELLIGENCE Intelligent backtracking 601
LOOKING BACKWARD
VARIABLE ORDER
Q, NSW, V, T, SA, WA, NT
25
ARTIFICIAL INTELLIGENCE Intelligent backtracking 602
CONFLICT-DIRECTED BACKJUMPING
CONFLICT SET
1: WA = CONFLICT SET SA CONFLICT SET
2: NT = 4: Q =
3: NT =
1. WA = CONFLICT SET 1: NSW =
2: NSW =
2. NSW = 1: WA =
3. T=
4. NT =
CONFLICT SET Q CONFLICT SET CONFLICT SET
5. Q= 2: NT = 3: NT =
1: NSW = 2: NSW =
CONFLICT SET
1: WA =
4: Q =
SA = ? 3: NT =
2: NSW =
1: WA =
NT CONFLICT SET CONFLICT SET
1: WA = 2: NSW =
1: WA =
NSW
26
Problem structure
SECTION 07
27
ARTIFICIAL INTELLIGENCE Problem structure 701
DIVIDE AND CONQUER
28
ARTIFICIAL INTELLIGENCE Problem structure 702
TREE-STRUCTURED CSPS
1. Remove backward: Apply arc consistency from the deepest leaf to its
parent. After this phase, all arcs are consistent.
2. Assign forward: Assign a value to the variable consistent with its parent.
Forward assignment will never backtrack.
29
ARTIFICIAL INTELLIGENCE Problem structure 703
NEARLY TREE-STRUCTURED CSPS
The process requires to instantiate the variables of the cutset and prune its
neighbors’ domain.
30
ARTIFICIAL INTELLIGENCE Problem structure 704
NEARLY TREE-STRUCTURED CSPS: EXAMPLE
31
QUESTIONS ?
32