Presentation is loading. Please wait.

Presentation is loading. Please wait.

Constraints and Search

Similar presentations


Presentation on theme: "Constraints and Search"— Presentation transcript:

1 Constraints and Search
Logic & AR Summer School, 2002 Constraints and Search Toby Walsh Cork Constraint Computation Centre (4C)

2 Constraint satisfaction
Constraint satisfaction problem (CSP) is a triple <V,D,C> where: V is set of variables Each X in V has set of values, D_X Usually assume finite domain {true,false}, {red,blue,green}, [0,10], … C is set of constraints Goal: find assignment of values to variables to satisfy all the constraints

3 Constraint solver Tree search Number of choices
Assign value to variable Deduce values that must be removed from future/unassigned variables Constraint propagation If any future variable has no values, backtrack else repeat Number of choices Variable to assign next, value to assign Some important refinements like nogood learning, non-chronological backtracking, …

4 Constraint propagation
Enfrocing arc-consistency (AC) A binary constraint r(X1,X2) is AC iff for every value for X1, there is a consistent value (often called support) for X2 and vice versa E.g. With 0/1 domains and the constraint X1 =/= X2 Value 0 for X1 is supported by value 1 for X2 Value 1 for X1 is supported by value 0 for X2 A problem is AC iff every constraint is AC

5 Tree search Backtracking (BT) Forward checking (FC)
Maintaining arc-consistency (MAC) Limited discrepany search (LDS) Non-chronological backtracking & learning

6 Example: n-queens Place n-queens on an n  n board so that no pair of queens attacks each other

7 Example: 4-queens Variables: x1, x2 , x3 , x4 Domains: {1, 2, 3, 4}
Constraints: xi  xj and | xi - xj |  | i - j | x1 x2 x3 x4 1 2 3 4

8 Example: 4-queens One solution: x1  2 x2  4 x3  1 x4  3 x1 x2 x3

9 BT on 4-queens x1 x2 x3 x4 Try: x1  1 1 Q 2 3 4

10 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  1 1 Q Q 2 3 4

11 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  1 Backtrack 1 Q Q 2 3 4

12 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  2 1 Q 2 Q 3 4

13 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  2 Backtrack 1 Q 2 Q 3 4

14 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 1 Q 2 3 Q 4

15 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  1 1 Q Q 2 3 Q 4

16 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  1 Backtrack 1 2 3 4

17 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  2 1 Q 2 Q 3 Q 4

18 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  2 Backtrack 1 2 3 4

19 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  3 1 Q 2 3 Q Q 4

20 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  3 Backtrack 1 2 3 4

21 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  4 1 Q 2 3 Q 4 Q

22 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  4 Backtrack 1 2 3 4

23 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 1 Q 2 3 4 Q

24 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 x3  1 1 Q Q 2 3 4 Q

25 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 x3  1 Backtrack 1 2 3 4

26 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 x3  2 1 Q 2 Q 3 4 Q

27 BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 x3  2 And so on! 1 2 3

28 BT search tree for 4-queens
x1 1 2 3 4 x2 x3 x4 (2,4,1,3) (3,1,4,2)

29 Forward checking (FC) Maintains limited form of arc-consistency
Makes constraints involving current var and any future var arc-consistent Only looks at each constraint once! No need to re-visit constraints to ensure support remains when a domain value is pruned Very cheap, little extra cost over BT

30 FC on 4-queens x1 x2 x3 x4 Try: x1  1 1 Q 2 3 4

31 FC on 4-queens x1 x2 x3 x4 Try: x1  1 Forward check 1 2 3 4 Q X X X X

32 FC on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 1 Q X X X 2 X 3 Q X 4 X

33 FC on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 Forward check 1 2 3 4 Q

34 FC on 4-queens Try: x1  1 x2  3 Domian wipeout for x3 x1 x2 x3 x4 1

35 FC on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 Backtrack 1 2 3 4 Q X X

36 FC on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 Backtrack 1 2 3 4 Q X X

37 FC on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 1 Q X X X 2 X 3 X 4 Q X

38 FC on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 Forward check 1 2 3 4 Q

39 FC on 4-queens Try: x1  1 x2  4 x3  2 x1 x2 x3 x4 1 2 3 4 Q X X X X

40 FC on 4-queens Try: x1  1 x2  4 x3  2 Forward check x1 x2 x3 x4 1 2

41 FC on 4-queens Try: x1  1 x2  4 x3  2 Domain wipeout for x4 x1 x2

42 FC on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 Backtrack 1 2 3 4 Q X X

43 FC on 4-queens x1 x2 x3 x4 Try: x1  1 Backtrack 1 Q X X X 2 X 3 X 4 X

44 FC on 4-queens x1 x2 x3 x4 Try: x1  2 1 2 Q 3 4

45 FC on 4-queens x1 x2 x3 x4 Try: x1  2 Forward check 1 2 3 4 X Q X X X

46 FC on 4-queens x1 x2 x3 x4 Try: x1  2 x2  4 1 X 2 Q X X X 3 X 4 Q X

47 FC on 4-queens x1 x2 x3 x4 Try: x1  2 x2  4 Forward check 1 2 3 4 X

48 FC on 4-queens x1 x2 x3 x4 Try: x1  2 x2  4 x3  1 1 2 3 4 X Q Q X X

49 FC on 4-queens x1 x2 x3 x4 Try: x1  2 x2  4 x3  1 Forward check 1 2

50 FC on 4-queens x1 x2 x3 x4 Try: x1  2 x2  4 x3  1 x4  3 1 2 3 4 X

51 FC on 4-queens x1 x2 x3 x4 Try: x1  2 x2  4 x3  1 x4  3 1 2 3 4 Q

