![Page 1: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/1.jpg)
Constraint-Satisfaction Problems
19 October 2020
CMPU 365 · Artificial Intelligence
![Page 2: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/2.jpg)
Programming Assignment 1: Search
Programming Assignment 2: Multi-agent
Exam 1
Programming Assignment 3: Uncertainty Out soon!
Programming Assignment 4: Classification
Exam 2
Final project / paper
![Page 3: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/3.jpg)
The story so far
![Page 4: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/4.jpg)
The story so farSearch and planning
Define a state space
Define a goal test
Find path from start to goal
![Page 5: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/5.jpg)
The story so farSearch and planning
Define a state space
Define a goal test
Find path from start to goal
Game trees Define utilities
Find path from start that maximizes utility
![Page 6: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/6.jpg)
The story so farSearch and planning
Define a state space
Define a goal test
Find path from start to goal
Game trees Define utilities
Find path from start that maximizes utility
Markov decision processes Define rewards, utility = (discounted) sum of rewards
Find policy that maximizes utility
![Page 7: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/7.jpg)
The story so farSearch and planning
Define a state space
Define a goal test
Find path from start to goal
Game trees Define utilities
Find path from start that maximizes utility
Markov decision processes Define rewards, utility = (discounted) sum of rewards
Find policy that maximizes utility
Reinforcement learning Just like MDPs, but T and R are not known in advance
![Page 8: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/8.jpg)
The story so farSearch and planning
Define a state space
Define a goal test
Find path from start to goal
Game trees Define utilities
Find path from start that maximizes utility
Markov decision processes Define rewards, utility = (discounted) sum of rewards
Find policy that maximizes utility
Reinforcement learning Just like MDPs, but T and R are not known in advance
Today: Constraint satisfaction Find solution that satisfies constraints
Not just for finding a sequential plan
![Page 9: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/9.jpg)
Constraint-satisfaction problems
![Page 10: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/10.jpg)
What’s search for?
Planning: sequences of actionsWant: path to the goal
Paths have various costs and depths
Heuristics give problem-solving guiance
![Page 11: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/11.jpg)
What’s search for?
Planning: sequences of actionsWant: path to the goal
Paths have various costs and depths
Heuristics give problem-solving guiance
Identification: assignments to variablesThe goal itself is important, not the path
All paths at the same depth (for some formulations)
CSPs are a specialized class of identification problems
![Page 12: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/12.jpg)
Constraint-satisfaction problemsStandard search problems:
State is a “black box”– any data structure
Goal test can be any function over states
Successor function can also be anything
![Page 13: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/13.jpg)
Constraint-satisfaction problemsStandard search problems:
State is a “black box”– any data structure
Goal test can be any function over states
Successor function can also be anything
![Page 14: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/14.jpg)
Constraint-satisfaction problemsStandard search problems:
State is a “black box”– any data structure
Goal test can be any function over states
Successor function can also be anything
Constraint satisfaction problems (CSPs): State is defined by variables Xi with values from a domain D
Goal test is a set of constraints specifying allowable combinations of values for subsets of variables
![Page 15: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/15.jpg)
Constraint-satisfaction problemsStandard search problems:
State is a “black box”– any data structure
Goal test can be any function over states
Successor function can also be anything
Constraint satisfaction problems (CSPs): State is defined by variables Xi with values from a domain D
Goal test is a set of constraints specifying allowable combinations of values for subsets of variables
![Page 16: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/16.jpg)
Constraint-satisfaction problemsStandard search problems:
State is a “black box”– any data structure
Goal test can be any function over states
Successor function can also be anything
Constraint satisfaction problems (CSPs): State is defined by variables Xi with values from a domain D
Goal test is a set of constraints specifying allowable combinations of values for subsets of variables
Simple example of a formal representation language
![Page 17: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/17.jpg)
Constraint-satisfaction problemsStandard search problems:
State is a “black box”– any data structure
Goal test can be any function over states
Successor function can also be anything
Constraint satisfaction problems (CSPs): State is defined by variables Xi with values from a domain D
Goal test is a set of constraints specifying allowable combinations of values for subsets of variables
Simple example of a formal representation language
Allows useful general-purpose algorithms with more power than standard search algorithms
![Page 18: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/18.jpg)
Spectrum of representations
Search, game-playing
CSPs, planning, propositional logic,
Bayes nets, neural nets
First-order logic, databases,
probabilistic programs
Atomic Factored Structured
![Page 19: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/19.jpg)
CSP examples
![Page 20: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/20.jpg)
Example: Map coloring
Variables: WA, NT, Q, NSW, V, SA, T
Domains: D = {red, green, blue}
Constraints: Adjacent regions must have different colors
Implicit: WA ≠ NT
Explicit: (WA, NT) ∈ {(red, green), (red, blue), …}
![Page 21: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/21.jpg)
Example: Map coloring
Variables: WA, NT, Q, NSW, V, SA, T
Domains: D = {red, green, blue}
Constraints: Adjacent regions must have different colors
Implicit: WA ≠ NT
Explicit: (WA, NT) ∈ {(red, green), (red, blue), …}
Solutions are assignments satisfying all constraints, e.g., {WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = green}
![Page 22: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/22.jpg)
Constraint graphs
Binary CSP: Each constraint relates (at most) two variables.
Constraint graph: Nodes are variables; arcs show constraints.
General-purpose CSP algorithms can use the graph structure to speed up search.
E.g., Tasmania is an independent subproblem!
![Page 23: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/23.jpg)
Example: n-queens
![Page 24: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/24.jpg)
Example: n-queens
![Page 25: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/25.jpg)
Example: n-queens
Formulation 1: Variables: Xij
Domains: {0, 1} Constraints:
![Page 26: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/26.jpg)
Example: n-queens
Formulation 1: Variables: Xij
Domains: {0, 1} Constraints:
![Page 27: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/27.jpg)
Example: n-queens
Formulation 1: Variables: Xij
Domains: {0, 1} Constraints:
![Page 28: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/28.jpg)
Example: n-queens
Formulation 1: Variables: Xij
Domains: {0, 1} Constraints:
![Page 29: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/29.jpg)
Example: n-queens
Formulation 2: Variables: Qk
Domains: {1, 2, 3, …, N}
Constraints:
Implicit: ∀ i, j non-threatening(Qi, Qj)
Explicit: (Q1, Q2) ∈ {(1, 3), (1, 4), …}
…
![Page 30: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/30.jpg)
Example: Sudoku
Variables:Each (open) square
Domains:{1, 2, …, 9}
Constraints:
![Page 31: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/31.jpg)
Example: Sudoku
Variables:Each (open) square
Domains:{1, 2, …, 9}
Constraints:9-way alldiff for each column
![Page 32: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/32.jpg)
Example: Sudoku
Variables:Each (open) square
Domains:{1, 2, …, 9}
Constraints:9-way alldiff for each column
9-way alldiff for each row
![Page 33: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/33.jpg)
Example: Sudoku
Variables:Each (open) square
Domains:{1, 2, …, 9}
Constraints:9-way alldiff for each column
9-way alldiff for each row
9-way alldiff for each region
![Page 34: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/34.jpg)
Example: Sudoku
Variables:Each (open) square
Domains:{1, 2, …, 9}
Constraints:9-way alldiff for each column
9-way alldiff for each row
9-way alldiff for each region
(or can have a bunch of pairwise inequality constraints)
![Page 35: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/35.jpg)
Example: The Waltz algorithm
The Waltz algorithm is for interpreting line drawings of solid polyhedra as 3D objects
An early example of an AI computation posed as a CSP
Approach:
Each intersection is a variable
Adjacent intersections impose constraints on each other
Solutions are physically realizable 3D interpretations
?
![Page 36: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/36.jpg)
Example: The Waltz algorithm
The Waltz algorithm is for interpreting line drawings of solid polyhedra as 3D objects
An early example of an AI computation posed as a CSP
Approach:
Each intersection is a variable
Adjacent intersections impose constraints on each other
Solutions are physically realizable 3D interpretations
?
![Page 37: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/37.jpg)
Varieties of CSPs and constraints
![Page 38: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/38.jpg)
Varieties of CSPsDiscrete variables
Finite domains
Size d means O(dn) complete assignments
E.g., Boolean CSPs, including Boolean satisfiability (NP-complete)
Infinite domains (integers, strings, etc.)
E.g., job scheduling, variables are start/end times for each job
Linear constraints solvable
Nonlinear constraints undecidable
![Page 39: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/39.jpg)
Varieties of CSPsDiscrete variables
Finite domains
Size d means O(dn) complete assignments
E.g., Boolean CSPs, including Boolean satisfiability (NP-complete)
Infinite domains (integers, strings, etc.)
E.g., job scheduling, variables are start/end times for each job
Linear constraints solvable
Nonlinear constraints undecidable
Continuous variablesE.g., start/end times for Hubble Telescope observations
Linear constraints solvable in polynomial time by linear-programming methods
![Page 40: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/40.jpg)
Varieties of constraints
Unary constraints involve a single variable (equivalent to reducing domains), e.g.,
SA ≠ green
Binary constraints involve pairs of variables, e.g., SA ≠ WA
Higher-order constraints involve three or more variables, e.g.,
Sudoku row constraints
![Page 41: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/41.jpg)
Real-world CSPs
Scheduling problems, e.g., which class is offered when and where?
Hardware configuration / circuit layout
Transportation scheduling
Factory scheduling
Fault diagnosis
… and many more!Many real-world problems involve real-valued variables…
![Page 42: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/42.jpg)
Solving CSPs
![Page 43: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/43.jpg)
Standard search formulation
States defined by the values assigned so far (partial assignments)
Initial state: the empty assignment, {}
Successor function: assign a value to an unassigned variable
Goal test: the current assignment is complete and satisfies all constraints
We’ll start with the straightforward, naïve approach, then improve it.
![Page 44: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/44.jpg)
Search methods
What would BFS do?
Level 1
Search Methods
o What would BFS do?
…
…
…
Level 1
Level 2
Level N(solution here)
⋯
Level 2
Search Methods
o What would BFS do?
…
…
…
Level 1
Level 2
Level N(solution here)
⋯
⋯
Level N solution!
![Page 45: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/45.jpg)
Search methods
What would BFS do?
What would DFS do? Let’s see!
![Page 46: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/46.jpg)
Demo: Naïve (depth-first) search
![Page 47: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/47.jpg)
Search methods
What would BFS do?
What would DFS do? Let’s see!
What problems does naïve search have?
![Page 48: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/48.jpg)
Backtracking search
![Page 49: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/49.jpg)
Backtracking search is the basic uninformed algorithm for solving CSPs. It’s depth-first search with two improvements:
![Page 50: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/50.jpg)
Backtracking search is the basic uninformed algorithm for solving CSPs. It’s depth-first search with two improvements:
Idea 1: One variable at a time
Variable assignments are commutative, e.g.,
[WA = red then NT = green] same as [NT = green then WA = red]
so fix the ordering to get a smaller branching factor.
Only need to consider assignments to a single variable at each step
![Page 51: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/51.jpg)
Backtracking search is the basic uninformed algorithm for solving CSPs. It’s depth-first search with two improvements:
Idea 1: One variable at a time
Variable assignments are commutative, e.g.,
[WA = red then NT = green] same as [NT = green then WA = red]
so fix the ordering to get a smaller branching factor.
Only need to consider assignments to a single variable at each step
Idea 2: Check constraints as you go
Only consider values that don’t conflict with previous assignments
Might have to do some computation to check the constraints
“Incremental goal test”
![Page 52: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/52.jpg)
Backtracking search is the basic uninformed algorithm for solving CSPs. It’s depth-first search with two improvements:
Idea 1: One variable at a time
Variable assignments are commutative, e.g.,
[WA = red then NT = green] same as [NT = green then WA = red]
so fix the ordering to get a smaller branching factor.
Only need to consider assignments to a single variable at each step
Idea 2: Check constraints as you go
Only consider values that don’t conflict with previous assignments
Might have to do some computation to check the constraints
“Incremental goal test”
Can solve n-queens for n ≈ 25
![Page 53: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/53.jpg)
Backtracking example
![Page 54: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/54.jpg)
Backtracking example
![Page 55: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/55.jpg)
Backtracking example
![Page 56: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/56.jpg)
Backtracking example
![Page 57: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/57.jpg)
Backtracking example
![Page 58: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/58.jpg)
Demo: Backtracking
![Page 59: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/59.jpg)
Improving backtracking
![Page 60: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/60.jpg)
Improving backtracking
General-purpose ideas give huge gains in speed
![Page 61: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/61.jpg)
Improving backtracking
General-purpose ideas give huge gains in speedFiltering:
Can we detect inevitable failure early?
Ordering:
![Page 62: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/62.jpg)
Improving backtracking
General-purpose ideas give huge gains in speedFiltering:
Can we detect inevitable failure early?
Ordering:
Which variable should be assigned next?
In what order should its values be tried?
![Page 63: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/63.jpg)
Filtering
![Page 64: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/64.jpg)
Filtering: Keep track of domains for unassigned variables and cross off bad options
Forward checking: Cross off values that violate a constraint when added to the existing assignment
WASA
NT QNSW
V
![Page 65: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/65.jpg)
Filtering: Keep track of domains for unassigned variables and cross off bad options
Forward checking: Cross off values that violate a constraint when added to the existing assignment
WASA
NT QNSW
V
![Page 66: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/66.jpg)
Filtering: Keep track of domains for unassigned variables and cross off bad options
Forward checking: Cross off values that violate a constraint when added to the existing assignment
WASA
NT QNSW
V
![Page 67: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/67.jpg)
Filtering: Keep track of domains for unassigned variables and cross off bad options
Forward checking: Cross off values that violate a constraint when added to the existing assignment
WASA
NT QNSW
V
![Page 68: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/68.jpg)
Filtering: Keep track of domains for unassigned variables and cross off bad options
Forward checking: Cross off values that violate a constraint when added to the existing assignment
WASA
NT QNSW
V
![Page 69: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/69.jpg)
Filtering: Keep track of domains for unassigned variables and cross off bad options
Forward checking: Cross off values that violate a constraint when added to the existing assignment
WASA
NT QNSW
V
![Page 70: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/70.jpg)
Filtering: Keep track of domains for unassigned variables and cross off bad options
Forward checking: Cross off values that violate a constraint when added to the existing assignment
WASA
NT QNSW
V
![Page 71: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/71.jpg)
Demo: Backtracking with forward checking
![Page 72: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/72.jpg)
Ordering
![Page 73: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/73.jpg)
Variable ordering: Minimum remaining values (MRV): Choose the variable with the fewest legal values left in its domain
Why min rather than max?
Also called “most constrained variable”
“Fail-fast” ordering
![Page 74: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/74.jpg)
Variable ordering: Minimum remaining values (MRV): Choose the variable with the fewest legal values left in its domain
Why min rather than max?
Also called “most constrained variable”
“Fail-fast” ordering
![Page 75: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/75.jpg)
Variable ordering: Minimum remaining values (MRV): Choose the variable with the fewest legal values left in its domain
Why min rather than max?
Also called “most constrained variable”
“Fail-fast” ordering
![Page 76: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/76.jpg)
Variable ordering: Minimum remaining values (MRV): Choose the variable with the fewest legal values left in its domain
Why min rather than max?
Also called “most constrained variable”
“Fail-fast” ordering
![Page 77: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/77.jpg)
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)
Why least rather than most?
Combining these ordering ideas makes 1000 queens feasible
![Page 78: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/78.jpg)
Demo: Ordering
![Page 79: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/79.jpg)
Iterative improvement
![Page 80: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/80.jpg)
Iterative algorithms for CSPs
Local search methods typically work with “complete” states, i.e., all variables assigned.
![Page 81: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/81.jpg)
Iterative algorithms for CSPs
Local search methods typically work with “complete” states, i.e., all variables assigned.
≠
![Page 82: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/82.jpg)
Iterative algorithms for CSPs
Local search methods typically work with “complete” states, i.e., all variables assigned.
To apply to CSPs:Take an assignment with unsatisfied constraints
Operators reassign variable values
No tree, no frontier!
≠
![Page 83: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/83.jpg)
Iterative algorithms for CSPs
Local search methods typically work with “complete” states, i.e., all variables assigned.
To apply to CSPs:Take an assignment with unsatisfied constraints
Operators reassign variable values
No tree, no frontier!
≠ ≠
![Page 84: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/84.jpg)
Iterative algorithms for CSPs
Local search methods typically work with “complete” states, i.e., all variables assigned.
To apply to CSPs:Take an assignment with unsatisfied constraints
Operators reassign variable values
No tree, no frontier!
Algorithm: While not solved,Variable selection: randomly select any conflicted variable
Value selection: min-conflicts heuristic:
Choose a value that violates the fewest constraints
≠ ≠
![Page 85: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/85.jpg)
Example: 4-queens
States: 4 queens in 4 columns (44 = 256 states)
Operators: move queen in column
Goal test: no attacks
Evaluation: h(n) = number of attacks
![Page 86: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/86.jpg)
Demo: Iterative improvement – coloring
![Page 87: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/87.jpg)
Summary
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
Iterative min-conflicts is often effective in practice
![Page 88: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/88.jpg)
Local search
![Page 89: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/89.jpg)
Local search
Tree search keeps unexplored alternatives on the frontier (ensures completeness)
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)
![Page 90: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/90.jpg)
Hill climbing
Simple, general idea: Start wherever.
Repeat: Move to the best neighboring state.
If no neighbors better than current, quit.
![Page 91: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/91.jpg)
Hill climbing diagram
![Page 92: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/92.jpg)
Hill climbing quiz
Starting from X, where do you end up?
Starting from Y, where do you end up?
Starting from Z, where do you end up?
![Page 93: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/93.jpg)
Simulated annealing
Idea: Escape local maxima by allowing downhill moves But make them rarer as time goes on
![Page 94: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/94.jpg)
Genetic algorithms use a natural selection metaphor Keep best N hypotheses at each step (selection) based on a fitness function
Also have pairwise crossover operators, with optional mutation to give variety
Possibly the most misunderstood, misapplied (and even maligned) technique in AI
![Page 95: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/95.jpg)
Example: n-queens
Why does crossover make sense here?
When wouldn’t it make sense?
What would mutation be?
What would a good fitness function be?
![Page 96: Constraint-Satisfaction Problemscs365/lectures/2020-10-19.pdf · 10/19/2020 · Constraint satisfaction problems (CSPs): State is de!ned by variables X i with values from a domain](https://reader035.vdocuments.net/reader035/viewer/2022070216/611c4799aa696f68b7633cda/html5/thumbnails/96.jpg)
Acknowledgments
The lecture incorporates material from: Pieter Abbeel, Dan Klein, et al., University of California, Berkeley; ai.berkeley.edu
Ketrina Yim (illustrations)