Title: Figaro Yet Another Constraint Programming Library
1FigaroYet Another Constraint Programming Library
- Martin Henz, Ka Boon Ng
- National University of Singapore
- Tobias Müller
- Universität des Saarlandes
2Finite Domain Constraint Programming
- A technique for solving combinatorial search and
optimization problems.
3S E N D M O R E M O N E Y
4S E N D M O R E M O N E Y
Modeling
- 0?S,,Y?9
- S ? 0
- M ? 0
- SY all different
- 1000S 100E
10N D - 1000M 100O 10R E
- 10000M 1000O 100N 10E Y
5S E N D M O R E M O N E Y
S ? N E ? N N ? N D ? N M ? N O ? N R ? N Y ? N
- 0?S,,Y?9
- S ? 0
- M ? 0
- SY all different
- 1000S 100E
10N D - 1000M 100O 10R E
- 10000M 1000O 100N 10E Y
6S E N D M O R E M O N E Y
Propagate
S ? 0..9 E ? 0..9 N ? 0..9 D ? 0..9 M ?
0..9 O ? 0..9 R ? 0..9 Y ? 0..9
- 0?S,,Y?9
- S ? 0
- M ? 0
- SY all different
- 1000S 100E
10N D - 1000M 100O 10R E
- 10000M 1000O 100N 10E Y
7S E N D M O R E M O N E Y
Propagate
S ? 1..9 E ? 0..9 N ? 0..9 D ? 0..9 M ?
1..9 O ? 0..9 R ? 0..9 Y ? 0..9
- 0?S,,Y?9
- S ? 0
- M ? 0
- SY all different
- 1000S 100E
10N D - 1000M 100O 10R E
- 10000M 1000O 100N 10E Y
8S E N D M O R E M O N E Y
Propagate
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
- 0?S,,Y?9
- S ? 0
- M ? 0
- SY all different
- 1000S 100E
10N D - 1000M 100O 10R E
- 10000M 1000O 100N 10E Y
9S E N D M O R E M O N E Y
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
Labeling
E ? 4
E 4
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
- 0?S,,Y?9
- S ? 0
- M ? 0
- SY all different
- 1000S 100E
10N D - 1000M 100O 10R E
- 10000M 1000O 100N 10E Y
10S E N D M O R E M O N E Y
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
Propagate
E ? 4
E 4
S ? 9 E ? 5..7 N ? 6..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
- 0?S,,Y?9
- S ? 0
- M ? 0
- SY all different
- 1000S 100E
10N D - 1000M 100O 10R E
- 10000M 1000O 100N 10E Y
11S E N D M O R E M O N E Y
Labeling
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
E ? 4
E 4
S ? 9 E ? 5..7 N ? 6..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
E 5
E ? 5
S ? 9 E ? 5..7 N ? 6..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
S ? 9 E ? 5..7 N ? 6..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
12S E N D M O R E M O N E Y
Propagate
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
E ? 4
E 4
S ? 9 E ? 5..7 N ? 6..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
E 5
E ? 5
S ? 9 E ? 5 N ? 6 D ? 7 M ? 1 O ? 0 R
? 8 Y ? 2
S ? 9 E ? 6..7 N ? 7..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
13S E N D M O R E M O N E Y
Complete Search Tree
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
E 4
E ? 4
S ? 9 E ? 5..7 N ? 6..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
E 5
E ? 5
S ? 9 E ? 5 N ? 6 D ? 7 M ? 1 O ? 0 R
? 8 Y ? 2
S ? 9 E ? 6..7 N ? 7..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
E ? 6
E 6
14Is That All?
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1...
E 4
E ? 4
- Complex
- symbolic
- constraints
- Programmable search
- Trailing vs copying
- Design patterns for constraint programming
- Integration of other search techniques
S ? 9 E ? 5..7 N ? 6..8 D ? 2..8 M ?
1...
E 5
E ? 5
S ? 9 E ? 5 N ? 6 D ? 7 M ? 1..
S ? 9 E ? 6..7 N ? 7..8 D ? 2..8 M ?
1...
E 6
E ? 6
15FD(CP) Languages and Libraries
- Languages
- CLP(FD)
- Eclipse, CHIP
- CLAIRE new language
- Oz new language
- Libraries
- PECOS LISP
- Ilog Solver C
- Figaro C, under development
Prolog based
16Design Issues
- Languages
- CLP(FD)
- Eclipse, CHIP
- CLAIRE
- Oz
- Libraries
- PECOS
- Ilog Solver
- Syntax
- Integration with
- application programming
- Programming
- propagation algorithms
- Programming search
- strategies
- Programming search
- algorithms
17Representing the Constraint Store
- class store
- public
- store()
- var newvar(int lo,
- int hi)
- var getlo(var v)
- var gethi(var v)
- ...
18Representing the Constraint Store
- class store
- public
- store()
- var newvar(int lo,
- int hi)
- var getlo(var v)
- var gethi(var v)
- ...
int main(...) storestnew store()
...
19Representing the Constraint Store
- class store
- public
- store()
- var newvar(int lo,
- int hi)
- var getlo(var v)
- var gethi(var v)
- ...
int main(...) storestnew store() s
st -gt newvar(0,9) ... y st -gt
newvar(0,9) ...
20Representing the Constraint Store
- class store
- public
- store()
- var newvar(int lo,
- int hi)
- var getlo(var v)
- var gethi(var v)
- ...
int main(...) storestnew store() s
st -gt newvar(0,9) ... y st -gt
newvar(0,9) all_different(st,
s,..,y) ...
21Representing Search Trees
- class node
- public virtual node child(store ,int)0
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1...
E 4
E ? 4
S ? 9 E ? 5..7 N ? 6..8 D ? 2..8 M ?
1...
E 5
E ? 5
S ? 9 E ? 5 N ? 6 D ? 7 M ? 1..
S ? 9 E ? 6..7 N ? 7..8 D ? 2..8 M ?
1...
E 6
E ? 6
22Representing Search Trees
- class naive public node
- private int idxvectorltvargt varsnodesubtree
- public
- naive(vectorltvargt vs,int i,nodet) ...
- node child(storest, int i)
- if (i0)
- st-gttell(varsidx,st-gtgetlo(varsidx))
- return (idx1var.size() ? subtree
- new naive(vars,idx1,subtree))
- else
- st-gttell(varsidx,st-gtgetlo(varsidx)1,
- st-gtgethi(varsidx))
- return new naive(vars,idx,subtree)
-
23Backtracking
- mark storemark()
- void storebacktrack(mark m)
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1...
E 4
E ? 4
S ? 9 E ? 5..7 N ? 6..8 D ? 2..8 M ?
1...
E 5
E ? 5
S ? 9 E ? 5 N ? 6 D ? 7 M ? 1..
S ? 9 E ? 6..7 N ? 7..8 D ? 2..8 M ?
1...
E 6
E ? 6
24Depth-first Search (backtracking)
- node solve_one(store s,node t)
- if (t NULL) return t
- mark m s-gtmark()
- try return solve_one(s,t-gtchild(s,0))
- catch (Failure)
- s-gtbacktrack(m)
- return solve_one(s,t-gtchild(s,1))
-
25Stepping Back
- Nothing new so far Oz has programmable search
algorithms through spaces (Schulte, ICLP97)
Ilog Solver has IlcManager objects. - But
- lean stores
- nodes as an abstraction for programming search
strategies - more on the basic data structures in the
proceedings - moving on Trailing vs. Copying (Schulte, ICLP99)
26Trailing vs Copying
- Trail and backtrack
- Copy and abandon
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1...
E 4
E ? 4
S ? 9 E ? 5..7 N ? 6..8 D ? 2..8 M ?
1...
E 5
E ? 5
S ? 9 E ? 5 N ? 6 D ? 7 M ? 1..
S ? 9 E ? 6..7 N ? 7..8 D ? 2..8 M ?
1...
E 6
E ? 6
27Copying Stores
- Simply copy the store with all variables and
constraints - storestore(const store)
- But nodes refer to variables
their addresses change!
28Labeling Refers to Variables
- class naive public node
- private int idxvectorltvargt varsnodesubtree
- public
- naive(vectorltvargt vs,int i,nodet) ...
- node child(storest, int i)
- if (i0)
- st-gttell(varsidx,st-gtgetlo(varsidx))
- return (idx1vars.size() ? subtree
- new naive(vars,idx1,subtree))
- else
- st-gttell(varsidx,st-gtgetlo(varsidx)1,
- st-gtgethi(varsidx))
- return new naive(vars,idx,subtree)
-
29Search Refers to Marks
- node solve_one(store s,node t)
- if (t NULL) return t
- mark m s-gtmark()
- try return solve_one(s,t-gtchild(s,0))
- catch (Failure)
- s-gtbacktrack(m)
- return solve_one(s,t-gtchild(s,1))
-
30Indirect Addressing
store
- only use indices in arrays to address variables,
propagators and marks
vars
props
trail
1 2 3 4 5 . . .
1 2 3 4 5 . . .
1 2 3 4 5 . . .
Now nodes dont need to care, whether they work
on original or copy.
31Depth-first Search (copying)
- node solve_one(store s,node t)
- if (t NULL) return t
- store s2 new store(s)
- try return solve_one(s,t-gtchild(s,0))
- catch (Failure)
- return solve_one(s2,t-gtchild(s,1))
-
32Stepping Back
- Indirect addressing allows copy and
trailing-based search - Possibly interesting combinations of the two to
be explored - Moving on Memory policy just one dimension in
the design space for search algorithms.
33Dimensions in the Design Space for Search
Algorithms
- Exploration depth-first search,
limited-discrepancy search,... - Memory policy copying, trailing,...
- Optimization branch-and-bound, restart
optimization,... - Interaction first, last, all solution search,
tracing,... - Visualization Oz Explorer like search tree
visualization
34STK Software Engineering of Inference Engines
- STK originally developed for Oz
- Allows to separate design dimensions into modules
- Software architecture ensures reusability of
components - STK ideas will be at the heart of Figaro
35Example Exploration and Interaction
- Exploration is defined by a class that extends
the abstract class exploration. - class exploration
- public virtual node one_step()0
36Example Exploration and Interaction
- Exploration is defined by a class that extends
the abstract class exploration. - class exploration
- public virtual node one_step()0
- Interaction calls one_step according to the
desired mode of interaction. - node first(exploration e)
- node n
- while (n e-gtone_step())
- if (nsuccess_node) break
- return n
37Stepping Back
- Design patterns for tree search
- More in paper A Search Toolkit for Constraint
Programming (PADL00) - Moving on Constraint programming is just one
technique local search?
38Global Search
??
F?
?T
T?
?F
FT
TT
FF
TF
39Global Search
??
v1F
F?
?T
v1T
T?
?F
FT
TT
FF
TF
40Global Search
??
v1F
F?
?T
v1T
T?
v2T
?F
v2F
FT
TT
FF
TF
41Global Search
??
v1F
F?
?T
v1T
T?
v2T
?F
Search Tree
v2F
FT
v2T
TT
FF
v2F
solution
TF
42Local Search
??
v1F
F?
?T
v1T
T?
v2T
?F
consider only full assignments of variables to
values
v2F
FT
v2T
TT
FF
v2F
solution
TF
43Local Search
FT
Search Space
TT
FF
TF
44Local Search
neighborhood
FT
initial assignment
TT
FF
TF
45Local Search
FT
TT
FF
local move
TF
46Local Search
FT
TT
FF
TF
local move
47Local Search
FT
TT
FF
solution found
TF
48Observations
- Data structures needed for constraint programming
are the same as in local search. - Integration of CP and LS has been approached
before. - Stephen Won, MS thesis supervised by Jimmy Lee
(1997)
49Stepping Back (for good)
- Viewing constraint programming as a collection of
design patterns. - Flexible memory policy through indirect
addressing - Figaro initiative
- library for discrete problem solving and
optimization - local search and constraint programming (LP,IP?)
- designed by researchers for researchers
- open source, current contributors N U Singapore,
partners CUHK, PSL
50Figaro (very last slide)
- Figaro, an offspring of Mozart
- F I nite domain
- GA dget for combinatorial
- p RO blem solving