52 Maintaining arc-consistency (MAC)
Enforces arc-consistency at each node in the search tree Much more expensive than FC But can save exploring many fruitless subtrees

53 MAC on 4-queens x1 x2 x3 x4 Try: x1  1 1 Q 2 3 4

54 MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC 1 Q 2 3 4

55 MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC 1 2 3 4 Q X X X X X

56 MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC 1 2 3 4 Q X X X X X

57 MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC 1 2 3 4 Q X X X X X

58 MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC 1 2 3 4 Q X X X X X

59 MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC
Domain wipeout for x3 1 Q X X X 2 X X 3 X X 4 X X

60 MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC Backtrack 1 2 3 4 Q

61 MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC Backtrack 1 Q 2 3 4

62 MAC on 4-queens x1 x2 x3 x4 Try: x1  2 1 2 Q 3 4

63 MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Enforce AC 1 2 Q 3 4

64 MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Enforce AC 1 2 3 4 X Q X X X X

65 MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Enforce AC 1 2 3 4 X Q X X X X

66 MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Enforce AC 1 2 3 4 X Q X X X X

67 MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Enforce AC 1 2 3 4 X X Q X X X

68 Each var has single value
MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Each var has single value Gives solution 1 X X 2 Q X X X 3 X X 4 X X

69 Each var has single value
MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Each var has single value Gives solution 1 X Q X 2 Q X X X 3 X X Q 4 Q X X

70 Each var has single value
MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Each var has single value Gives solution 1 Q 2 Q 3 Q 4 Q

71 Heuristics for backtracking algorithms
Variable ordering (important) what variable to branch on next Value ordering (not yet so important) given a choice of variable, what order to try values Constraint ordering (not so important) what order to propagate constraints most likely to fail or cheapest propagated first

72 Variable ordering Domain dependent heuristics
Domain independent heuristics Static variable ordering fixed before search starts Dynamic variable ordering chosen during search

73 Variable ordering: Possible goals
Minimize expected depth of any branch Encourage constraint propagation Minimize expected number of branches Minimize size of search space explored by backtracking algorithm intractable to find “best” variable

74 Basic idea Assign a heuristic value to a variable that estimates how difficult it is to find a satisfying value for that variable Principle: most likely to fail first or don’t postpone the hard part

75 Some variable ordering heuristics
minimum domain size (dom) maximum degree (deg) most constraining plus: combining — tie break strategies e.g., dom + deg, dom / deg

76 Value ordering All solutions One solution
value ordering not so important One solution if a solution exists, there exists a perfect value ordering

77 Value ordering: Intuition
Goal: minimize size of search space explored Principle: given that we have already chosen the next variable to instantiate, choose first the values that are most likely to succeed

78 Comparing algorithms How do BT, FC and MAC compare?
Theoretical comparison based on size of their search tree MAC beats FC beats BT Experimental comparison MAC is more expensive at each node!

79 Theoretical comparison
Alg1 dominates Alg2 (written Alg1 >= Alg2) iff given same fixed variable and value ordering Alg1 visits search node implies Alg2 also visits this node Alg1 strictly dominates Alg2 (written Alg1 > Alg2) iff Alg1 domiantes Alg2 it visits fewer nodes on at least one problem

80 Theoretical comparison
MAC > FC > BT Homework exercise! Exist problems on which search trees are exponentially smaller But do such problems turn up in practice? Only experiment will tell you if MAC is better than FC for your class of problems Usually it is!

81 Limited discrepancy search
Often first decision is wrong Depth-first search (used in BT/FC/MAC) can take long time to undo this decision E.g. in 4-queens, first decision was x1=1 But first solution has x1=2

82 Limited discrepancy search
Explore search tree in order of number of discrepancies “discrepancy” = branch against heuristic LDS search goes in waves: 0th iteration, explore heuristic branch 1st iteration, explore all branches with 1 branch against heuristic 2nd iteration, explore all branches with 2 branches agaisnt heuristic

83 LDS 0th iteration Follow heuristic to root (or backtrack point)

84 LDS 1st iteration Follow all banches that go against heuristic once

85 LDS 2nd iteration Follow all banches that go against heuristic twice

86 Non-chronological backtracking
Backjumping (BJ) Conflict directed backjumping (CBJ) Key idea in each of these is to backtrack to a “relevant” variable, decision that led to failure Ignore decisions that didn’t contribute to the failure Can combine with FC or MAC E.g. FC-CBJ and MAC-CBJ

87 Backjumping For each var xi, keep index of deepest var which xi performed consistency check If xi has no consistent values, jump back to that var

88 Backjumping For each var xi, keep index of deepest var which xi performed consistency check If xi has no consistent values, jump back to that var Only last backtrack down branch is non-chronological

89 Conflict-directed backjumping
For each var xi, keep conflict set Set of vars which ruled out values from xi If xi has no consistent values, jump back to deepest var Not only first backtrack can be non-chronological Multiple “backjumps” across conflicts possible

90 Theoretical comparison
We can apply the same dominance ordering MAC-CBJ > FC-CBJ > CBJ > BJ > BT FC > BJ

91 Learning Another use for conflict sets
At end of branch, identify cause for failure This is a conflict set Heuristically add to set of constraints Heuristics include size bounded and relevance bounded learning

92 Local search Initial assignment 1 2 Pick queen in conflict Q x1 x2 x3
Move to min. conflicts Q x1 x2 x3 x4 2 Pick queen in conflict Q x1 x2 x3 x4

93 Summary Search important part of constraint solving
Backtracking algorithms often perform inference/constraint propagation at each node Exist various refinements of chronological backtracking like CBJ, LDS, …


Download ppt "Constraints and Search"

Similar presentations


Ads by Google