Search Combinators Tom Schrijvers with Guido Tack, Pieter Wuille, Horst Samulowitz, Peter Stuckey
Search heuristics are crucial.
Support for Search? General Purpose Solver-Provided Programming Language Options “everthing is possible, “everything is easy, nothing is easy” nothing is possible”
State-of-the-Art Modularity: Prolog ✓ label1(Vars1) , label2(Vars2) ✓ label1(Vars1) ; label2(Vars2) ✓ once(label1(Vars1)) ✓ once((label1(Vars1),label2(Vars2))
Lack of Modularity ✘ lds(label1(Vars1))
Lack of Modularity ✘ lds(label1(Vars1)) ✘ lds((label1(Vars1) , label2(Vars2)))
Lack of Modularity ✘ lds(label1(Vars1)) ✘ lds((label1(Vars1) , label2(Vars2))) ✓ lds_label1(Vars1) ✓ lds_label1_label2(Vars1,Vars2)
Can we do better? ✓ Lots of expressivity and flexibility ✓ Lots of productivity through high-level specifications ✓ Modular reuse of search specifications
Yes: Search Combinators High-level modular building blocks “Everything is possible and easy”
Base Search s ≡ int_search( vars ,var_sel,val_sel) • provided by the solver • augment with combinators
Combinators prune let( v , e , s ) assign( v , e ) post( c , s ) if( c , s 1 , s 2 ) and([ s 1 , s 2 ,..., s n ]) or([ s 1 , s 2 ,..., s n ]) portfolio([ s 1 , s 2 ,..., s n ]) restart( c , s )
Statistics Combinators depth( v , s ) discrepancy( v , s ) nodes( v , s ) failures( v , s ) time( v , s )
Statistics Combinators depth( v , s ) discrepancy( v , s ) nodes( v , s ) failures( v , s ) time( v , s ) if(v < 5,depth(v,s 1 ),s 2 )
Statistics Combinators depth( v , s ) discrepancy( v , s ) nodes( v , s ) failures( v , s ) time( v , s ) if(v < 5,depth(v,s 1 ),s 2 ) if(depth < 5,s 1 ,s 2 )
Reusable Abstractions limit( c , s ) ≡ if( c , s ,prune) for( v , l , u , s ) ≡ ... lds(s) ≡ for(n,0, ∞ , limit(discrepancy ≤ n,s) )
Reuse Examples ✓ lds(int_search( vars ,...)) ✓ lds(and([int_search( vars1 ,...) ,int_search( vars2 ,...)]) ✓ lds(or([int_search( vars1 ,...) ,int_search( vars2 ,...)]) ...
More Abstractions bab( obj , s ) restart_bab( obj , s ) dicho( obj , s , lb , ub ) id( s ) hot_start( c , s 1 , s 2 ) see paper
Radiotherapy Planning bab(k, and([int_search(N,...)] ++ [once(int_search(row i ,...)) | i in 1..n ] ) )
Modular Syntax vs. Modular Semantics
Modular Semantics search tree node traditional modularity: • each combinator is an atomic unit • minimal interaction
Modular Semantics search tree node traditional modularity: • each combinator is an atomic unit • minimal interaction
Modular Semantics • cross-cutting behavior • highly entangled in monolithic code ➡ “Aspect-Oriented Programming”
Functional Mixin Inheritance • disciplined form of AOP ★ meaningful and pre-defined set of interaction points • no AOP system needed
Mixin-based Interaction for every child c next(n',n) enter(n) push(c) success failure more
Mixin-based Interaction for every child c next(n',n) enter(n) push(c) Details: see paper success failure more
Implementations DSL Haskell C++ Scala Compact Loop Compacte Lus
Implementations DSL Haskell C++ Scala Zoekheuristiek Search Spec Compact Loop Compacte Lus
Implementations DSL Haskell C++ Scala Objectcompositie Objects Interpreted Zoekheuristiek Search Spec Compact Loop Compacte Lus
Implementations DSL Haskell C++ Scala Objectcompositie Objects Interpreted Zoekheuristiek Search Spec Codegenerators Compact Loop Compacte Lus Code Generators Compiled
Combinator Overhead? Worst-case Scenario compiled interpreted 300,00% n portfolio 250,00% prune runtime base search 200,00% without propagation 150,00% 100,00% 1 2 5 10 20 #combinators
In Practice 180,00% propagation dwarfs combinator overhead 160,00% Gecode Interpreted Compiled 140,00% 120,00% 100,00% 80,00% 0 1 2 1 2 3 4 5 2 5 3 5 0 1 1 1 G H H - 1 y y y y y 1 t p p p p p b b b m Z p p p m m m a a a a a o o o B r r r r r p h h h A o o o e e e e e o s s s l l l h h h h h o o o p - - - h t t t t t G G G b b b o o o o o o s o o o - i i i i i h d d d d d b J J J s a a a a a o - R R R R R b J o J
Summary high-level modular modeling of search low-level modular implementation competitive performance compared to hand-coded algorithm
Future Work • Optimizations • MiniZinc integration • Combinators for parallel search • Extend other solving technology (e.g., LP) ➡ Combinators for hybrid search
Thank You!
Combinator Overhead 300,00% compiled interpreted 250,00% runtime 200,00% 150,00% 100,00% 1 2 5 10 20 #combinators
Recommend
More recommend