Constraint Programming 2001 Edition Jan Maluszynski and Ulf Nilsson TCSLAB, LiU {janma, ulfni}@ida.liu.se http://www.ida.liu.se/~ulfni/cp2001 5/31/2016 1 Course organization Date 11 Sep 18 Sep 25 Sep 2 Oct 9 Oct 16 Oct 23 Oct 5/31/2016 Content Organization, motivation, limitations, etc. Basics (Ch 1+2) Finite domain constraints (Ch 3) Logic programming (optional) (Ch 4) Modelling with FD-constraints (Ch 5, 8) Interval constraints Available systems Lect UN JM JM UN UN JM PP 2 Course organization (cont’d) Date 30 Oct 6 Nov 13 Nov 20 Nov 27 Nov 5/31/2016 Content Constraints for system design Constraint Handling Rules Survey of HAL Reserve Solutions to exercises Lect KK ?? ?? --- 3 Course organization (cont) Obligatory course assignments (23 Oct) with deadline 20 Nov, and examination 27 Nov Course credit points 4 Literature: K. Marriott and P. Stuckey Programming with Constraints: An Introduction MIT Press, 1998. + handouts and on-line manuals 5/31/2016 4 A simple definition Constraint programming is the study of computational systems based on constraints. Constraints are roughly systems of equations, inequations and disequations over some algebraic structure. The idea of constraint programming is to solve problems by encoding the problem as a set of constraints and exploring solutions to the constraints. 5/31/2016 5 Typical problem Processes A-D may start at times 1,2,3,4,5,6,7 Process A uses 3 resources during 2sec Process B uses 1 resource during 4sec Process C uses 2 resources during 1sec Process D uses 2 resources during 1sec There are 4 resources Process A must finish before C can start When are A, B, C, D earliest finished? 5/31/2016 6 Overview Constraints, basics, operations, domains Focus on finite domains, intervals Constraint logic programming Modeling and applications Systems CLP-systems Systems for defining constraints CHR, HAL 5/31/2016 7 Constraints A constraint problem consists of a set of problem variables ranging over some domain and a set of constraints restricting the values that may be assigned to the variables. Example: x in {1,2,3}, y in {2,3,4,5}, 2x = y Examples of domains: Reals/rationals, intervals, finite domains, Booleans, sets, monoids (strings) etc 5/31/2016 8 Methods for constraint solving Reals/rational constraints Gauss-Jordan elimination + Simplex Real/Rational intervals interval narrowing, box consistency, Gauss-Seidel elimination, interval Newton method, Booleans for example, operations on BDD’s Finite domains arc, node and path consistency methods constraint propagation (forward checking, look-ahead) 5/31/2016 9 Optimization Finding a solution which satisfies constraints and minimizes/maximizes objective function Different types combinatorial optimization of discrete (finite domain) variables linear optimization for continuous variables 5/31/2016 10 Different constraint systems Real/rational constraints: CLP(R), CLP(Q) CLP(R), Sicstus Prolog, CHIP Finite domains constraints: CLP(FD) Sicstus Prolog, CHIP Boolean constraints: CLP(B) Sicstus Prolog, CHIP Interval constraints: CLP(I) CLP(BNR), Numerica, Prolog IV 5/31/2016 11 Systems discussed in the course SICStus Prolog Chip 5.2 Prolog IV CHR HAL 5/31/2016 12 The programming paradigm Logic programming Constraint satisfaction/solving CLP Optimization 5/31/2016 13 Logic programming Logic (relations) for problem description Declarative description style (problem description separated from its solving) Unification (a kind of constraint solving) Builtin search Constraint programming does not need LP !!! 5/31/2016 14 Some applications Spatial and temporal problems Placment and layout Manpower planning Scheduling Resource allocation Configuration management Verification (e.g. correctness, safety+liveness) 5/31/2016 15 Placement/Layout A window contains a number of widgets. As the window is shrinking or growing the widgets have to be repositioned while satisfying certain constraints (e.g. certain widgets must always be visible or must be in a certain relation to other widgets). Given a certain window size, produce a layout that satisfies the constraints. 5/31/2016 16 Scheduling A conference consists of 11 sessions of equal length. The program is to be organized as a sequence of slots, where a slot contains up to 3 parallel sessions: 1. Session 4 must take place before Session 11. 2. Session 5 must take place before Session 10. 3. Session 6 must take place before Session 11. … 8. Session 6 must not be in parallel with 7 and 10. 9. Session 7 must not be in parallel with 8 and 9. 10. Session 8 must not be in parallel with 10. Minimize the number of slots. 5/31/2016 17 Job shop scheduling There are n jobs and m machines. Each job requires execution of a sequence of operations within a time interval, and each operation Oi requires exclusive use of a designated machine Mi for a specied amount of processing time pi. Determine a schedule for production that satisfies the temporal and resource capacity constraints. 5/31/2016 18 Manpower planning Airport Counter Allocation problem: Allocate enough counters and staff (the number depends on the aircraft type) to each flight. The counters are grouped in islands and for each flight all assigned counters have to be in the same island. The staff has working regulations that must be satisfied (breaks etc). 5/31/2016 19 Black-box vs Glass-box solvers Most systems rely on non-extensible, black-box constraint solvers Efficiency unpredictable Hard to debug Some systems facilitate defining new constraints and solvers (glass-box approach) Improved control of propagation and search Examples CHR, HAL, ... Then again, most problems are NP-complete... 5/31/2016 20