07ConstraintSatisfaction

.pdf
School
University of Illinois, Urbana Champaign**We aren't endorsed by this school
Course
CSE 388
Subject
Computer Science
Date
Dec 17, 2024
Pages
60
Uploaded by MajorGull4766
Listen carefully! I might rhyme with "orange" in EECS 492 Topic 7:Constraint Satisfaction!You belong here.Think about how much more you know now compared to 1 year ago. You did that! Keep pushing forward and you'll learn more and more.Please download these slides for class: Canvas course, "Google Drive" linkxkcd.com
Background image
Midterm Exam: 10/8, 7 8:20 PMTentative / in the works:Room assignmentsSSD details for those that have already heard from mePractice exam will be released soon (without solutions). Try it like a real test!Special review session tentatively on 10/5, 1-3PM, room TBAPractice exam solutions:Discussed in review sessionReleased after review sessionAllowed: One 8.5” x 11” double-sided reference sheet. Nothing else.Topics: Everything through topic 8 (Propositional Logic), but not topic 9 (PL Inference).Prior midterm exams were no-notes, so some questions then were easier (e.g., vocabulary).Current draft of midterm exam is all multiple choice, but that may change.Still requires problem-solving (e.g., do an A* search on this graph…)20% of course grade. "How many points" doesn't actually matter; whatever your percentage is will be scaled to count for 20% of course grade. (e.g., 75% on exam means 15% / 20% towards course grade).
Background image
Constraint Satisfaction ProblemsA CSP is framed as:a set of variablesto which values must be assigned,with constraintson allowable values.Assign one of three colors to each territory such that no adjacent territories have the same color.Factory: In what order should assembly occur given a required partial ordering of steps and what steps can be completed simultaneously?http://www.lyndexnikken.com/job-shopU-M: Where and when should classes be held given constraints on rooms, instructors, and student needs?https://pharmacy.umich.edu/file/l2-classroomjpg
Background image
Constraint Satisfaction ProblemsA CSP is framed as:a set of variablesto which values must be assignedwith constraintson allowable values.Strategy:1)Constraint Propagation to eliminate disallowed combinations of values2)Searchamong the remaining possible values (if any!)Local search, or something specific for CSPs like backtracking searchUsually includes inference to eliminate more disallowed values
Background image
Solving CSPsAssignmentspecifies values for variablesPartial assignmentfor some variablesComplete assignmentfor all variablesConsistent assignmentviolates no constraintsaka legal assignmentMay be partial or completeSolution: A complete and consistent assignmentBenefit: break the CSP into sub-problemsIf partial assignment isn't consistent, any corresponding full assignment won't be either
Background image
Defining a CSPX1, X2have domain {1,2,3}.Constraint that X1> X2:< (X1, X2), {(3,1), (3,2), (2,1)} >or just< (X1, X2), X1>X2 >Problem consists of three components:Xa set of variables {X1, …, Xn}We want to know these valuesDset of domains {D1, …, Dn} each is a set of allowed values for a variableDomain Di set {v1, …, vk} of allowable values for variable XiCset of constraints (allowable combinations of variables)Constraint: <scope, rel>scopetuple of variables that participate in the constraintrelrelation that defines values variables can takeConstraints let us eliminate disallowed combinations, to reduce the search space.1)Constraint propagationto eliminate disallowed values.2)Searchamong remaining values, + inference.
Background image
Example: Map ColoringGoal color in each region: (pink, yellow, blue)Constraint: no neighbors have same colorDefine CSP:Variables: X = {WA, NT, Q, NSW, V, SA, T}Domains: iDi= {pink, yellow, blue}Constraints: C= {SAWA, SA NT, SAQ, …}Shorthand: SAWAis <(SA, WA), {(pink, yellow),(pink, blue),(yellow, pink), (yellow, blue),(blue, pink),(blue, yellow)}>Constraint GraphEdge means constraintX1 X2X3X4X5 X6 X7
Background image
Constraint GraphWANTSAQNSWVTSAHow many complete (and not necessarily consistent)assignments are there?7 variables, 3 choices per variable37= 2187T has no constraints, so it can be anything! Let's say blue.Remaining assignments to consider:36= 729Let's just pick SA to be blue.Remaining assignments to consider:35= 243So now we know WA, NT, Q, NSQ, and V must each be pink or yellow.Remaining assignments to consider:25= 32TSANTWAQNSWVWith just a few easy steps, we've greatly reduced the search space!Some generally-applicable rules can help us act similarly in a systematic way.
Background image
Local Consistency: InferenceEliminatecertain disallowed combinations.One elimination another another.This is called constraint propagation.Consider constraints through generally-applicable requirements:Node-consistencyArc-consistencyPath-consistencyK-consistency1)Constraint propagationto eliminate disallowed values.2)Searchamong remaining values, + inference.
Background image
Node-ConsistencyConstraint: <scope, rel>SA hates yellow:<(SA),{(pink), (blue)}>If a constraint says SA can't be yellow, achieve node-consistency for SA by reducing SA's domain from{yellow, pink, blue}to{pink, blue}Unary constraint: scope contains exactly one variableXiis node-consistentmeans"All values in Disatisfy Xi's unary constraints"We can achieve node-consistency of Xiby reducing the domain of Xi.A CSP is node-consistentiff every variable is node consistent.Why nodeinstead of state?Contains variable value (state) plus additional info (domain, constraints).
Background image
Node-Consistency AlgorithmFor each unary constraintEliminate disallowed value(s)If any variable ends up with an empty domain, there is no solution to the CSP.X1 with domain D1={1,2,3,4,5,6,7,8} Constraints:CA: X1must be evenCB: X1must be > 5CA: reduce to D1={2,4,6,8}CB: reduce further to D1={6,8}1)Constraint propagationApply node-consistency algorithm2)Search+ inference.
Background image
Arc-ConsistencyBinary constraint: scope contains exactly two variablesXiis arc-consistentw.r.t. Xjmeans:"For anyvalue we give Xifrom its domain, Xjstill has a possible value."We can achieve arc-consistency of Xiw.r.t. Xjby reducing the domain of Xi.A CSP is arc-consistentiff every variable is arc-consistent w.r.t. every other variable.SA ≠ WA:<(SA, WA),{(pink, yellow), …}>Constraint: <scope, rel>There's also a definition of generalized arc-consistencyfor constraints involving >2 variables…For such u Diand v Djwe can say that v is a supportof u.
Background image
X1with D1= {2,3}X2with D2= {1,4}X1< X2:<(X1, X2), {(2,4), (3,4)}>Is X1arc-consistent w.r.t. X2? X1< X2u D1v D2:X1=2: X2=4 is allowed X1=3: X2=4 is allowed YES! X1is arc-consistent w.r.t. X2.Is X2arc-consistent w.r.t. X1? X1< X2u D2v D1:X2=1: noX1is allowedXX2=4: both X1=2 and X1=3 are allowed NO! X2is not arc-consistent w.r.t. X1.We need to reduce X2's domain to D2={4} to make X2arc-consistent w.r.t. X1.Arc-Consistency:ExampleArc-consistency is a binary relation. This example shows thatarc-consistency is notsymmetric.That is:(Xiarc-consistent w.r.t. Xj) does not necessarily imply (Xjarc-consistent w.r.t. Xi)
Background image
Arc-Consistency:Exercise 1X with DX= {0, 1, 2, 3, 4, 5}Y with DY= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}Constraint: Y = X21) Explain why X is not arc-consistent w.r.t. Y.2) Show any domain changes necessary to make X arc-consistent w.r.t. Y.Check solution on next slide afteryou try this!
Background image
Arc-Consistency:Solution 1X with DX= {0, 1, 2, 3, 4, 5}Y with DY= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}Constraint: Y = X21) Explain why X is not arc-consistent w.r.t. Y.2) Show any domain changes necessary to make X arc-consistent w.r.t. Y.Do the next exercise too!When X = 4, no value in DYcan satisfy Y=42.When X = 5, no value in DYcan satisfy Y=52.Update DX= {0, 1, 2, 3}X arc-consistent w.r.t. Y would mean:u DXv DY: X=u and Y=v is allowed
Background image
Arc-Consistency:Exercise 2X with DX= {0, 1, 2, 3} (updated from previous exercise)Y with DY= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}Constraint: Y = X21) Explain why Y is not arc-consistent w.r.t. X.2) Show any domain changes necessary to make Y arc-consistent w.r.t. X.Check solution on next slide afteryou try this!
Background image
Arc-Consistency:Solution 2X with DX= {0, 1, 2, 3} (updated from previous exercise)Y with DY= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}Constraint: Y = X21) Explain why Y is not arc-consistent w.r.t. X.2) Show any domain changes necessary to make Y arc-consistent w.r.t. X.Y arc-consistent w.r.t. X would mean:u DYv DX: Y=u and X=v is allowedWhen Y=2, no value in DXcan satisfy 2=X2.Similarly for 3=X2, 5=X2, 6=X2, 7=X2, 8=X2Update DY= {0, 1, 4, 9}If Y=X2is our only constraint, then the entire CSP is arc-consistent with updated domains:DX= {0, 1, 2, 3}DY= {0, 1, 4, 9}
Background image
Arc-Consistency Algorithm: AC-3Suppose we eliminate one value vfrom Dj.1) Best case:v Djwasn't "essential" (the only support)for any u DiNothing more to do as a result of eliminating vfrom Dj.Mackworth, Alan K. "Consistency in networks of relations."Artificial intelligence8.1 (1977): 99-118.XjXiDj={…,v,…}Di={ }vNo u Dicould be paired with v Djanyway.XjXiDj={…,v,…}Di={ }…,u,…vAny u Dithat could be paired with v Djcould also be paired with some other value in Dj.1)Constraint propagationApply node-consistency algorithmApply arc-consistency algorithm2)Search+ inference
Background image
Arc-Consistency Algorithm: AC-3Suppose we eliminate one value vfrom Dj.2) Or there could be a problem:v Djwas "essential" (the only support)for one or more u DiNeed to eliminate the one or more u Dialso.XjXiDj={…,v,…}Di={ }…,u,…vA single u Dicould only be paired with v Dj.Di={}…,XjXiDj={…,v,…}uavMultiple u Dicould only be paired with v Dj.,ub,…1)Constraint propagationApply node-consistency algorithmApply arc-consistency algorithm2)Search+ inference
Background image
Arc-Consistency Algorithm: AC-3Suppose we eliminate one value vfrom Dj.3) Or there could be an even a bigger chain reaction:v Djwas the only supportfor some u Diwe eliminate that u Dibut also u Diwas the only supportfor some t Dkwe eliminate that t DkIf any variable ends up with an empty domain, there is no solution to the CSP.XjXiDj={…,v,…}Di={…,u,…}uvXkDk={…,t,…}t1)Constraint propagationApply node-consistency algorithmApply arc-consistency algorithm2)Search+ inference
Background image
Arc-Consistency Algorithm: AC-3function AC-3(csp) returns false if an inconsistency is found, true otherwisequeue a queue of arcs, initially all the arcs in cspwhilequeue is not empty do(Xi, Xj) POP(queue)ifRevise(csp, Xi, Xj) thenif size of Di= 0 then return falsefor each Xkin Xi.NEIGHBORS{Xj} doadd (Xk, Xi) to queuereturn truefunction Revise(csp, Xi, Xj) returns true iff we revise the domain of Xirevised falsefor each uin Didoif no value vin Djallows (u,v) to satisfy the constraint between XiandXj thendelete ufrom Direvised truereturn revisedOne for each direction of the constraint (arc, edge).Remove values from Diif necessary, to make Xiarc-consistent w.r.t. Xj.Values (u) were removed from Di. Need to check all (Xk, Xi) constraints.Remove unsupported values from Di:for each uif no vsupports udelete uXkXjXiuXk1)Constraint propagationApply node-consistency algorithmApply arc-consistency algorithm2)Search+ inference
Background image
AC-3 for AustraliaDWA= {blue}DSA= {blue, yellow, pink}Suppose we popped SAWA :Not arc-consistent: u=blue has no vDWAReduce to DSA={yellow, pink} Now, must add-to-queue all "neighbors" of SA except WA:NTSAQ≠SA NSW≠SA V≠SA WASAQNSWVTNTfunction AC-3(csp) returns false if inconsistency, else truequeue a queue of arcs, initially all the arcs in cspwhilequeue is not empty do(Xi, Xj) POP(queue)ifRevise(csp, Xi, Xj) thenif size of Di= 0 then return falsefor each Xkin Xi.NEIGHBORS{Xj} doadd (Xk, Xi) to queuereturn trueRemove values from Diif necessary.XjXiXkXkXkXkAdd to queue to check.
Background image
AC-3 for AustraliaDWA= {blue}DSA= {blue, yellow, pink}We popped SAWA :What about WASA :?That would be a different element of the queue,checked some other time.WANTSAQNSWVTfunction AC-3(csp) returns false if inconsistency, else truequeue a queue of arcs, initially all the arcs in cspwhilequeue is not empty do(Xi, Xj) POP(queue)ifRevise(csp, Xi, Xj) thenif size of Di= 0 then return falsefor each Xkin Xi.NEIGHBORS{Xj} doadd (Xk, Xi) to queuereturn trueRemove values from Diif necessary.XiXjAdd to queue to check.
Background image
Efficiency of AC-3c: number of binary constraintsd: domain sizeSuppose:|domain| ≤ d (upper bound for size of domain for any given variable)c binary constraintsChecking consistency of one arc in the queue: worst case O(d2) timeFor every Xi, find some XjEach arc is put in queue only when we reduce the domain of a variable, and there are at most d values to delete per variable.Thus: Each arc (Xi, Xj) is on the queue ≤ dtimes.So one arc may require O(d3) time.There are c arcs. Thus AC-3 is worst case O(cd3) time.In practice, AC-3 is often much better. Depends on many assumptions… maybe O(cd2)?
Background image
136297854294629218XY1839584212345Z716Sudoku:No repeats of 1-9 within any row, column, or 3x3 square.Is X arc-consistent w.r.t. Y?Is Y arc-consistent w.r.t. X?Is X arc-consistent w.r.t. Z?Is Z arc-consistent w.r.t. X?Is Y arc-consistent w.r.t. Z?Is Z arc-consistent w.r.t. Y?Suppose:DX= {3, 6, 7}DY= {6, 7}DZ= {6, 7}Exercise: Arc-Consistency
Background image
YESYESYESYESYESYESSolution: Arc-Consistency136297854294629218XY1839584212345Z716Sudoku:No repeats of 1-9 within any row, column, or 3x3 square.Is X arc-consistent w.r.t. Y?Is Y arc-consistent w.r.t. X?Is X arc-consistent w.r.t. Z?Is Z arc-consistent w.r.t. X?Is Y arc-consistent w.r.t. Z?Is Z arc-consistent w.r.t. Y?Suppose:DX= {3, 6, 7}DY= {6, 7}DZ= {6, 7}
Background image
Limits of Arc-ConsistencySuppose: DWA= DNT= DSA= {pink, yellow}Is SA arc-consistentw.r.t. WA?u = pink v = yellowu = yellow v = pinkYES!Similarly for all pairs from {SA, WA, NT}.BUT: There's obviously no allowed coloring of all three involving just pink, yellow.WANTSA
Background image
Preview: Path-ConsistencyXjXmXiWANTSASuppose: DWA= DNT= DSA= {pink, yellow}Is {WA, SA} path-consistentw.r.t. NT?{WA = pink, SA = yellow} no t DNT{WA = yellow, SA = pink} no t DNTNo!Loosely: For every consistent pair of values, there's a third that supports the pair…
Background image
Preview: k-Consistency (Assuming only unary & binary constraints)A set of k-1 variables is k-consistentw.r.t. another variable ifffor all consistent assignments of the k-1 variables,there exists a consistent value for the kthvariable.A CSP is strongly k-consistentiff it is k-consistent, (k-1)-consistent, …, 1-consistent.Solving a CSP is NP-Complete!Establishing k-consistency takes exponential time and memory.w.r.t { }
Background image
How much consistency to enforce?1)Constraint PropagationEnforce k-consistency for k = 1 to ???2) Searchamong remaining values.The more we do, the more we reduce the search space! But there may be diminishing returns…Up next: How to searchfor a solution to a CSP.Such a search algorithm could be called a CSP solver.
Background image
functionBACKTRACKING-SEARCH(csp) returnsa solution or failurereturnBACKTRACK(csp,{})functionBACKTRACK(csp, assignment) returnsa solution or failureifassignmentis complete then return assignmentresultBACKTRACK(csp, assignment)ifresultfailurethen return resultreturnfailureStart with no assignmentsBase caseLoop: Try each possible value for some variable until one choice gives a complete, consistent solution.Recursive callif successful, return result of recursive callElse undo it, loop, and try something elseBacktracking Search:A depth-limited search (low mem. req.)with limit n (number of variables)except that only a single variable (all its values) are considered at a given level.
Background image
functionBACKTRACKING-SEARCH(csp) returnsa solution or failurereturnBACKTRACK(csp,{})functionBACKTRACK(csp, assignment) returnsa solution or failureifassignmentis complete then return assignmentvarSELECT-UNASSIGNED-VARIABLE(csp, assignment)for each valuein ORDER-DOMAIN-VALUES(csp, var, assignment) doif{var=value} is consistent with assignmentthenadd {var=value} to assignmentinferencesINFERENCE(csp, var, assignment)ifinferencesfailurethenadd inferencesto cspresultBACKTRACK(csp, assignment)ifresultfailurethen return resultremove inferencesfrom cspremove {var=value} from assignmentreturnfailureif consistent(no constraint violations)update assignmenttry to inferif inference doesn't find impossibility update CSP with inferencesrecurseto handle remaining variables.if recursion succeeds, we're done.undo the inferences (since failure).undo this attempted assignment.Many options…Reduce domains via k-consistencyAssign variables if only one choice leftBacktracking Search:A depth-limited search (low mem. req.)with limit n (number of variables)except that only a single variable (all its values) are considered at a given level.
Background image
functionBACKTRACKING-SEARCH(csp) returnsa solution or failurereturnBACKTRACK(csp,{})functionBACKTRACK(csp, assignment) returnsa solution or failureifassignmentis complete then return assignmentvarSELECT-UNASSIGNED-VARIABLE(csp, assignment)for each valuein ORDER-DOMAIN-VALUES(csp, var, assignment) doif{var=value} is consistent with assignmentthenadd {var=value} to assignmentinferencesINFERENCE(csp, var, assignment)ifinferencesfailurethenadd inferencesto cspresultBACKTRACK(csp, assignment)ifresultfailurethen return resultremove inferencesfrom cspremove {var=value} from assignmentreturnfailureif consistent, update assignmenttry to inferif inference doesn't find impossibilityupdate CSP with inferencesrecurse to handle remaining variables.if recursion succeeds, we're done.undo the inferences.undo this attempted assignment.Backtracking Search:A depth-limited search (low mem. req.)with limit n (number of variables)except that only a single variable (all its values) are considered at a given level.
Background image
CSP with Backtracking Search{}dnodes at this leveld* dnodes at this leveldnnodes at this levelComplete assignmentsn: # of variablesd: size of domainX1=v1X1=v3X1=v2X1=v1X2=v1X1=v1X2=v2X1=v1X2=v3SELECT-UNASSIGNED-VARIABLE: X1, X2, …ORDER-DOMAIN-VALUES: V1, V2, …Assign X1at this levelAssign X2at this level
Background image
Backtracking Illustration{}n: # of variablesd: size of domainX1=v1X1=v3X1=v2X1=v1X2=v1X1=v1X2=v2X1=v1X2=v3SELECT-UNASSIGNED-VARIABLE: X1, X2, …ORDER-DOMAIN-VALUES: V1, V2, …X1=v1X2=v1X3=v1Allowed? NOX1=v1X2=v1X3=v2NOX1=v1X2=v1X3=vlastNOSuppose there are only n=3 variables.(suppose)
Background image
Backtracking Illustration{}n: # of variablesd: size of domainX1=v1X1=v3X1=v2X1=v1X2=v1X1=v1X2=v3SELECT-UNASSIGNED-VARIABLE: X1, X2, …ORDER-DOMAIN-VALUES: V1, V2, …NOX1=v1X2=v2Suppose there are only n=3 variables.
Background image
Backtracking Illustration{}n: # of variablesd: size of domainX1=v1X1=v3X1=v2X1=v1X2=v1X1=v1X2=v2X1=v1X2=v3SELECT-UNASSIGNED-VARIABLE: X1, X2, …ORDER-DOMAIN-VALUES: V1, V2, …X1=v1X2=v2X3=v1NOSuppose there are only n=3 variables.
Background image
Backtracking Illustration{}n: # of variablesd: size of domainX1=v1X1=v3X1=v2X1=v1X2=v1X1=v1X2=v2X1=v1X2=v3SELECT-UNASSIGNED-VARIABLE: X1, X2, …ORDER-DOMAIN-VALUES: V1, V2, …NONONONOSuppose there are only n=3 variables.
Background image
Backtracking Illustration{}n: # of variablesd: size of domainX1=v1X1=v3X1=v2SELECT-UNASSIGNED-VARIABLE: X1, X2, …ORDER-DOMAIN-VALUES: V1, V2, …NOSuppose there are only n=3 variables.
Background image
functionBACKTRACKING-SEARCH(csp) returnsa solution or failurereturnBACKTRACK(csp,{})functionBACKTRACK(csp, assignment) returnsa solution or failureifassignmentis complete then return assignmentvarSELECT-UNASSIGNED-VARIABLE(csp, assignment)for each valuein ORDER-DOMAIN-VALUES(csp, var, assignment) doif{var=value} is consistent with assignmentthenadd {var=value} to assignmentinferencesINFERENCE(csp, var, assignment)ifinferencesfailurethenadd inferencesto cspresultBACKTRACK(csp, assignment)ifresultfailurethen return resultremove inferencesfrom cspremove {var=value} from assignmentreturnfailureDecisions to make:Variable orderingValue ordering for a given variableWhat inference to do
Background image
Picking Which Variable to Expand NextDecisions to make:Variable orderingValue ordering for a given variableWhat inference to doSELECT-UNASSIGNED-VARIABLEWANTNSWVTSAQ{b,p,y}{b,p,y}{b,p,y}{p,b}{b}Pick SA!Picking next variable arbitrarily is often inefficient.A "good" choice can improve efficiency.Minimum Remaining Value (MRV) heuristicChoose variable with fewest legal values remainingaka "most constrained variable" or "fail-first"Every variable must be assigned, so try the hardest variable first, so if we fail we can backtrack ASAP.If any variable has no legal values, MRV will choose that and detect failure immediately
Background image
Picking Which Variable to Expand NextDegree heuristicReduce branching factor by selecting variable involved in largest number of constraints with other unassigned variablesDecisions to make:Variable orderingValue ordering for a given variableWhat inference to doSELECT-UNASSIGNED-VARIABLEWANTQNSWVTPick SAor NSW!(Constraints with three other unassigned variables.)SA
Background image
Picking Which Value to Try NextLeast-constraining-valueThe one that leaves the most options remaining for neighboring variables.We only need one solution might as well try the easiest values first.Decisions to make:Variable orderingValue ordering for a given variableWhat inference to doORDER-DOMAIN-VALUESWANTNSWVTSAQSuppose we picked Q next.Which value to try first?Q = yellowdoesn't work (conflict with NT).Q = bluewould be bad, since no remaining values for SA.Q = pinkis the least-constraining value.Enforce A.C. with neighbors and see what values remain.
Background image
Suppose we assignX = v. So:becomes:We can make Y arc-consistent w.r.t. X by reducing DYas needed.Do this for every unassigned variable Yconnected to X in the constraint graph.One Type of Inference:Forward Checking (FC)Decisions to make:Variable orderingValue ordering for a given variableWhat inference to doSuppose before our search began, we've already established arc consistency across the CSP.Is there any purpose to doing forward checking too?Yes! The assignment X = v means we may have more domains that can be reduced.XYX=vDY={…,u,…}uvXYDX={…,v,…}DY={…,u,…}uvFC as defined here does not propagate. That is, no "next, look at each Y's constraints with other nodes, and then their constraints, …".
Background image
4-Queens Example; Backtracking + FC4x4 grid; one queen in each columnVariables: q1, q2, q3, q4Domain: r1,r2,r3,r4q1q2q3q4initialr1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4
Background image
4-Queens Example; Backtracking + FC4x4 grid; one queen in each columnVariables: q1, q2, q3, q4Domain: r1,r2,r3,r4q1q2q3q4initialr1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4q1=r1; FC(r1)r3,r4r2,r4r2,r3
Background image
4-Queens Example; Backtracking + FC4x4 grid; one queen in each columnVariables: q1, q2, q3, q4Domain: r1,r2,r3,r4q1q2q3q4initialr1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4q1=r1; FC(r1)r3,r4r2,r4r2,r3q2=r3; FC(r1)(r3)r2
Background image
4-Queens Example; Backtracking + FC4x4 grid; one queen in each columnVariables: q1, q2, q3, q4Domain: r1,r2,r3,r4q1q2q3q4initialr1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4q1=r1; FC(r1)r3,r4r2,r4r2,r3q2=r3; FC, Empty q3(r1)(r3)r2q2=r4; FC(r1)(r4)r2r3
Background image
4-Queens Example; Backtracking + FC4x4 grid; one queen in each columnVariables: q1, q2, q3, q4Domain: r1,r2,r3,r4q1q2q3q4initialr1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4q1=r1; FC(r1)r3,r4r2,r4r2,r3q2=r3; FC, Empty q3(r1)(r3)r2q2=r4; FC(r1)(r4)r2r3q3=r2; FC (r1)(r4)(r2)
Background image
4-Queens Example; Backtracking + FC4x4 grid; one queen in each columnVariables: q1, q2, q3, q4Domain: r1,r2,r3,r4q1q2q3q4initialr1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4q1=r1; FC(r1)r3,r4r2,r4r2,r3q2=r3; FC, Empty q3(r1)(r3)r2q2=r4; FC(r1)(r4)r2r3q3=r2; FC (r1)(r4)(r2)
Background image
4-Queens Example; Backtracking + FC4x4 grid; one queen in each columnVariables: q1, q2, q3, q4Domain: r1,r2,r3,r4q1q2q3q4initialr1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4q1=r1; FC(r1)r3,r4r2,r4r2,r3q2=r3; FC, Empty q3(r1)(r3)r2q2=r4; FC(r1)(r4)r2r3q3=r2; FC (r1)(r4)(r2)
Background image
4-Queens Example; Backtracking + FC4x4 grid; one queen in each columnVariables: q1, q2, q3, q4Domain: r1,r2,r3,r4q1q2q3q4initialr1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4q1=r1; FC(r1)r3,r4r2,r4r2,r3q2=r3; FC, Empty q3(r1)(r3)r2q2=r4; FC(r1)(r4)r2r3q3=r2; FC, Empty q4(r1)(r4)(r2)
Background image
4-Queens Example; Backtracking + FC4x4 grid; one queen in each columnVariables: q1, q2, q3, q4Domain: r1,r2,r3,r4q1q2q3q4initialr1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4q1=r1; FC(r1)r3,r4r2,r4r2,r3q2=r3; FC, Empty q3(r1)(r3)r2q2=r4; FC(r1)(r4)r2r3q3=r2; FC, Empty q4(r1)(r4)(r2)q1=r2; FC(r2)r4r1, r3r1,r3,r4
Background image
4-Queens Example; Backtracking + FC4x4 grid; one queen in each columnVariables: q1, q2, q3, q4Domain: r1,r2,r3,r4q1q2q3q4initialr1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4q1=r1; FC(r1)r3,r4r2,r4r2,r3q2=r3; FC, Empty q3(r1)(r3)r2q2=r4; FC(r1)(r4)r2r3q3=r2; FC, Empty q4(r1)(r4)(r2)q1=r2; FC(r2)r4r1, r3r1,r3,r4q2=r4;FC(r2)(r4)r1r1,r3
Background image
4-Queens Example; Backtracking + FC4x4 grid; one queen in each columnVariables: q1, q2, q3, q4Domain: r1,r2,r3,r4q1q2q3q4initialr1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4q1=r1; FC(r1)r3,r4r2,r4r2,r3q2=r3; FC, Empty q3(r1)(r3)r2q2=r4; FC(r1)(r4)r2r3q3=r2; FC, Empty q4(r1)(r4)(r2)q1=r2; FC(r2)r4r1, r3r1,r3,r4q2=r4;FC(r2)(r4)r1r1,r3q3=r1; FC(r2)(r4)(r1)r3
Background image
4-Queens Example; Backtracking + FC4x4 grid; one queen in each columnVariables: q1, q2, q3, q4Domain: r1,r2,r3,r4q1q2q3q4initialr1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4r1,r2,r3,r4q1=r1; FC(r1)r3,r4r2,r4r2,r3q2=r3; FC, Empty q3(r1)(r3)r2q2=r4; FC(r1)(r4)r2r3q3=r2; FC, Empty q4(r1)(r4)(r2)q1=r2; FC(r2)r4r1, r3r1,r3,r4q2=r4;FC(r2)(r4)r1r1,r3q3=r1; FC(r2)(r4)(r1)r3q4=r3(r2)(r4)(r1)(r3)
Background image
FC as defined here does not propagate. That is, no "next, look at each Y's constraints with other nodes, and then their constraints, …".
Background image
Suppose we assign X = v. So:becomes:We can make Y arc-consistent w.r.t. X by reducing DYas needed.Do this for every unassigned variable Y(connected to X in the constraint graph)Forward Checking: LimitationDecisions to make:Variable orderingValue ordering for a given variableWhat inference to doWe may reduce domains for many variables (each Y)!But FC doesn't then check:If we did reduce Z, that may require even more reductions! XYX=vDY={…,u,…}uvZDZ={…,t,…}tFC
Background image
Suppose we assign X = v. So:becomes:We can make Y arc-consistent w.r.t. X by reducing DYas needed.In INFERENCE, apply AC-3, but initialize queue with arcs containing X and adjacent Y's (not all arcs).What's the differencebetween MAC and forward checking?Constraint propagation: In MAC, if DYis reduced, add its arcs to the queue as well, to check them too, and possibly apply more reductions, which lead to more… (AC-3).Maintaining Arc Consistency (MAC)(It's like Forward Checking that propagates.)Decisions to make:Variable orderingValue ordering for a given variableWhat inference to doXYX=vDY={…,u,…}uvZDZ={…,t,…}t
Background image
Up Next…Propositional Logic!
Background image