Kangaroo: An Efficient Constraint-Based Local Search System Using - - PowerPoint PPT Presentation

kangaroo an efficient constraint based local search
SMART_READER_LITE
LIVE PREVIEW

Kangaroo: An Efficient Constraint-Based Local Search System Using - - PowerPoint PPT Presentation

Kangaroo: An Efficient Constraint-Based Local Search System Using Lazy Propagation M.A.Hakim Newton 1 , 2 , Duc Nghia Pham 1 , 2 , Abdul Sattar 1 , 2 , Michael Maher 1 , 3 , 4 1 National ICT Australia, 2 IIIS, Griffith University 3 CSE, University


slide-1
SLIDE 1

Kangaroo: An Efficient Constraint-Based Local Search System Using Lazy Propagation

M.A.Hakim Newton1,2, Duc Nghia Pham1,2, Abdul Sattar1,2, Michael Maher1,3,4

1National ICT Australia, 2IIIS, Griffith University 3CSE, University of NSW, 4Reasoning Research Institute, Sydney

CP’2011, September 12–16, Perugia, Italy

1 / 26

slide-2
SLIDE 2

Presentation Outline

1

CBLS Introduction

2

Comet & Kangaroo

3

Kangaroo Details

4

Conclusions

2 / 26

slide-3
SLIDE 3

Constraint-Based Local Search (CBLS)

Constraint satisfaction as optimisation

◮ Minimising constraints’ violation metrics. ◮ Solved when violation metrics are zero. ◮ Search is perhaps guided by the constraints.

Using local search to solve the problem

1 Start from a random value-to-variable assignment. 2 Repeatedly make the “best” possible move each time. 3 If stuck at plateaus, restart the search process. 3 / 26

slide-4
SLIDE 4

Magic Square Example

Frequent Operations During Search

◮ Execution: given a move, propagate changes as needed. ◮ Simulation: given a move, what would be the violation metric? ◮ Simulations help find the “best” move for next execution.

4 / 26

slide-5
SLIDE 5

CBLS System

Separation of Representation and Search

◮ Representation: easy problem specification (e.g. sum, equal). ◮ Search: easy to play with strategies (e.g. best swap). ◮ The CBLS system supports the interactions in between.

Invariants and Differentiable Objects

◮ Invariants are expressions that are maintained up-to-date. ◮ Diff. objects efficiently compute effects of potential moves. ◮ These commitments are maintained by the CBLS system.

5 / 26

slide-6
SLIDE 6

Local Search and CBLS Systems

iOpt, 2000: A toolkit for private use within British Telecom, UK. HotFrame, 2002: Template-based libraries focusing on flexibility rather than efficiency. EasyLocal++, 2003: Template-based libraries focusing on flexibility rather than efficiency. Localizer, 2000: A precursor to Comet; supports mainly invariants. Comet, 2005: The state-of-the-art CBLS system with its own language for problem model & search specification. Kangaroo, 2011: An efficient C++ library; first exposition of key implementation details.

6 / 26

slide-7
SLIDE 7

Magic Square Representation

Comet Kangaroo

SolverLSm(); int C = n ∗ (n ∗ n + 1)/2; range Size = 1..n ∗ n; var{int} s[Size](m, Size); ConstraintSystemLSS(m); forall( i in 1..n ) S.post((sum(j in 1..n) s[(i − 1) ∗ n + j]) == C) S.post((sum(j in 1..n) s[(j − 1) ∗ n + i]) == C) S.post((sum(i in 1..n) s[(i − 1) ∗ n + i]) == C) S.post((sum(i in 1..n) s[(i − 1) ∗ n + n − i + 1]) == C) defSolver (Solver); int C = n ∗ (n ∗ n + 1)/2; forall( i in 1..n ∗ n ) defVar (Solver,s[i], 1, n ∗ n) Row[i] : Vars in Row i, Col[j] : Vars in Col j Diag1, Diag2 : Vars in the 2 diagonals resp. RS, CS, DS1, DS2: row, col, and diag. sums resp. Eq, AC: equal constraints and their combinator. forall( k in 1..n ) defSum (Solver, RS[k], Row[k]) defEqConstr (Solver, Eq[k], RS[k], C) defSum (Solver, CS[k], Col[k]) defEqConstr (Solver, Eq[n + k], CS[k], C) defSum (Solver, DS1, Diag1) defEqConstr (Solver, Eq[2 ∗ n + 1], DS1, C) defSum (Solver, DS2, Diag2) defEqConstr (Solver, Eq[2 ∗ n + 2], DS2, C) defAndConstr (Solver, AC, Eq)

