1 / 56

Choco A Constraint Programming System

Choco A Constraint Programming System. Suzette Person CSCE 821 Spring 2008. Outline. Background & introduction Domain types Constraints and Constraint Propagation Search & Branching How we use Choco in.. Java Pathfinder, a static analysis tool for Java programs. Background.

ananda
Download Presentation

Choco A Constraint Programming System

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ChocoA Constraint Programming System Suzette Person CSCE 821 Spring 2008

  2. Outline • Background & introduction • Domain types • Constraints and Constraint Propagation • Search & Branching • How we use Chocoin.. • Java Pathfinder, a static analysis tool for Java programs

  3. Background • Open-source (BSD license) • Hosted on Sourceforge.net • Created in 1996 by François Laburthe and Narenda Jussien • Associated with Ecole des Mines de Nantes (Nantes, France), Bouygues (Paris, France) and Amadeus (Nice, France)

  4. Background • Developed to support CP research in combinatorial optimization • ‘Easy’ to use • Extensible • Modular • ‘Optimized’ • Library vs. autonomous system

  5. Implementation Highlights • Developed in Claire (compile to Java or C++) • Encapsulate all information in a Problem object to support definition of multiple problems in a single session • Single threaded search, one per problem instance • Use trailing (i.e. incremental) stack for backtracking

  6. Outline • Background & introduction • Domain types • Constraints and Constraint Propagation • Search & Branching • How we use Chocoin.. • Java Pathfinder, a static analysis tool for Java programs

  7. Domain Types Supports three types of variable domains • Integer: IntDomainVar • Real: RealVar • Set: SetVar

  8. Domain Types • IntDomainVar (support for discrete domains) • EnumIntVar • Enumerated integer values • Used for small domains • BoundIntVar • Intervals of integer values • Used for large domains • Represented by upper and lower bounds: useful for box-consistency (propagation is performed only on bounds)

  9. Domain Types • RealVar (support for continuous domains) • Limited support currently available in Choco (enough to support “toy” problems) • Ex. CycloHexane problem y2 * (1 + z2) + z * (z - 24 * y) = -13 x2 * (1 + y2) + y * (y - 24 * x) = -13 z2 * (1 + x2) + x * (x - 24 * z) = -13 RealVar x = pb.makeRealVar("x"); RealVar y = pb.makeRealVar("y", -1.0e8, 1.0e8); RealVar z = pb.makeRealVar("z", -1.0e8, 1.0e8);

  10. Domain Types • SetVar • High level modeling tool • Supports representation of domains where each value is a set • Example: a set variable on integer values [1..n] has 2n values - every possible subset of {1..n} • Choco applies a kind of bounds consistency to this type of domain

  11. Outline • Background & introduction • Domain types • Constraints and Constraint Propagation • Search & Branching • How we use Chocoin.. • Java Pathfinder, a static analysis tool for Java programs

  12. Constraints • Constraints on integer variables • Constraints on real variables • Constraints on set variables • User-defined constraints

  13. 1. Constraints on integer variables • Basic constraints • Channeling constraints • Arbitrary constraints (in extension) • Binary constraints; Nary constraints • Advanced constraints • Global constraints • Boolean composition of constraints

  14. Integer Vars > Basic Constraints • Arithmetic • Equality (v1 == v2, v1 != v2); comparisons (v1 <= v2, v1 < v2); difference; linear combinations; product of variables, … • Complex expressions • Over expressions: plus, minus, mult, … • Over variables: times, scalar, sum, … • More expressions • max, min, abs , …

  15. Integer Vars > Basic Constraints var1 var2 c1 [2..5] [1..10] var4 c2 [-4..8] [1..10] var3 [5..10] c3 var5exp IntDomainVar var1 = prob.makeEnumIntVar(“var1”, 2, 5); IntDomainVar var2 = prob.makeEnumIntVar(“var2”, 1, 10); IntDomainVar var3 = prob.makeEnumIntVar(“var3”, 5, 10); IntDomainVar var4 = prob.makeEnumIntVar(“var4”, 1, 10); Constraint c1 = prob.gt(var2,var1); Constraint c2 = prob.leq(var1,var3); IntExp var5Exp = prob.minus(var4, var1); Constraint c3 = prob.neq(var5Exp,var3); prob.post(c1); prob.post(c2); prob.post(c3);

  16. Integer Vars > Channeling Constraints • Redundant models • A common technique for strengthening propagation or to get more freedom in designing dedicated heuristics • Channeling constraints • Used to ensure the integrity of different models • By propagating variable instantiations and domain reductions between models

  17. Integer Vars > Channeling Constraints • Channeling constraints are not part of the original problem specification – only serve as a link between models • Inverse channeling: ensures x[i]=j <=> y[j]=i (useful in matrix models) • Boolean channeling: ensures x=j <=> bv=1 where bv is a boolean variable of domain {0,1} and x is an integer variable

  18. Integer Vars > Arbitrary Constraints • Binary and N-ary • Specified in extension • As supports or conflicts • Suitable for small domains • In tables, which may be shared by different constraints (!) in order to reduce space • Specified in intension • As predicates, implies some run-time overhead for calling the feasibility test

  19. Integer Vars > Arbitrary Constraints > Extension • Binary • Consistency checking available: AC3, AC4, AC2001 • Nary • Consistency checking available: FC (?) & GAC • GAC • Supports: GAC3rm by [Lecoutre & Hemery IJCAI 2007] • Conflicts: standard GAC

  20. Integer Vars > Advanced Constraints • Global • allDiff • globalCardinality • occurrence • cumulative • nth • lex • atMostValue • regular

  21. Integer Vars > Advanced Constraints • allDiff: ensures all pairs of variables have distinct values • globalCardinality: ensures the number of occurrences of the value i is within the specified bounds Satisfying? var1 = 5 var2 = 8 var3 = 5 var4 = 5 var1 var2 vars=[var1,var2,var4] low[4]=1 high[4]=2 c1 [2..5] [1..10] var4 c2 c1:var1 < var2 c2: var1 <= var3 c3: var5exp<>var3 c4:gc(vars,low,high) [-4..8] [1..10] var3 [5..10] c3 var5exp (var4 – var1)

  22. Integer Vars > Advanced Constraints • occurrence: ensures that the specified variable is instantiated to the number of occurrences of the value in a list of variable values (a specialization of globalCardinality) Satisfying? var1 = 5 var2 = 8 var3 = 2 var4 = 5 var1 var2 vars=[var1,var2,var4] c1 [2..5] [1..10] var4 c2 c1:var1 < var2 c2: var1 <= var3 c3: var5exp<>var3 c4: occur(vars, 5, var3) [-4..8] [1..10] var3 [5..10] c3 var5exp (var4 – var1)

  23. Integer Vars > Advanced Constraints • cumulative: Given a set of tasks defined • by their starting dates, ending dates, durations and consumptions/heights, • the cumulative ensures that at any time t, the sum of the heights of the tasks which are executed at time t does not exceed a given limit C (the capacity of the resource).

  24. Integer Vars > Advanced Constraints > cumulative C = capacity (cumulative) cost/consumption time t1 In this example: each task has consumption/height = 1 unit t2 t3 t4 t5

  25. Integer Vars > Advanced Constraints • nth: allows specification of a constraint where values are variables (also known as the element constraint) • http://www.emn.fr/x-info/sdemasse/gccat/sec4.105.html#uid11321 • lex: enforces a strict lexicographic ordering on two vectors of integer values

  26. Integer Vars > Advanced Constraints • atMostValue: enforces the number of different values assigned to variables to be at most n vars=[var1,var2,var4] Satisfying? var1 = 5 var2 = 8 var3 = 5 var4 = 5 var1 var2 c1 [2..5] [1..10] c1:var1 < var2 c2: var1 <= var3 c3: var5exp<>var3 c4:amv(vars, 2) var4 c2 [-4..8] [1..10] var3 [5..10] c3 var5exp (var4 – var1)

  27. Integer Vars > Advanced Constraints • regular: enforces a sequence of variables to be a word recognized by a given finite deterministic automaton (DFA) 3 Accepted words : sequence of value 3 (of size 6) where subsequences of value 1 (if any exist) are exactly of size 3. For example : 331113. 3 1 1 1 1 0 2 3 3

  28. Integer Vars > Advanced Constraints > regular Problem pb = new Problem(); IntDomainVar[] vars = new IntDomainVar[6]; for (inti = 0; i < vars.length; i++) { vars[i] = pb.makeEnumIntVar("v" + i, 0, 5); } // Build the list of transitions of the DFA List<Transition> t = new LinkedList<Transition>(); t.add(new Transition(0, 1, 1)); t.add(new Transition(1, 1, 2)); t.add(new Transition(2, 1, 3)); t.add(new Transition(3, 3, 0)); t.add(new Transition(0, 3, 0)); // Two final states: 0, 3 List<Integer> fs = new LinkedList<Integer>(); fs.add(0); fs.add(3); DFA auto = new DFA(t, fs, 6); // Build the DFA pb.post(pb.regular(vars , auto)); // post the constraint

  29. Integer Vars > Advanced Constraints > regular • Can be used as a GAC algorithm for a list of feasible or infeasible tuples • Can be more efficient than a standard GAC algorithm if the DFA is compact

  30. Integer Vars > Advanced Constraints > regular • AllEqual constraint using the regular constraint Problem pb = new Problem(); IntDomainVar v1 = pb.makeEnumIntVar("v1", 1, 4); IntDomainVar v2 = pb.makeEnumIntVar("v2", 1, 4); IntDomainVar v3 = pb.makeEnumIntVar("v3", 1, 4); //add some allowed tuples (here, the tuples define an allEqual constraint) List<int[]> tuples = new LinkedList<int[]>(); tuples.add(new int[]{1, 1, 1}); tuples.add(new int[]{2, 2, 2}); tuples.add(new int[]{3, 3, 3}); tuples.add(new int[]{4, 4, 4}); // post the constraint pb.post(pb.regular(new IntDomainVar[]{v1, v2, v3},tuples));

  31. Integer Vars > Boolean Composition of Constraints var1 var2 • If Only If • If Then c1 [2..5] [1..10] • And • Or • Implies c2 [-4..8] [1..10] var3 [5..10] c3 var5exp var4 IntDomainVar var1 = prob.makeEnumIntVar(“var1”, 2, 5); IntDomainVar var2 = prob.makeEnumIntVar(“var2”, 1, 10); IntDomainVar var3 = prob.makeEnumIntVar(“var3”, 5, 10); IntDomainVar var4 = prob.makeEnumIntVar(“var4”, 1, 10); Constraint c1 = prob.gt(var2,var1); Constraint c2 = prob.leq(var1,var3); IntExp var5Exp = prob.minus(var4, var1); Constraint c3 = prob.neq(var5Exp,var3); Constraint c4 = prob.or(prob.lt(var2,var3),prob.gt(var5Exp,0)); prob.post(c1); prob.post(c2); prob.post(c3); prob.post(c4);

  32. 2. Constraints on Set Variables • member • notMember • setDisjoint • eqCard • …

  33. 2a. Mixed Constraints (Set and Integer) • member • notMember • setDisjoint • eqCard • … (Provides supports for integer variables as set values)

  34. 3. Constraints on Real Variables y2 * (1 + z2) + z * (z - 24 * y) = -13 x2 * (1 + y2) + y * (y - 24 * x) = -13 z2 * (1 + x2) + x * (x - 24 * z) = -13 RealVar x = pb.makeRealVar("x"); RealVar y = pb.makeRealVar("y", -1.0e8, 1.0e8); RealVar z = pb.makeRealVar("z", -1.0e8, 1.0e8); RealExp exp1 = pb.plus(pb.mult(pb.power(y, 2), pb.plus(pb.cst(1.0), pb.power(z, 2))), pb.mult(z, pb.minus(z, pb.mult(pb.cst(24), y)))); … Equation eq1 = (Equation) pb.eq(exp1, pb.cst(-13)); eq1.addBoxedVar(y); eq1.addBoxedVar(z); … pb.post(eq1); pb.post(eq2); pb.post(eq3);

  35. 4. User-Defined Constraints • Useful when the basic propagation algorithms are not efficient enough to propagate the constraint • Abstract classes are available to support management of • the constraint network and • constraint propagation (for Integer and Set constraints)

  36. Outline • Background & introduction • Domain types • Constraints and Constraint Propagation • Search & Branching • How we use Chocoin.. • Java Pathfinder, a static analysis tool for Java programs

  37. Constraint Propagation • Choco uses a reactive approach to propagate constraints • Events are generated on variables • Variables “wake up” their constraints • Which generates new events • Propagate immediately • Add event to a queue

  38. Constraint Propagation • Events on finite domains • INCINF: domain lower-bound on variable v is increased from b to a. • DECSUP: domain upper-bound on variable v is decreased from b to a. • INSTANTIATE: domain of v is reduced to {a} • REMOVAL: the value a is removed from the domain of v

  39. Constraint Propagation • DFS vs. BFS processing of constraints • DFS: preemptive propagation of child events • BFS: propagation of events by generations (propagate root event, then children, then grandchildren, etc.) • Choco policy • INCINF & DECSUP: BFS (common FIFO queue) • REMOVAL events: FIFO queue • INSTANTIATE events: DFS (highest priority)

  40. Outline • Background & introduction • Domain types • Constraints and constraint propagation • Search & branching • How we use Chocoin.. • Java Pathfinder, a static analysis tool for Java programs

  41. Search • One (First) solution or all solutions • Optimization • Create a new variable corresponding to the cost of a solution (‘cost variable’) • Generate a constraint • representing the objective function and • relating the variables in the CSP to the ‘cost variable’ • Value of ‘cost variable’ is computed from the partial/complete assignment using the objective function • Values of ‘cost variable’ is then maximized/minimized • Restart parameter restarts the search after a solution is found or backtracks from current solution

  42. Limiting the Search • Bound the search based on • Time • Number of nodes visited • User-defined criterion (e.g., depth bound)

  43. Branching • Variable/value ordering • User-defined branching • Branching by posting constraints • Limited Discrepancy Search • Limited-Depth First Search

  44. Branching > Over var/val • Defaults • Variable ordering: Least Domain • Value ordering: lexicographical increasing order • Also available • Most constrained (deg) • Domain over Degree (dom/deg) • Random • User-defined heuristics

  45. Branching > User-Defined Branching • Beyond var/val ordering • User defines branching alternatives • Search proceeds down the first alternative, then moves to the next one, etc. • Special case: dichotomic branching • Dichotomic • Branches over a variable’s domain, splitting it in half • Left branch, updating upper bound • Right branch, updating lower bound

  46. Branching > By Posting Constraints • One way to do ‘user-defined’ branching is to explicitly split the domain of a given variable • Another way is to add a new constraint whose effect to split the domain • Example: dichotomic branching • Divide in half • Add constraint for xmiddle point and x< middle point

  47. Branching > Other • Limited Discrepancy Search • Limited Depth First Search • Choose a given depth • Allow backtracking as long as depth of partial solution is smaller than threshold • When depth limit is reached • Solver branches according to the heuristic • Without backtracking

  48. Outline • Background & introduction • Domain types • Constraints and Constraint Propagation • Search & Branching • How we use Chocoin.. • Java Pathfinder, a static analysis tool for Java programs

  49. My experience with Choco • Use in Java Pathfinder (JPF) • To support software development • Test case generation • Error detection (e.g., check for unhandled exceptions) • Check path conditions (specified as conjunctions of constraints) during symbolic execution • Check for path feasibility

  50. Terminology • Static analysis • Symbolic execution • Path condition • Test-case generation

More Related