1 / 48

CLP Principles

CLP Principles. H. Simonis COSYTEC SA 4, rue Jean Rostand F-91893 Orsay Cedex helmut@cosytec.fr. Outline. Background on CLP Simple Examples Global Constraints Search. What is common among. the production of Mirage 2000 fighter aircraft

jessieb
Télécharger la présentation

CLP Principles

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. CLP Principles H. Simonis COSYTEC SA 4, rue Jean Rostand F-91893 Orsay Cedex helmut@cosytec.fr CHIP Overview

  2. Outline • Background on CLP • Simple Examples • Global Constraints • Search CHIP Overview

  3. What is common among • the production of Mirage 2000 fighter aircraft • the personnel planning for the guards in all French jails • the production of Belgian chocolates • the selection of the music programme of a Pop music radio station • the design of advanced signal processing chips • the print engine controller in Xerox copiers They all use constraint programming to solve their problem CHIP Overview

  4. Constraint Programming - in a nutshell • Declarative description of problems with • Variables which range over (finite) sets of values • Constraints over subsets of variables which restrict possible value combinations • A solution is a value assignment which satisfies all constraints • Constraint propagation/reasoning • Removing inconsistent values for variables • Detect failure if constraint can not be satisfied • Interaction of constraints via shared variables • Incomplete • Search • User controlled assignment of values to variables • Each step triggers constraint propagation • Different domains require/allow different methods CHIP Overview

  5. Techniques behind CLP Predicate logic Unification Non-determinism Logic Programming Constraint propagation Consistency checking Demons CLP tools Artificial Intelligence Operations Research Simplex & Linear programming Integer programming Implicit enumeration Branch & bound Flow algorithms Scheduling methods Graph theory Combinatorics Spatial data structures Equation solving methods Mathematics CHIP Overview

  6. Example: Problem • Solve the cryptarithmetic puzzle • Each character represents a digit • Different characters have different values • Numbers do not start with 0 SEND +MORE ------ MONEY CHIP Overview

  7. Example: Model top:- [S, E, N, D, M, O, R, Y] :: 0..9, alldifferent([S, E, N, D, M, O, R, Y]), S \= 0, M \= 0, 1000 * S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E = 10000 *M + 1000*O + 100*N + 10*E + Y, labeling([S, E, N, D, M, O, R, Y]). Variable definition Constraints between variables Search routine CHIP Overview

  8. Constraint reasoning • Simplification (each variable occurs once) • 1000*S in {1..9}+ 91*E in {0..9} + D in {0..9} + 10*R in {0..9} = 9000*M in {1..9} +900*O in {0..9} + 90*N in {0..9} + Y in {0..9} • Evaluation lhs/rhs • lhs in 1000..9918 • rhs in 9000..89919 • Merging of sides • constraint in 9000..9918 CHIP Overview

  9. Reasoning • Consequence • M = 1 • S = 9 • O in {0..1} • Propagation of alldifferent • O = 0 CHIP Overview

  10. Reasoning • Re-evaluation of equality • 1000*9+ 91*E in {2..8} + D in {2..8} + 10*R in {2..8} = 9000*1 +900*0 + 90*N in {2..8} + Y in {2..8} • lhs in 9204..9816, rhs in 9182..9728, eq in 9204..9728 • N \= 2, E \= 8 • Re-evaluation, ... • Continuing the process gives • M = 1, S = 9, O = 0, E in 4..7, N in 5..8, D in 2..8, R in 2..8, Y in 2..8 CHIP Overview

  11. Starting labeling • First variable is E, first value is 4 • Propagation on equality gives • 1000*9+ 91*4 + D in {2..8} + 10*R in {2..8} = 9000*1 +900*0 + 90*N in {5..8} + Y in {2..8} • results in N = 5, D = 8, R = 8, Y = 2 • Propagation on alldifferent fails • Backtracking to last choice CHIP Overview

  12. First alternative • Next value for E is 5 • Propagation on equality gives • 1000*9+ 91*5 + D in {2..8} + 10*R in {2..8} = 9000*1 +900*0 + 90*N in {5..8} + Y in {2..8} • results in N = 6, R = 8 • Constraint propagation (alldifferent + equality) gives • D = 7, Y = 2 CHIP Overview

  13. Points to remember • Even small problems create complex propagation chains • The same constraint can be woken several times in the same propagation loop • The order in which constraints are woken has an influence on the speed • Propagation continues until no further information is obtained • Search (under user control) required to find ground solution • Basic structure of finite domain program always the same • define variables • define constraints • user defined search • typical: pick variable and find value CHIP Overview

  14. Example 2: The N-queens problem • Place queens on a NxN chessboard so that they do not attack each other • The classical constraints example • Not a hard problem: possible to construct generic solutions • Used here show the impact of the search routine CHIP Overview

  15. Model run(N):- length(L, N), L :: 1..N, create_dif(L, 1, N, L1, L2), alldifferent(L), alldifferent(L1), alldifferent(L2), labeling(L). create_dif([], N, M, [], []). create_dif([H|T], N, M, [H+N|R], [H+M|S]):- N1 is N+1, M1 is M-1, create_dif(T, N1, M1, R, S). CHIP Overview

  16. Naïve search labeling([]). labeling([X|Y]) :- indomain(X), labeling(Y). CHIP Overview

  17. Results first hard instance 22 CHIP Overview

  18. Searchtree (N=22) CHIP Overview

  19. First fail label([]). label([X|Y]) :- delete(Var,[X|Y],Rest,0,first_fail), indomain(Var), label(Rest). CHIP Overview

  20. Results First hard instance 80 CHIP Overview

  21. Searchtree (N=80) CHIP Overview

  22. run(N):- length(L, N), L :: 1..N, create_dif(L, 1, N, L1, L2), alldifferent(L), alldifferent(L1), alldifferent(L2), reorder(L, LL), label(LL). reorder(L, L1):- front_rear(L, L, [], F, R), merge_it(F, R, L1). front_rear(R, [], F, F, R). front_rear(R, [_], F, F, R). front_rear([H|T], [_, _|Q], F, Fend, Rear):- front_rear(T, Q, [H|F], Fend, Rear). merge_it([], [], []). merge_it([], [A], [A]). merge_it([A|A1], [B|B1], [A, B|C1]):- merge_it(A1, B1, C1). label([]). label([X|Y]) :- delete(Var, [X|Y], Rest, 0, first_fail), indomain(Var, middle), label(Rest). Heuristic reordering CHIP Overview

  23. Results Exceptional hard instances 108, 168 CHIP Overview

  24. Searchtree (N=108) CHIP Overview

  25. Credit based partial search label(L):- length(L,K), Credit is K*K, credit(L, Credit, K, choose, choice, 5, part(1,2)). choose(Term, LTerm, RTerm):- delete(Term, LTerm, RTerm, 0,first_fail). choice(X):- indomain(X,middle). CHIP Overview

  26. Results runs up to several thousand queens with less than 10 backtracking steps CHIP Overview

  27. Searchtree (N=108) CHIP Overview

  28. Global Constraints CHIP Overview

  29. Need for global constraints 1 X X in {2,3} Y 2 Y in {2,3}  U in {1,2,3,4} Z 3 Z in {1,3} U 4 local reasoning, no action global reasoning, detect implications by bi-partite matching CHIP Overview

  30. Global constraints • Work on sets of variables • Global conditions, not local constraints • Semantic methods • Operations Research • Spatial algorithms • Graph theory • Network flows • Building blocks (high-level constraint primitives) • Multi-purpose • As general as possible • Usable with other constraints • Very strong propagation • Acceptable algorithmic complexity CHIP Overview

  31. Constraint morphology precedence diffn cumulative sequence cycle case among alldifferent setup disjunctive permutation prod/cons \= >=, distance atmost, atleast circuit element Different Order Resource Tour Dependency CHIP Overview

  32. cumulative The Cumulative global constraint • Cumulative constraint • Resource limits over periods of time • Upper/lower limits • Soft/hard limits • Gradual constraint relaxation • Application • Resource restrictive scheduling, producer consumer constraints, disjunctive schedule, manpower constraints, overtime CHIP Overview

  33. Cumulative • Methods • obligatory parts • task intervals • available space • many more (25000 lines of C code) • Concepts • one constraint may be used for different purposes CHIP Overview

  34. diffn The Diffn global constraint • Diffn constraint • non overlapping areas on n-dimensional rectangles • distances between rectangles • limit use of areas • relaxation • Application • layout, packing, resource assignment, setup, distribution planning, time-tabling CHIP Overview

  35. Diffn • Methods • obligatory parts • region intervals • max flow on assignment • available space • many others (32000 lines of C code) • Concepts CHIP Overview

  36. cycle The Cycle global constraint • Cycle constraint • Finds cycles in directed graphs with minimal cost • Assign resources, find compatible start dates • Applications • Tour planning, personnel rotation, distribution problems, production sequencing CHIP Overview

  37. Cycle • Methods • connected components • bi-partite matching • non-oriented graph concepts • shortest/longest paths • micro-rules • many others (38000 lines of C code) • Concepts CHIP Overview

  38. among 1 of 3 2 of 5 1 of 6 The Among global constraint • Among constraint • How often do values occur in (sub)sequences • based on counting arguments • interaction between sequences • Applications • production sequencing, time tabling, coloring problems, set covering CHIP Overview

  39. precedence The Precedence global constraint • Precedence constraint • Combine resource constraints and precedence networks • Reasoning on latency (position in network) • Co-operation between multiple resources • Applications • resource restricted scheduling, channel routing, frequency allocation CHIP Overview

  40. The Sequence global constraint sequence <= 40 hours 2 days off after day with more than 10 hours, next day must have less than 8 hours • Sequence constraint • constraints on pattern inside sequences • combinatorial pattern matching • counting arguments • Applications • Time tabling, personnel assignment, • work rules, scheduling with daily working time limits CHIP Overview

  41. cycle cumulative diffn The power of global constraints plan schedule • Multi-functional tools • Building blocks assign CHIP Overview

  42. Controlling Search CHIP Overview

  43. Search tree visualization • Generation of search tree representation at run-time • Shows parent child relation, failed sub-trees, success nodes • In examples here • leaf failure nodes suppressed • failure trees not collapsed • Interface a set of simple meta-call predicates • Supported by work in DISCIPL Esprit project • Declarative debugging • Visualization of constraint programming results • Understand behaviour of different strategies CHIP Overview

  44. Search tree tool Menubar Panel Tree view Other Views, here domain state Info Area CHIP Overview

  45. Search strategies • How to find values for variables • Central to application of strategies/heuristics • Chronological backtracking • explores full search tree • complete • often stuck in one part of tree • Partial search meta-heuristics • different search methods • not complete • polynomial complexity • used to explore different parts of search tree in systematic fashion • uses normal variable and value selection criteria CHIP Overview

  46. Credit based search • Systematic search at top of tree • Limited amount of backtracking = credit • typical N, N2, N3 • Distribute credit to children in different ways • preference on first child • equal credit to all children • If credit runs out, perform deterministic search • Allow small amount of local search to overcome problems CHIP Overview

  47. Example of tree search credit([X1..X10],8, 10, my_delete, my_indomain,4,part(1,2)), CHIP Overview

  48. Credit Example CHIP Overview

More Related