1 / 77

Finite Constraint Domains

Finite Constraint Domains. Finite Constraint Domains. Constraint satisfaction problems (CSP) A backtracking solver Node and arc consistency Bounds consistency Generalized consistency Optimization for arithmetic CSPs. Finite Constraint Domains. An important class of constraint domains

manning
Download Presentation

Finite Constraint Domains

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Finite Constraint Domains

  2. Finite Constraint Domains • Constraint satisfaction problems (CSP) • A backtracking solver • Node and arc consistency • Bounds consistency • Generalized consistency • Optimization for arithmetic CSPs

  3. Finite Constraint Domains • An important class of constraint domains • Use to model constraint problems involving choice: e.G. Scheduling, routing and timetabling • The greatest industrial impact of constraint programming has been on these problems

  4. Constraint Satisfaction Problems • A constraint satisfaction problem (CSP) consists of: • A constraint C over variables x1,..., Xn • A domain D which maps each variable xi to a set of possible values d(xi) • It is understood as the constraint

  5. Map Colouring A classic CSP is the problem of coloring a map so that no adjacent regions have the same color Can the map of Australia be colored with 3 colors ?

  6. Q1 Q2 Q3 Q4 1 2 3 4 4-queens Place 4 queens on a 4 x 4 chessboard so that none can take another. Four variables Q1, Q2, Q3, Q4 representing the row of the queen in each column. Domain of each variable is {1,2,3,4} One solution! -->

  7. 4-queens The constraints: Not on the same row Not diagonally up Not diagonally down

  8. Smugglers Knapsack Smuggler with knapsack with capacity 9, who needs to choose items to smuggle to make profit at least 30 What should be the domains of the variables?

  9. Systematic Search Methods • exploring the solution space • complete and sound • efficiency issues • Backtracking (BT) • Generate & Test (GT) exploring subspace exploringindividual assignments Z Y X

  10. Generate & Test • probably the most general problem solving method • Algorithm: generate labelling test satisfaction Drawbacks: Improvements: blind generator smart generator --> local search late discovery of testing within generator inconsistencies --> backtracking

  11. Backtracking (BT) • incrementally extends a partial solution towards a complete solution • Algorithm: assign value to variable check consistency until all variables labelled • Drawbacks: • thrashing • redundant work • late detection of conflict A 1 B 2 1 C 2 1 1 D 2 2 1 1 1  A = D, B  D, A+C < 4

  12. GT & BT - Example • Problem:X::{1,2}, Y::{1,2}, Z::{1,2}X = Y, X  Z, Y > Z generate & test backtracking

  13. Simple Backtracking Solver • The simplest way to solve CSPs is to enumerate the possible solutions • The backtracking solver: • Enumerates values for one variable at a time • Checks that no prim. Constraint is false at each stage • Assume satisfiable(c) returns false when primitive constraint c with no variables is unsatisfiable

  14. Partial Satisfiable • Check whether a constraint is unsatisfiable because of a prim. Constraint with no vars • Partial_satisfiable(c) • For each primitive constraint c in C • If vars(c) is empty • Ifsatisfiable(c) = falsereturnfalse • Returntrue

  15. Backtrack Solve • Back_solve(c,d) • Ifvars(c) is empty returnpartial_satisfiable(c) • Choose x in vars(c) • For each value d in d(x) • Let C1 be C with x replaced by d • Ifpartial_satisfiable(c1) then • Ifback_solve(c1,d) then returntrue • Returnfalse

  16. Backtracking Solve Choose var X domain {1,2} Choose var Y domain {1,2} Choose var Z domain {1,2} Variable X domain {1,2} Choose var Y domain {1,2} No variables, and false partial_satisfiablefalse No variables, and false

  17. Consistency Techniques • removing inconsistent values from variables’ domains • graph representation of the CSP • binary and unary constraints only (no problem!) • nodes = variables • edges = constraints • node consistency (NC) • arc consistency (AC) • path consistency (PC) • (strong) k-consistency A>5 A A<C AB C B B=C

  18. Node and Arc Consistency • Basic idea: find an equivalent CSP to the original one with smaller domains of vars • Key: examine 1 prim.Constraint c at a time • Node consistency: (vars(c)={x}) remove any values from domain of x that falsify c • Arc consistency: (vars(c)={x,y}) remove any values from d(x) for which there is no value in d(y) that satisfies c and vice versa

  19. Node Consistency • Primitive constraint c is node consistent with domain D if |vars(c)| /=1 or • If vars(c) = {x} then for each d in d(x) • X assigned d is a solution of c • A CSP is node consistent if each prim. Constraint in it is node consistent

  20. Node Consistency Examples Example CSP is not node consistent (see Z) This CSP is node consistent The map coloring and 4-queens CSPs are node consistent. Why?

  21. Achieving Node Consistency • Node_consistent(c,d) • For each prim. Constraint c in C • D := node_consistent_primitive(c, D) • ReturnD • Node_consistent_primitive(c, D) • If|vars(c)| =1then • Let {x} = vars(c) • ReturnD

  22. Arc Consistency • A primitive constraint c is arc consistent with domain D if |vars{c}| != 2 or • Vars(c) = {x,y} and for each d in d(x) there exists e in d(y) such that • And similarly for y • A CSP is arc consistent if each prim. Constraint in it is arc consistent

  23. Arc Consistency Examples This CSP is node consistent but not arc consistent For example the value 4 for X and X < Y. The following equivalent CSP is arc consistent The map coloring and 4-queens CSPs are also arc consistent.

  24. Achieving Arc Consistency • Arc_consistent_primitive(c, D) • If|vars(c)| = 2then • ReturnD • Removes values which are not arc consistent with c

  25. Achieving Arc Consistency • Arc_consistent(c,d) • Repeat • W := d • For each prim. Constraint c in C • D := arc_consistent_primitive(c,d) • UntilW = D • ReturnD • A very naive version (there are much better)

  26. Using Node and Arc Cons. • We can build constraint solvers using the consistency methods • Two important kinds of domain • False domain: some variable has empty domain • Valuation domain: each variable has a singleton domain • Extend satisfiable to CSP with val. Domain

  27. Node and Arc Cons. Solver • D := node_consistent(C,D) • D := arc_consistent(C,D) • ifD is a false domain • returnfalse • ifD is a valuation domain • returnsatisfiable(C,D) • returnunknown

  28. WA NT SA Q NSW V T Node and Arc Solver Example Colouring Australia: with constraints Node consistency

  29. WA NT SA Q NSW V T Node and Arc Solver Example Colouring Australia: with constraints Arc consistency

  30. WA NT SA Q NSW V T Node and Arc Solver Example Colouring Australia: with constraints Arc consistency

  31. WA NT SA Q NSW V T Node and Arc Solver Example Colouring Australia: with constraints Arc consistency Answer: unknown

  32. Backtracking Cons. Solver • We can combine consistency with the backtracking solver • Apply node and arc consistency before starting the backtracking solver and after each variable is given a value

  33. Back. Cons Solver Example Q1 Q2 Q3 Q4 1 Therefore, we need to choose another value for Q2. No value can be assigned to Q3 in this case! There is no possible value for variable Q3! 2 3 4

  34. Back. Cons Solver Example Q1 Q2 Q3 Q4 1 Backtracking… Find another value for Q3? No! backtracking, Find another value of Q2? No! backtracking, Find another value of Q1? Yes, Q1 = 2 We cannot find any possible value for Q4 in this case! 2 3 4

  35. Back. Cons Solver Example Q1 Q2 Q3 Q4 1 2 3 4

  36. Back. Cons Solver Example Q1 Q2 Q3 Q4 1 2 3 4

  37. WA NT SA Q NSW V T Node and Arc Solver Example Colouring Australia: with constraints Backtracking enumeration Select a variable with domain of more than 1, T Add constraint Apply consistency Answer: true

  38. Is AC enough? • empty domain => no solution • cardinality of all domains is 1 => solution • Problem:X::{1,2}, Y::{1,2}, Z::{1,2}X  Y, X  Z, Y  Z X 1 2 1 2 Y Z 1 2

  39. Path Consistency (PC) V2 V4 V3 V5 • Path (V0 … Vn) is path consistent iff for each pair of compatible values x in D(V0) and y in D(Vn) there exists an instantiation of the variables V1 ..Vn-1 such that all the constraint (Vi,Vi+1) are satisfied • CSP is path consistent iff each path is path consistent • consistency along the path only V0 V1 ???

  40. Path Consistency (PC) V2 V4 V3 V5 • checking paths of length 2 is enough • Plus/Minus + detects more inconsistencies than AC - extensional representation of constraints (01 matrix), huge memory consumption - changes in graph connectivity V0 V1 ???

  41. K -consistency • K-consistency • consistent valuation o (K-1) variables can be extended to K-th variable • strong K-consistency J-consistency for each JK

  42. Is k-consistency enough ? • If all the domains have cardinality 1=> solution • If any domain is empty => no solution • Otherwise ? • strongly k-consistent constraint graph with k nodes => completeness • for some special kind of graphs weaker forms of consistency are enough

  43. Consistency Completeness • strongly N-consistent constraint graph with N nodes => solution • strongly K-consistent constraint graph with N nodes (K<N) => ???path consistent but no solution • Special graph structures • tree structured graph => (D)AC is enough  A D {1,2,3} {1,2,3}     C B  {1,2,3} {1,2,3}

  44. hyper-arc consistency • A primitive constraint c is hyper-arc consistent with domain D if • for each variable x in c and for each d in d(x) the valuation x-->d can be extended to a solution of c • A CSP is hyper-arc consistent if each prim. Constraint in it is hyper-arc consistent • NC  hyper-arc consistency for constraint with 1 var • AC  hyper-arc consistency for constraint with 2 var

  45. Non binary constraints • What about prim. constraints with more than 2 variables? • Each CSP can be transformed into an equivalent binary CSP (dual encoding) • k-consitncy • hyper-arc consistency

  46. Dual encoding • Each CSP can be transformed into an equivalent binary CSP by ``dual encoding’’: • k-ary constraint c is converted to a dual variable vc with the domain consisting of compatible tuples • for each pair of constraint c,c’ sharing some variable there is a binary constraint between vc and vc’ restricting the dual variables to tuples in which the original shared variables take the same value

  47. Hyper-arc consistency • hyper-arc consistency: extending arc consistency to arbitrary number of variables • (better than binary representation) • Unfortunately determining hyper-arc consistency is NP-hard (as expensive as determinining if a CSP is satisfiable). • Solution?

  48. Bounds Consistency • arithmetic CSP: domains = integers • range: [l..u] represents the set of integers {l, l+1, ..., u} • idea use real number consistency and only examine the endpoints (upper and lower bounds) of the domain of each variable • Define min(D,x) as minimum element in domain of x, similarly for max(D,x)

  49. Bounds Consistency • A prim. constraint c is bounds consistent with domain D if for each var x in vars(c) • exist real numbers d1, ..., dk for remaining vars x1, ..., xk such that min(D,xj),= dj<= max(D,xj) and is a solution of c • and similarly for • An arithmetic CSP is bounds consistent if all its primitive constraints are

  50. Bounds Consistency Examples Not bounds consistent, consider Z=2, then X-3Y=10 But the domain below is bounds consistent Compare with the hyper-arc consistent domain

More Related