Introduction to Constraint Programming Kris Kuchcinski kkuida liu
- Slides: 31
Introduction to Constraint Programming Kris Kuchcinski kku@ida. liu. se 9/25/2020 1
Programming with Constraints “Constraint programming represents one of the closest approaches computer science has yet made to the Holy Grail of programming: the user states the problem, the computer solves it. ” Eugene C. Freuder CONSTRAINTS, April 1997 9/25/2020 2
Programming with Constraints “Were you to ask me which programming paradigm is likely to gain most in commercial significance over the next 5 years I’d have to pick Constrained Logic Programming (CLP), even though it’s perhaps currently one of the least known and understood” Dick Pountain BYTE, February 1995 9/25/2020 3
Course organization 9/25/2020 4
Course organization (cont’d) 9/25/2020 5
Course organization (cont’d) z Three obligatory course assignments with the following deadlines: y 25 March y 20 April y 18 May z Course credit points 4 z Possibility for additional project and up to 6 credit points 9/25/2020 6
A simple definition Constraint programming is the study of computational systems based on constraints. The idea of constraint programming is to solve problems by exploring constraints which must be satisfied by the solution. 9/25/2020 7
Different constraint systems z Real/rational constraints- CLP(R), CLP(Q) y CLP(R), Sicstus, CHIP z Finite domains constraints- CLP(FD) y Sicstus, CHIP z Boolean constraints- CLP(B) y Sicstus, CHIP z Interval constraints- CLP(I) y CLP(BNR), Numerica 9/25/2020 8
The programming paradigm Logic programming Constraint satisfaction/solving CLP Optimisation 9/25/2020 9
Logic programming z Logic for problem description z Declarative description style z Problem description separated from its solving z Unification z Lists and recursion z Standard backtracking z Constraint programming does not need to use LP !!! 9/25/2020 10
Constraint satisfaction/solving z Set of variables and constraints which limit the values that can be assigned to the constraint variables z Constraint propagation methods z “Encapsulation” of specific knowledge from mathematics, geometry, graph theory and operational research 9/25/2020 11
Optimization z Finding a solution which satisfies constraints and minimizes/maximizes objective function z Different types y combinatorial optimization of discrete (finite domain) variables y linear optimization for continuous variables 9/25/2020 12
Examples z DC circuit using real constraints z Digital circuits synthesis and verification using binary constraints z Allocation, scheduling and binding in high-level synthesis using finite domain constraints 9/25/2020 13
Analysis of DC circuit CLP(R) I 5 I 2 I 3 Is I 8 V I 1 I 9 I 4 R 1 I 6 I 7 9/25/2020 Is - I 1 - I 2 - I 8 = 0, I 1 + I 7 - Is = 0, I 2 + I 3 - I 5 = 0, I 8 - I 3 - I 4 - I 9 = 0, I 4 + I 6 - I 7 = 0, I 5 - I 6 + I 9 = 0, R 1*I 1 = V, 2*I 2 - 3*I 3 - 8*I 8 = 0, 3*I 3 + 5*I 5 -9*I 9 = 0, 6*I 6 - 4*I 4 +9*I 9 =0, 4*I 4 - I 1 + 7*I 7 +8*I 8 = 0 14
Analysis of DC circuit CLP(R) dc([Is, I 1, Is - I 1 + I 7 I 2 + I 3 I 8 - I 3 I 4 + I 6 I 5 - I 6 + (cont’d) I 2, I 3, I 4, I 5, I 6, I 7, I 8]) : I 2 - I 8 = 0, Is = 0, I 5 = 0, I 4 - I 9 = 0, I 7 = 0, I 9 = 0, R 1*I 1 = V, 2*I 2 3*I 3 6*I 6 4*I 4 9/25/2020 + - 3*I 3 5*I 5 4*I 4 I 1 + - 8*I 8 - 9*I 9 + 9*I 9 7*I 7 + = 0, =0, 8*I 8 = 0. 15
Analysis of DC circuit CLP(R) (cont’d) V = 10, R 1 = 1 V= 10, R 1=3 V = 10, R 1=? I 8 I 7 I 6 I 5 I 4 I 3 I 2 I 1 IS 10 = = = = = 0. 259209 0. 828299 0. 296239 0. 25726 0. 53206 -0. 31183 0. 56909 10 10. 8283 = = = = = 0. 086403 0. 2761 0. 098746 0. 085753 0. 177353 -0. 103943 0. 189697 3. 33333 3. 60943 = = = = = 3. 19549*I 8 1. 14286*I 8 0. 992481*I 8 2. 05263*I 8 -1. 20301*I 8 2. 19549*I 8 38. 5789*I 8 41. 7744*I 8 I 1 * R 1 *** Maybe 9/25/2020 16
Analysis of DC circuit CLP(I) dc([Is, I 1, I 2, I 3, I 4, I 5, I 6, I 7, I 8]) Is>= -100, Is<=100, I 1>= -100, I 2<=100, I 3>= -100, I 4<=100, I 5>= -100, I 6<=100, I 7>= -100, I 8<=100, I 9>= -100, : I 1<=100, I 3<=100, I 5<=100, I 7<=100, I 9<=100, Is-I 1 -I 2 -I 8=: =0, I 2+I 3 -I 5=: =0, I 4+I 6 -I 7=: =0, I 1+I 7 -Is=: =0, I 8 -I 3 -I 4 -I 9=: =0, I 5 -I 6+I 9=: =0, R>=1, R<=3, R*I 1=: =10, 2*I 2 -3*I 3 -8*I 8=: =0, 6*I 6 -4*I 4+9*I 9=: =0, 3*I 3+5*I 5 -9*I 9=: =0, 4*I 4 -I 1+7*I 7+8*I 8=: =0. 9/25/2020 17
Analysis of DC circuit CLP(I) (cont’d) ? - dc([Is, I 1, I 2, I 3, I 4, I 5, I 6, I 7, I 8]). Is I 1 I 2 I 3 I 4 I 5 I 6 I 7 I 8 in in in 9/25/2020 (3. 6094328590907638, 10. 8282985772764136) (3. 333333330, 10. 00000000] (0. 1896966153445871, 0. 5690898460339618) (-0. 3118300526213467, -0. 1039433508737487) (0. 1773533424283491, 0. 5320600272851572) (0. 0857532644708472, 0. 2572597934126064) (0. 0987461833300698, 0. 2962385499902706) (0. 2760995257584099, 0. 8282985772754369) (0. 0864029104138029, 0. 2592087312414950) 18
Digital Circuits- full adder CLP(B) adder(_, A, B, C, SUM, CARRY) : sat(SUM =: = card([1, 3], [A, B, C])), sat(CARRY =: = card([2, 3], [A, B, C])). 9/25/2020 19
Digital Circuits- full adder CLP(B) (cont’d) | ? - adder(_, a, b, c, SUM, CARRY). sat(SUM=: =a#b#c), sat(CARRY=: =b*a#c*b). 9/25/2020 20
Digital Circuits- full adder CLP(B) (cont’d) z N-transistor model ntrans(_, B, X, Y) : sat((B * (X=: =Y)) + (B=: =0)). z P-transistor model ptrans(_, B, X, Y) : sat((~B * (X=: =Y)) + (B=: =1)). X X B B Y 9/25/2020 Y 21
Digital Circuits- full adder CLP(B) (cont’d) full_adder(_, A, B, C, SUM, CARRY) : carry_part(_, A, B, C, NCA, CARRY), sum_part(_, A, B, C, NCA, SUM) : ptrans(_, NCA, T 1, 1), ptrans(_, C, 1, T 5), ptrans(_, B, T 1, T 5), ptrans(_, A, T 1, T 2), ptrans(_, NCA, T 5, T 2), ptrans(_, T 2, 1, SUM), ntrans(_, A, T 2, T 3), ntrans(_, NCA, T 2, T 6), ntrans(_, T 2, SUM, 0), ntrans(_, B, T 3, T 6), ntrans(_, NCA, T 3, 0), ntrans(_, C, T 6, 0). carry_part(_, A, B, C, NCA, CA) : ptrans(_, A, T 1, 1), ptrans(_, B, T 1, 1), ptrans(_, A, T 2, 1), ptrans(_, C, T 1, NCA), ptrans(_, B, T 2, NCA), ptrans(_, NCA, 1, CA), ntrans(_, C, NCA, T 3), ntrans(_, B, NCA, T 4), ntrans(_, NCA, 0), ntrans(_, A, T 3, 0), ntrans(_, B, T 3, 0), ntrans(_, A, T 4, 0). 9/25/2020 22
Digital Circuits- full adder CLP(B) (cont’d) | ? - full_adder(_, a, b, c, SUM, CARRY). sat(SUM=: =a#b#c), sat(CARRY=: =b*a#c*b). 9/25/2020 23
High-level synthesis CLP(FD) 3 x u dx 3 * * y u dx x * u * * + 3 x u dx 3 y u dx x + u * dx - data-flow graph 9/25/2020 < * * y * - + u 1 a x 1 < c dx * * a x 1 y 1 - + * y dx dx u 1 c y 1 scheduled data-flow graph 24
High-level synthesis CLP(FD) Op 1 (cont’d) Op 2 T 1 + D 1 #=< T 3, T 2 + D 2 #=< T 3, T 3 + D 3 #=< T 4, Op 4 Op 3 T 4 : : 0. . 50, D 4 : : 3. . 4, R 4 : : 0. . 1 9/25/2020 (T 1 + D 1 #=< T 2 + D 2 #=< T 1 R 1 #= R 2). 25
High-level synthesis CLP(FD) (cont’d) Scheduled design 9/25/2020 26
Methods for constraint solving z CLP(R) y Gauss-Jordan elimination y simplex z CLP(I) y interval narrowing, box consistency, y Gauss-Seidel elimination, interval Newton method, z CLP(B) y for example, operations on BDD’s z CLP(FD) y arc, node and path consistency methods y constraint propagation (forward checking, look-ahead), y branch-and-bound 9/25/2020 27
Constraint programming limitations z Many addressed problems in the area of FD constraints are NP-complete (combinatorial problems, such as scheduling, traveling salesman) y search for (optimal) solution has exponential complexity in general case y constraints and their propagation methods try to reduce the search space y possible heuristic search methods z Boolean satisfaction problem is NP-complete z Linear programming has polynomial time solving algorithms (but in many practical cases it has too long execution times) 9/25/2020 28
An Example 9/25/2020 29
An Example (cont’d) 9/25/2020 30
Web resources z Constraints archive http: //www. cs. unh. edu/ccc/archive z Guide to constraints programming http: //kti. ms. mff. cuni. cz/~bartak/constraints z Sicstus manual http: //www. sics. se/isl/sicstus_toc. html z CHIP documentation file: /sw/chip-5. 1/chip. htm z Prolog systems at IDA y http: //www. ida. liu. se/labs/logpro/lpsw/ 9/25/2020 31
- Alex liu cecilia liu
- Líu líu lo lo ta ca hát say sưa
- Constraint programming tutorial
- Constraint programming python
- Excel sensitivity report
- Alldifferent constraint excel solver
- Kris fernando
- Kris kmitl
- Kris pister
- överdeterminerad
- Kris francken
- Kris miner
- Kris k hauser
- Kris stas
- Wade kerrigan husch blackwell
- Kris claes
- Kris kmitl
- Wui placard
- Kristofer pister
- Kris kmitl
- Kris wui
- Kris kowdley
- Guy mareels
- Nyorienteringsfas
- Kris brewer
- Kris krider
- Kris caldwell
- Paul de sutter gynaecoloog
- Kris de volder
- Kris hildrum
- Kris carver
- Kris fernando