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
Midterm Exam: 10/8, 7 –8:20 PM•Tentative / in the works:•Room assignments•SSD details for those that have already heard from me•Practice exam will be released soon (without solutions). Try it like a real test!•Special review session tentatively on 10/5, 1-3PM, room TBA•Practice exam solutions:•Discussed in review session•Released after review session•Allowed: 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).
Constraint Satisfaction Problems•A 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
Constraint Satisfaction Problems•A 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 search•Usually includes inference to eliminate more disallowed values
Solving CSPs•Assignment–specifies values for variables•Partial assignment–for some variables•Complete assignment–for all variables•Consistent assignment–violates no constraints•aka legal assignment•May be partial or complete•Solution: A complete and consistent assignment•Benefit: break the CSP into sub-problems•If partial assignment isn't consistent, any corresponding full assignment won't be either
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:•X–a set of variables {X1, …, Xn}•We want to know these values•D–set of domains {D1, …, Dn} –each is a set of allowed values for a variable•Domain Di –set {v1, …, vk} of allowable values for variable Xi•C–set of constraints (allowable combinations of variables)•Constraint: <scope, rel>•scope–tuple of variables that participate in the constraint•rel–relation that defines values variables can take•Constraints let us eliminate disallowed combinations, to reduce the search space.1)Constraint propagationto eliminate disallowed values.2)Searchamong remaining values, + inference.
Example: Map Coloring•Goal –color in each region: (pink, yellow, blue)•Constraint: no neighbors have same color•Define CSP:•Variables: X = {WA, NT, Q, NSW, V, SA, T}•Domains: ∀iDi= {pink, yellow, blue}•Constraints: C= {SA≠ WA, SA ≠ NT, SA≠ Q, …}Shorthand: SA≠ WAis <(SA, WA), {(pink, yellow),(pink, blue),(yellow, pink), (yellow, blue),(blue, pink),(blue, yellow)}>Constraint GraphEdge means constraintX1 X2X3X4X5 X6 X7
Constraint GraphWANTSAQNSWVTSA•How many complete (and not necessarily consistent)assignments are there?7 variables, 3 choices per variable37= 2187•T has no constraints, so it can be anything! Let's say blue.Remaining assignments to consider:36= 729•Let's just pick SA to be blue.Remaining assignments to consider:35= 243•So 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.
Local Consistency: Inference•Eliminatecertain disallowed combinations.•One elimination →another →another.This is called constraint propagation.•Consider constraints through generally-applicable requirements:•Node-consistency•Arc-consistency•Path-consistency•K-consistency1)Constraint propagationto eliminate disallowed values.2)Searchamong remaining values, + inference.
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 variable•Xiis 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).
Node-Consistency Algorithm•For each unary constraint•Eliminate 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 propagation•Apply node-consistency algorithm•…2)Search+ inference.
Arc-Consistency•Binary constraint: scope contains exactly two variables•Xiis 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.
X1with D1= {2,3}X2with D2= {1,4}X1< X2:<(X1, X2), {(2,4), (3,4)}>Is X1arc-consistent w.r.t. X2? X1< X2∀u ∈D1∃v ∈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< X2∀u ∈D2∃v ∈D1:•X2=1: noX1is allowedX•X2=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)
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!
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 ∈DX∃v ∈DY: X=u and Y=v is allowed
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!
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 ∈DY∃v ∈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}
Arc-Consistency Algorithm: AC-3Suppose we eliminate one value vfrom Dj.1) Best case:v ∈Djwasn't "essential" (the only support)for any u ∈Di→Nothing 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={ }…v……No u ∈Dicould be paired with v ∈Djanyway.XjXiDj={…,v,…}Di={ }…,u,…v……Any u ∈Dithat could be paired with v ∈Djcould also be paired with some other value in Dj.1)Constraint propagation•Apply node-consistency algorithm•Apply arc-consistency algorithm•…2)Search+ inference
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 ∈Di→Need to eliminate the one or more u ∈Dialso.XjXiDj={…,v,…}Di={ }…,u,…v……A single u ∈Dicould only be paired with v ∈Dj.Di={}…,XjXiDj={…,v,…}uav……Multiple u ∈Dicould only be paired with v ∈Dj.,ub,…1)Constraint propagation•Apply node-consistency algorithm•Apply arc-consistency algorithm•…2)Search+ inference
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 ∈Di→we eliminate that u ∈Dibut also u ∈Diwas the only supportfor some t ∈Dk→we eliminate that t ∈Dk…If any variable ends up with an empty domain, there is no solution to the CSP.XjXiDj={…,v,…}Di={…,u,…}uvXkDk={…,t,…}t1)Constraint propagation•Apply node-consistency algorithm•Apply arc-consistency algorithm•…2)Search+ inference
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 uXkXjXiuXk…1)Constraint propagation•Apply node-consistency algorithm•Apply arc-consistency algorithm•…2)Search+ inference
AC-3 for Australia•DWA= {blue}•DSA= {blue, yellow, pink}•Suppose we popped SA≠WA :•Not arc-consistent: u=blue has no v∈DWA→Reduce to DSA={yellow, pink} •Now, must add-to-queue all "neighbors" of SA except WA:NT≠SAQ≠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.
AC-3 for Australia•DWA= {blue}•DSA= {blue, yellow, pink}•We popped SA≠WA :•What about WA≠SA :?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.
Efficiency of AC-3c: number of binary constraintsd: domain size•Suppose:•|domain| ≤ d (upper bound for size of domain for any given variable)•c binary constraints•Checking consistency of one arc in the queue: worst case O(d2) time•For every Xi, find some Xj•Each 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)?
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
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}
Limits of Arc-Consistency•Suppose: DWA= DNT= DSA= {pink, yellow}•Is SA arc-consistentw.r.t. WA?•u = pink →v = yellow•u = yellow →v = pink•YES!•Similarly for all pairs from {SA, WA, NT}.•BUT: There's obviously no allowed coloring of all three involving just pink, yellow.WANTSA
Preview: Path-ConsistencyXjXmXiWANTSA•Suppose: 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 ∈DNT•No!Loosely: For every consistent pair of values, there's a third that supports the pair…
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 { }
How much consistency to enforce?1)Constraint Propagation•Enforce 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.
functionBACKTRACKING-SEARCH(csp) returnsa solution or failurereturnBACKTRACK(csp,{})functionBACKTRACK(csp, assignment) returnsa solution or failureifassignmentis complete then return assignmentresultBACKTRACK(csp, assignment)ifresult≠ failurethen 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.
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)ifinferences≠ failurethenadd inferencesto cspresultBACKTRACK(csp, assignment)ifresult≠ failurethen 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-consistency•Assign variables if only one choice left•…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.
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)ifinferences≠ failurethenadd inferencesto cspresultBACKTRACK(csp, assignment)ifresult≠ failurethen 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.
CSP with Backtracking Search{}dnodes at this leveld* dnodes at this leveldnnodes at this levelComplete assignmentsn: # of variablesd: size of domainX1=v1X1=v3X1=v2…………………X1=v1X2=v1X1=v1X2=v2X1=v1X2=v3…SELECT-UNASSIGNED-VARIABLE: X1, X2, …ORDER-DOMAIN-VALUES: V1, V2, …Assign X1at this levelAssign X2at this level
Backtracking Illustration{}n: # of variablesd: size of domainX1=v1X1=v3X1=v2…X1=v1X2=v1X1=v1X2=v2X1=v1X2=v3…SELECT-UNASSIGNED-VARIABLE: X1, X2, …ORDER-DOMAIN-VALUES: V1, V2, …X1=v1X2=v1X3=v1Allowed? NOX1=v1X2=v1X3=v2NOX1=v1X2=v1X3=vlastNO…Suppose there are only n=3 variables.(suppose)
Backtracking Illustration{}n: # of variablesd: size of domainX1=v1X1=v3X1=v2…X1=v1X2=v1X1=v1X2=v3…SELECT-UNASSIGNED-VARIABLE: X1, X2, …ORDER-DOMAIN-VALUES: V1, V2, …NOX1=v1X2=v2Suppose there are only n=3 variables.
Backtracking Illustration{}n: # of variablesd: size of domainX1=v1X1=v3X1=v2…X1=v1X2=v1X1=v1X2=v2X1=v1X2=v3…SELECT-UNASSIGNED-VARIABLE: X1, X2, …ORDER-DOMAIN-VALUES: V1, V2, …X1=v1X2=v2X3=v1NO…Suppose there are only n=3 variables.
Backtracking Illustration{}n: # of variablesd: size of domainX1=v1X1=v3X1=v2…X1=v1X2=v1X1=v1X2=v2X1=v1X2=v3…SELECT-UNASSIGNED-VARIABLE: X1, X2, …ORDER-DOMAIN-VALUES: V1, V2, …NONONONOSuppose there are only n=3 variables.
Backtracking Illustration{}n: # of variablesd: size of domainX1=v1X1=v3X1=v2…SELECT-UNASSIGNED-VARIABLE: X1, X2, …ORDER-DOMAIN-VALUES: V1, V2, …NO…Suppose there are only n=3 variables.
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)ifinferences≠ failurethenadd inferencesto cspresultBACKTRACK(csp, assignment)ifresult≠ failurethen return resultremove inferencesfrom cspremove {var=value} from assignmentreturnfailureDecisions to make:•Variable ordering•Value ordering for a given variable•What inference to do
Picking Which Variable to Expand NextDecisions to make:•Variable ordering•Value ordering for a given variable•What 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) heuristic•Choose variable with fewest legal values remaining•aka "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
Picking Which Variable to Expand Next•Degree heuristic•Reduce branching factor by selecting variable involved in largest number of constraints with other unassigned variablesDecisions to make:•Variable ordering•Value ordering for a given variable•What inference to doSELECT-UNASSIGNED-VARIABLEWANTQNSWVTPick SAor NSW!(Constraints with three other unassigned variables.)SA
Picking Which Value to Try Next•Least-constraining-value•The 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 ordering•Value ordering for a given variable•What 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.
•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 ordering•Value ordering for a given variable•What 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, …".
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
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
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
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
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)
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)
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)
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)
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
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
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
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)
FC as defined here does not propagate. That is, no "next, look at each Y's constraints with other nodes, and then their constraints, …".
•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 ordering•Value ordering for a given variable•What inference to do•We 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,…}t…FC
•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 ordering•Value ordering for a given variable•What inference to doXYX=vDY={…,u,…}uvZDZ={…,t,…}t…