0% found this document useful (0 votes)
11 views24 pages

Chapter 6 - CS Search

Uploaded by

bobjan6900
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views24 pages

Chapter 6 - CS Search

Uploaded by

bobjan6900
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Artificial

Intelligence
Constraint satisfaction problems
Constraint satisfaction problems (CSPs)
 Standard search problem:
• state is a “black box “
• that supports goal test, evaluation, successor
 Goal test can be any function over states
 Successor function can also be anything
 CSP:
• A special subset of search problems
• 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
DEFINING CONSTRAINT SATISFACTION PROBLEMS

 Each domain Di consists of a set of allowable values, {v1, . . . , vk} for variable
Xi.
 Each constraint Ci consists of a pair <scope, rel> , where scope is a tuple of
variables that participate in the constraint and rel is a relation that defines
the values that those variables can take on.
Relations
 if X1 and X2 both have the domain {A,B}, then the constraint saying the two
variables must have different values can be written as:

 OR
 To solve a CSP, we need to define a state space and the notion of a solution.

 Each state in a CSP is defined by an assignment of values to some or all of


the variables

 An assignment that does not violate any constraints is called a consistent or


legal assignment.
 A complete assignment is one in which every variable is assigned, and a
solution to a CSP is a consistent, complete assignment.
 A partial assignment is one that assigns values to only some of the variables.
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) can be any of {(red , green),


(red , blue), (green, red ), (green, blue),
(blue, red ), (blue, green)}
Example: Map-Coloring contd.

 Solutions are assignments satisfying all constraints, e.g.,


 {WA=red, NT =green, Q=red, NSW =green, V =red, SA=blue, T =green}
Example: Sudoku
 Variables:
• Each (open) square
 Domains:
• {1,2,…,9}
 Constraints:
• 9-way alldiff for each row
• 9-way alldiff for each column
• 9-way alldiff for each region
Constraint graph
 Constraint graph: nodes are variables, arcs show constraints
 General-purpose CSP algorithms use the graph structure to speed up search.
Varieties of CSPs
 Unary constraints: involve a single variable,
• e.g., SA ≠ green

 binary constraint: relates two variables.


• For example, SA≠NSW is a binary constraint.

 Higher-order constraints: involve 3 or more variables,


• e.g., crypt-arithmetic column constraints
 Preferences (soft constraints): e.g., red is better than green often
representable by a cost for each variable assignment
• constrained optimization problems
Real-world CSPs
 Assignment problems
• e.g., who teaches what class
 Timetabling problems
• e.g., which class is offered when and where?
 Hardware configuration
 Transportation scheduling
 Factory scheduling
 Circuit layout
 Fault diagnosis
Solving CSPs
 Standard search formulation of CSPs
 States defined by the values assigned
• Initial state: the empty assignment, {}
• Successor function: assign a value to an
unassigned variable that does not conflict
with current assignment.
• ==> fail if no legal assignments (not fixable!)
• Goal test: the current assignment is complete
and satisfies all constraints
Backtracking Search
 Backtracking search is the basic uninformed algorithm for solving CSPs
 Idea 1: One variable at a time
• Variable assignments are commutative, so fix ordering
• I.e., [WA = red then NT = green] same as [NT = green then WA = red]
• Only need to consider assignments to a single variable at each step
 Idea 2: Check constraints as you go
• I.e. consider only values which do not conflict previous assignments
• Might have to do some computation to check the constraints
• “Incremental goal test”
 Depth-first search with these two improvements is called backtracking
search
Backtracking Example
Improving Backtracking
 General-purpose ideas give huge gains in speed
 Ordering:
• Which variable should be assigned next?
• In what order should its values be tried?
 Filtering: Can we detect inevitable failure early?
Filtering: Forward checking
 Idea: Keep track of remaining legal values for unassigned variables and cross
off bad options
 Terminate search when any variable has no legal values
 Forward checking: Cross off values that violate a constraint when added to
the existing assignment
Forward checking
 Idea: Keep track of remaining legal values for unassigned variables
 Terminate search when any variable has no legal values
Forward checking
 Idea: Keep track of remaining legal values for unassigned variables
 Terminate search when any variable has no legal values
Forward checking
 Idea: Keep track of remaining legal values for unassigned variables
 Terminate search when any variable has no legal values
Constraint propagation
 Forward checking propagates information from assigned to unassigned
variables, but doesn't provide early detection for all failures:
 NT and SA cannot both be blue!
 Constraint propagation repeatedly enforces constraints locally
Arc consistency
 Simplest form of propagation makes each arc consistent
 X  Y is consistent iff
• for every value x of X there is some allowed y
Arc consistency
 Simplest form of propagation makes each arc consistent
 X  Y is consistent iff
• for every value x of X there is some allowed y
Arc consistency
 Simplest form of propagation makes each arc consistent
 X  Y is consistent iff
• for every value x of X there is some allowed y

• f X loses a value, neighbors of X need to be rechecked


Arc consistency
 Simplest form of propagation makes each arc consistent
 X  Y is consistent iff
• for every value x of X there is some allowed y

 If X loses a value, neighbors of X need to be rechecked


 Arc consistency detects failure earlier than forward checking
 Can be run as a preprocessor or after each assignment

You might also like