Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00%...

36
Search Combinators Tom Schrijvers with Guido Tack, Pieter Wuille, Horst Samulowitz, Peter Stuckey

Transcript of Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00%...

Page 1: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Search CombinatorsTom Schrijvers

with Guido Tack, Pieter Wuille, Horst Samulowitz, Peter Stuckey

Page 2: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Search heuristics are crucial.

Page 3: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Support for Search?General Purpose

Programming Language

“everthing is possible, nothing is easy”

Solver-ProvidedOptions

“everything is easy, nothing is possible”

Page 4: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

State-of-the-Art Modularity: Prolog

✓ label1(Vars1) , label2(Vars2)

✓ label1(Vars1) ; label2(Vars2)

✓ once(label1(Vars1))

✓ once((label1(Vars1),label2(Vars2))

Page 5: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Lack of Modularity

✘ lds(label1(Vars1))

Page 6: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Lack of Modularity

✘ lds(label1(Vars1))

✘ lds((label1(Vars1) , label2(Vars2)))

Page 7: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Lack of Modularity

✘ lds(label1(Vars1))

✘ lds((label1(Vars1) , label2(Vars2)))

✓ lds_label1(Vars1)

✓ lds_label1_label2(Vars1,Vars2)

Page 8: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Can we do better?

✓Lots of expressivity and flexibility

✓Lots of productivity through high-level specifications

✓Modular reuse of search specifications

Page 9: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Yes: Search Combinators

“Everything is possible and easy”

High-level modular building blocks

Page 10: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Base Search

s ≡ int_search(vars,var_sel,val_sel)

• provided by the solver• augment with combinators

Page 11: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Combinatorsprunelet(v,e,s)assign(v,e)post(c,s)if(c,s1,s2)and([s1, s2,..., sn])or([s1, s2,..., sn])portfolio([s1, s2,..., sn])restart(c,s)

Page 12: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Statistics Combinators

depth(v,s)discrepancy(v,s)

nodes(v,s)failures(v,s)time(v,s)

Page 13: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Statistics Combinators

depth(v,s)discrepancy(v,s)

nodes(v,s)failures(v,s)time(v,s)

if(v < 5,depth(v,s1),s2)

Page 14: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Statistics Combinators

depth(v,s)discrepancy(v,s)

nodes(v,s)failures(v,s)time(v,s)

if(v < 5,depth(v,s1),s2)if(depth < 5,s1,s2)

Page 15: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Reusable Abstractionslimit(c,s) ≡ if(c,s,prune)

for(v,l,u,s) ≡ ...

lds(s) ≡ for(n,0,∞, limit(discrepancy ≤ n,s) )

Page 16: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Reuse Examples

✓lds(int_search(vars,...))

✓lds(and([int_search(vars1,...) ,int_search(vars2,...)])

✓lds(or([int_search(vars1,...) ,int_search(vars2,...)])...

Page 17: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

More Abstractionsbab(obj,s)

restart_bab(obj,s)

dicho(obj,s,lb,ub)

id(s)

hot_start(c,s1,s2) see paper

Page 18: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Radiotherapy Planning

bab(k, and([int_search(N,...)] ++ [once(int_search(rowi,...)) | i in 1..n ] ) )

Page 19: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

ModularSyntax

vs.

SemanticsModular

Page 20: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Modular Semantics

traditional modularity:• each combinator is an atomic unit• minimal interaction

search treenode

Page 21: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Modular Semantics

traditional modularity:• each combinator is an atomic unit• minimal interaction

search treenode

Page 22: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Modular Semantics

• cross-cutting behavior

• highly entangled in monolithic code

➡ “Aspect-Oriented Programming”

Page 23: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Functional Mixin Inheritance

• disciplined form of AOP

★ meaningful and pre-defined set of interaction points

• no AOP system needed

Page 24: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Mixin-based Interaction

successfailure

enter(n)

more

for every child c

push(c)next(n',n)

Page 25: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Mixin-based Interaction

Details:see paper

successfailure

enter(n)

more

for every child c

push(c)next(n',n)

Page 26: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Implementations

Compacte Lus

DSL Haskell C++ Scala

Compact Loop

Page 27: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Implementations

Zoekheuristiek Compacte Lus

DSL Haskell C++ Scala

Compact LoopSearch Spec

Page 28: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Implementations

Zoekheuristiek

Objectcompositie

Compacte Lus

DSL Haskell C++ Scala

Compact LoopSearch Spec

Objects

Interpreted

Page 29: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Implementations

Zoekheuristiek

Objectcompositie

Compacte LusCodegenerators

DSL Haskell C++ Scala

Compact LoopSearch Spec

Objects

Code Generators

Interpreted

Compiled

Page 30: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Combinator Overhead?

portfolio

prune

base searchwithout

propagation

n

Worst-case Scenario

100,00%

150,00%

200,00%

250,00%

300,00%

1 2 5 10 20

runtim

e

#combinators

compiled interpreted

Page 31: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

80,00%

100,00%

120,00%

140,00%

160,00%

180,00%

Golom

b 10

Golom

b 11

Golom

b 12

Radio

ther

apy 1

Radio

ther

apy 2

Radio

ther

apy 3

Radio

ther

apy 4

Radio

ther

apy 5

Job-s

hop G2

Job-s

hop H5

Job-s

hop H3

Job-s

hop ABZ1-

5

Job-s

hop mt1

0

In Practicepropagation dwarfs combinator overhead

Gecode Interpreted Compiled

Page 32: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Summary

high-level modular modeling of search

low-level modular implementation

competitive performance compared to hand-coded algorithm

Page 33: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Future Work

• Optimizations

• MiniZinc integration

• Combinators for parallel search

• Extend other solving technology (e.g., LP)

➡ Combinators for hybrid search

Page 34: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Thank You!

Page 35: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy
Page 36: Search Combinatorshorst/cogrobo/papers/cp2011_search... · 2011. 10. 10. · 80,00% 100,00% 120,00% 140,00% 160,00% 180,00% Golomb 10 Golomb 11 Golomb 12 Radiotherapy 1 Radiotherapy

Combinator Overhead

100,00%

150,00%

200,00%

250,00%

300,00%

1 2 5 10 20

runtim

e

#combinators

compiled interpreted