1CS 188: Artificial IntelligenceSpring 2006Lecture 4: CSPs9/7/2006Dan Klein – UC BerkeleyMany slides over the course adapted from either Stuart Russell or Andrew MooreAnnouncements Reminder: Project 1.1 is due Friday at 11:59pm! Check web page for this week’s office hours Sections this Monday Can go to any of them, or multiple (unless over capacity of room) Dan / John back late today Don’t forget about the newsgroup Good for course questions Good for finding partners2Constraint Satisfaction Problems Standard search problems: State is a “black box”: any old data structure Goal test: any function over states Successors: any map from states to sets of states Constraint satisfaction problems (CSPs): State is defined by variables Xiwith values from a domain D (sometimes D depends on i) 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 algorithmsExample: N-Queens Formulation 1: Variables: Domains: Constraints3Example: N-Queens Formulation 2: Variables: Domains: Constraints:… there’s an even better way! What is it?Example: Map-Coloring Variables: Domain: Constraints: adjacent regions must have different colors Solutions are assignments satisfying all constraints, e.g.:4Example: The Waltz Algorithm The Waltz algorithm is for interpreting line drawings of solid polyhedra An early example of a computation posed as a CSP Look at all intersections Adjacent intersections impose constraints on each other?Waltz on Simple Scenes Assume all objects: Have no shadows or cracks Three-faced vertices “General position”: no junctions change with small movements of the eye. Then each line on image is one of the following: Boundary line (edge of an object) (→) with right hand of arrow denoting “solid” and left hand denoting “space” Interior convex edge (+) Interior concave edge (-)5Legal Junctions Only certain junctions are physically possible How can we formulate a CSP to label an image? Variables: vertices Domains: junction labels Constraints: both ends of a line should have the same labelxy(x,y) in,, …Constraint Graphs Binary CSP: each constraint relates (at most) two variables Constraint graph: nodes are variables, arcs show constraints General-purpose CSP algorithms use the graph structure to speed up search. E.g., Tasmania is an independent subproblem!6Example: Cryptarithmetic Variables: Domains: Constraints:Varieties of CSPs Discrete 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 Need a constraint language, e.g., StartJob1+ 5 < StartJob3 Linear constraints solvable, nonlinear undecidable Continuous variables E.g., start/end times for Hubble Telescope observations Linear constraints solvable in polynomial time by LP methods (see cs170 for a bit of this theory)7Varieties of Constraints Varieties of Constraints Unary constraints involve a single variable (equiv. to shrinking domains): Binary constraints involve pairs of variables: Higher-order constraints involve 3 or more variables:e.g., cryptarithmetic column constraints Preferences (soft constraints): E.g., red is better than green Often representable by a cost for each variable assignment Gives constrained optimization problems (We’ll ignore these until we get to Bayes’ nets)Real-World CSPs Assignment problems: e.g., who teaches what class Timetabling problems: e.g., which class is offered when and where? Hardware configuration Spreadsheets Transportation scheduling Factory scheduling Floorplanning Many real-world problems involve real-valued variables…8Standard Search Formulation Standard search formulation of CSPs (incremental) Let's start with the straightforward, dumb approach, then fix it States are defined by the values assigned so far Initial state: the empty assignment, {} Successor function: assign a value to an unassigned variable Goal test: the current assignment is complete and satisfies all constraintsSearch Methods What does BFS do? What does DFS do? [ANIMATION] What’s the obvious problem here? What’s the slightly-less-obvious problem?9Backtracking Search Idea 1: Only consider a single variable at each point: Variable assignments are commutative 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 How many leaves are there? Idea 2: Only allow legal assignments at each point I.e. consider only values which do not conflict previous assignments Might have to do some computation to figure out whether a value is ok Depth-first search for CSPs with these two improvements is called backtracking search [ANIMATION] Backtracking search is the basic uninformed algorithm for CSPs Can solve n-queens for n ≈ 25Backtracking Search What are the choice points?10Backtracking ExampleImproving Backtracking General-purpose ideas can give huge gains in speed: Which variable should be assigned next? In what order should its values be tried? Can we detect inevitable failure early? Can we take advantage of problem structure?11Minimum Remaining Values Minimum remaining values (MRV): Choose the variable with the fewest legal values Why min rather than max? Called most constrained variable “Fail-fast” orderingDegree Heuristic Tie-breaker among MRV variables Degree heuristic: Choose the variable with the most constraints on remaining variables Why most rather than fewest constraints?12Least Constraining Value Given a choice of variable: Choose the least constraining value The one that rules out the fewest values in the remaining variables Note that it may take some computation to determine this! Why least rather than most? Combining these heuristics makes 1000 queens feasibleForward Checking Idea: Keep track of remaining legal values for unassigned variables Idea: Terminate when any
View Full Document