CS 106: Artificial Intelligence: Constraint Satisfaction Problems
CS 106: Artificial Intelligence: Constraint Satisfaction Problems
♛
Implicit:
Explicit:
♛
♛
Example: Sudoku
Variables:
Each (open) square
Domains:
{1,2,…,9}
Constraints:
Continuous variables
E.g., start/end times for Hubble Telescope observations
Varieties of Constraints
Varieties of Constraints
Unary constraints involve a single variable (equivalent to
reducing domains), e.g.:
♛
♛
What would DFS do?
♛
♛
♛ ♛ ♛
♛
♛
… … … … … ♛
♛ ♛
♛ ♛ ♛
♛
♛ … ♛
♛ … ♛
… … … ♛
♛
… ♛
♛
♛ ♛ ♛
♛ ♛ ♛ ♛ ♛ ♛ ♛
♛
♛
♛
… ♛
♛ … ♛
♛
♛ … ♛ ♛
♛ … … ♛
♛
♛
… ♛
♛
♛ … … ♛
♛
♛
♛
DFS?
♛ ♛
♛
♛
♛
…
♛
♛ ♛ ♛ ♛
♛ ♛
♛ …… ♛
…
♛
♛
♛ ♛
♛ ♛
♛
♛
♛
♛
♛
♛ …
♛
♛
♛
♛
… ♛
… ♛
♛ ♛ ♛
♛ ♛ ♛ ♛
♛ ♛♛
♛
♛
♛
♛ …
♛
♛
♛
♛
… ♛
♛
♛
♛ ♛ ♛ ♛
♛ ♛
Backtracking Search
Backtracking Search
Backtracking search is the basic uninformed algorithm for solving CSPs
Idea 1: One variable at a time
Only need to consider assignments to a single variable at each step
♛
♛
♛
♛
♛ ♛
♛
♛
♛ ♛
♛ ♛
♛ ♛
♛ ♛
♛
♛
♛
♛
Map Coloring with Backtracking
https://vi.wikipedia.org/
Map Coloring with Backtracking
https://camranhcitygate.info/
Backtracking Example
Backtracking Search
Ordering:
Which variable should be assigned next?
In what order should its values be tried?
Vạn Ninh Ninh Hòa Khánh Vĩnh Diên Khánh Nha Trang Cam Lâm Khánh Sơn Cam Ranh Trường Sa
Filtering: Constraint Propagation
Forward checking propagates information from assigned to unassigned variables, but
doesn't provide early detection for all failures:
Vạn Ninh Ninh Hòa Khánh Vĩnh Diên Khánh Nha Trang Cam Lâm Khánh Sơn Cam Ranh Trường Sa
https://www.cs.upc.edu/~erodri/webpage/cps/cps.html
Arc Consistency of an Entire CSP
A simple form of propagation makes sure all arcs are consistent:
Vạn Ninh Ninh Hòa Khánh Vĩnh Diên Khánh Nha Trang Cam Lâm Khánh Sơn Cam Ranh Trường Sa
Remember: Delete
from the tail!
https://www.cs.upc.edu/~erodri/webpage/cps/cps.html
Limitations of Arc Consistency
Ordering:
Which variable should be assigned next?
In what order should its values be tried?
Vạn Ninh Ninh Hòa Khánh Vĩnh Diên Khánh Nha Trang Cam Lâm Khánh Sơn Cam Ranh Trường Sa
Ordering: Minimum Remaining Values
Variable Ordering: Minimum remaining values (MRV):
Choose the variable with the fewest legal left values in its domain
Vạn Ninh Ninh Hòa Khánh Vĩnh Diên Khánh Nha Trang Cam Lâm Khánh Sơn Cam Ranh Trường Sa
Ordering: Least Constraining Value
Value Ordering: Least Constraining Value
Given a choice of variable, choose the least
constraining value
I.e., the one that rules out the fewest values in
the remaining variables
Note that it may take some computation to
determine this! (E.g., rerunning filtering)
Ordering:
Which variable should be assigned next?
In what order should its values be tried?
Theorem: if the constraint graph has no loops, the CSP can be solved in O(n d 2) time
Compare to general CSPs, where worst-case time is O(dn)
Tree-Structured CSPs
Improving Structure
Nearly Tree-Structured CSPs
Vạn Ninh Ninh Hòa Khánh Vĩnh Diên Khánh Nha Trang Cam Lâm Khánh Sơn Cam Ranh Trường Sa
Tree-Structured CSP
Algorithm for tree-structured CSPs:
Order: Choose a root variable, order variables so that parents precede children
Vạn Ninh Ninh Hòa Nha Trang Khánh Vĩnh Khánh Sơn Cam Ranh
To apply to CSPs:
Take an assignment with unsatisfied constraints
Operators reassign variable values
No fringe! Live on the edge.
♛ ♛ 0 3 1 ♛
♛ ♛ ♛
♛ ♛ ♛
♛ ♛ ♛
Performance of Min-Conflicts
Given random initial state, can solve n-queens in almost constant time for arbitrary
n with high probability (e.g., n = 10,000,000)!
The same appears to be true for any randomly-generated CSP except in a narrow
range of the ratio
Summary: CSPs
CSPs are a special kind of search problem:
States are partial assignments
Goal test defined by constraints
Basic solution: backtracking search
Speed-ups:
Ordering
Filtering
Structure
Local search: improve a single option until you can’t make it better
New successor function: local changes
Generally much faster and more memory efficient (but incomplete and suboptimal)
Pretty much unavoidable when the state is “yourself”
Hill Climbing
Simple, general idea:
Start wherever
Repeat: move to the best neighboring state
If no neighbors better than current, quit
Hill Climbing
64
Hill Climbing Diagram
Hill Climbing Quiz
67
Simulated Annealing
Theoretical guarantee:
Stationary distribution (Boltzmann):
If T decreased slowly enough,
will converge to optimal state!
Possibly the most misunderstood, misapplied (and even maligned) technique around
Example: N-Queens
71
Local Search in Continuous Spaces
Cost f(x1,y1,x2,y2,x3,y3) =
(x1,y1)
73
Example: Fault Diagnosis
Causes Symptoms
Fault networks:
Variables? SMTP down
Can’t email
Domains?
DNS down
Constraints? Can’t IM
Firewall
blocking
Various ways to query, Can’t print
Printer jam
given symptoms
Some cause (abduction)
Simplest cause
All possible causes
What test is most useful?
Prediction: cause to effect