7 / 26

slide-8
SLIDE 8

Magic Square Search

Comet Kangaroo

RandomPermutation distr (Size); forall( i in Size ) s[i] := distr.get (); int tabu[Size] = 0; while( S.violations() > 0 ){ if it ≥ MaxIt then return; selectMin( i in Size: tabu[i] ≤ it, j in Size: i < j∧ tabu[j] ≤ it ) (S.getSwapDelta(s[i], s[j])) { s[i] :=: s[j]; // Swap the values tabu[i] = it + TabuLength; tabu[j] = it + TabuLength; } it = it + 1; } setTabuLength (Solver, TabuLength); defTabuMinSwapSel// handles tabu (Solver, Selector, AndConstr); assign a random permutation of [1..n ∗ n] to s; while( AC.violations() > 0 ){ if it ≥ MaxIt then return; run Selector to select a var-pair (s[i], s[j]); swap the value of s[i] and s[j]; it = it + 1; }

8 / 26

slide-9
SLIDE 9

Comet and Kangaroo: Performance

Benchmark Problems from CSP-Lib

The problem model and search algorithms are semantically very close. Kangaroo Comet Instances %Succ #Iter Time Mem %Succ #Iter Time Mem all interval series (4) 75% 21, 734 1.6 20 50% 504, 465 65.1 42 golomb ruler (11) 91% 681, 452 8.0 21 45% not computed 42 graph coloring (20) 100% 774 0.0 22 50% 590 0.3 44 magic square (9) 100% 212 172.6 22 100% 213 103.3 43 n-queens (18) 100% 8, 532 104.7 111 100% 8, 597 140.9 293 social golfer (16) 88% 987, 822 21.7 22 19% not computed 47 vessel loading (45) 100% 212 0.0 24 62% 3, 741, 397 96.4 43 Time in cpu-seconds, Memory in megabytes ◮ Kangaroo’s memory usage is half of Comet’s. ◮ Kangaroo solves problems more frequently. ◮ Kangaroo is usually very efficient.

9 / 26

slide-10
SLIDE 10

Kangaroo Features

Key Features

◮ Lazy on-demand recomputation using top-down traversal ◮ Specialised incremental execution for aggregate formula ◮ Specialised incremental simulation boosted by caching

◮ When ranges of values are tried for the same variables ◮ Dfferent sets of variables differ just by one variable

Other features

◮ Array-based fast data structures ◮ Indexes unify values of any data types. ◮ Low-level memory management for compactness. ◮ System level data encapsulation (not object level)

10 / 26

slide-11
SLIDE 11

Incremental Computation

Key to Efficient Propagation in CBLS systems

◮ Each move normally changes values only to a few variables. ◮ Expr. values recomputed only by incorporating the changes. ◮ Undo/Redo with the old/new value of the changed operand.

Summation Example: B = 5, S =?

◮ S = A + B + C ◮ S = 3 + 4 + 2 ◮ S = 9 ◮ S = 9+undo(B)+redo(B) ◮ S = 9 − B.old + B.new ◮ S = 9 − 4 + 5 = 10

11 / 26

slide-12
SLIDE 12

Incremental Propagation

◮ Change variables and propagate the changes incrementally. ◮ Propagation is required for both execution and simulation.

12 / 26

slide-13
SLIDE 13

Prompt Propagation

◮ Ancestors of the changed variable would be affected ◮ The would-be-affected nodes are to be recomputed

13 / 26

slide-14
SLIDE 14

Comet Propagation

◮ Prompt, bottom-up, topological ordering, priority queue ◮ No change in a recomputed node, no further propagation

14 / 26

slide-15
SLIDE 15

Lazy Propagation

◮ Recompute only nodes that are currently required ◮ Defer computations for nodes not required currently

15 / 26

slide-16
SLIDE 16

Mark-Sweep† Propagation: Marking

1 Two phases in the algorithm: marking and sweeping. 2 Mark the would-be-affected nodes recursively bottom up. 3 The would-be-affected nodes become out-of-date. † Incremental Attribute Evaluation: A Flexible Algorithm for Lazy Update, Scott Hudson, TransactIons on Programming Languages and Systems, Vol 13, No 3, July 1991. 16 / 26

slide-17
SLIDE 17

Mark-Sweep† Propagation: Sweeping

1 Sweep only the required nodes recursively top-down. 2 Required nodes are now recomputed and up-to-date. 3 Recomp. of out-of-date nodes appears non-incremental. † Incremental Attribute Evaluation: A Flexible Algorithm for Lazy Update, Scott Hudson, TransactIons on Programming Languages and Systems, Vol 13, No 3, July 1991. 17 / 26

slide-18
SLIDE 18

Kangaroo Propagation

1 Top-down recursive recomputation from requisite nodes. 2 Bottom-up recursive notification to deferred nodes. 3 No separate marking/sweeping/notification phase. 18 / 26

slide-19
SLIDE 19

Kangaroo Propagation

If a node is changed

1 Perform undo operation in its deferred parents. 2 Undeferred parents take the change into account. 19 / 26

slide-20
SLIDE 20

Kangaroo Propagation

If a node is unchanged

1 No propagation is required to the deferred parents. 2 Undeferred parents take the no-change into account. 20 / 26

slide-21
SLIDE 21

Kangaroo Propagation

If a deferred node is undone

1 Deferred ancestors are notified about potential changes. 2 This (out-of-date) notification is recursive and bottom-up. 21 / 26

slide-22
SLIDE 22

Kangaroo Propagation

Deferred Computation Summary

1 Immediate deferred parents perform undo operation. 2 Higher-level deferred parents just get notifications. 3 Recomp. of a deferred node carefully performs undo/redo. 22 / 26

slide-23
SLIDE 23

Incremental Simulation

Comet and Mark-Sweep

◮ Comet propagates and reverse the effect; very costly. ◮ Comet depends on specialised APIs, not simulations. ◮ Mark-Sweep approach does not consider simulations.

Kangaroo

◮ Two separate sets of data buffers, so no reversing. ◮ Supported for both out-of-date and up-to-date nodes. ◮ Simulation, boosted by caching, is at the center.

23 / 26

slide-24
SLIDE 24

Kangaroo Simulation with Caching

Same variables, Ranges of values: factor out and cache.

◮ S = X + Y + Z, X = 1, Simulate for X = 2, 3 ◮ S.newval = S.oldval + undo(1) + redo(2) ◮ S.newval = S.oldval + undo(1) + redo(3)

Shared variables in swap: factor out and cache

◮ S = f (A, B, C) = f ′(X, Y , Z), Simulate swaps (X, Y), (X, Z) ◮ Factor out and cache children dependent on X. ◮ Factor out and cache undo operation for X.

24 / 26

slide-25
SLIDE 25

Conclusions

◮ We introduced a lazy but efficient CBLS system. ◮ We plan to release it under open source license. ◮ We plan to further extend its functionalities.

25 / 26

slide-26
SLIDE 26

Kangaroo vs Kangaroo

◮ Australian Marsupial ◮ Look around and hop ◮ Usually very lazy ◮ A pouch to hold kids ◮ Cannot move backward ◮ Australian Software ◮ Explore Neighbor & Move ◮ Performs lazy propagation ◮ Cache to hold results ◮ Normally no backtracking

26 / 26