Download presentation
Presentation is loading. Please wait.
Published byIsiah Morie Modified over 9 years ago
1
Constraint Processing and Programming Introductory Exemple Javier Larrosa
2
Combinatorial Problem Solving Science and Engineering are full of Combinatorial Problems Solving algorithms are exponentially expensive A lot of tricks can be applied to improve performance Naive Approach For each problem, design and implement an efficient algorithm
3
Place numbers 1 through 8 on nodes each number appears exactly once no connected nodes have consecutive numbers ? ? ? ? ? ? ?? Note the graph symmetry Acknowledgement: Patrick Prosser
4
Heuristic Search Which nodes are hardest to number? ? ? ? ? ? ? ?? Guess a value, but be prepared to backtrack
5
Heuristic Search ? ? ? ? ? ? ?? Which nodes are hardest to number?
6
Heuristic Search Which are the least constraining values to use? ? ? ? ? ? ? ?? Values 1 & 8
7
Heuristic Search Symmetry means we don’t need to consider: 8 1 ? 1 ? ? 8 ? ??
8
Inference/propagation We can now eliminate many values for other nodes ? 1 ? ? 8 ? ?? {1,2,3,4,5,6,7,8}
9
Inference/propagation By symmetry ? 1 ? ? 8 ? ?? {3,4,5,6}
10
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6} {1,2,3,4,5,6,7,8}
11
Inference/propagation By symmetry ? 1 ? ? 8 ? ?? {3,4,5,6}
12
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6} {3,4,5,6,7}{2,3,4,5,6}
13
Inference/propagation ? 1 ? ? 8 ? 27 {3,4,5,6}
14
Inference/propagation ? 1 ? ? 8 ? 27 {3,4,5,6} And propagate
15
Inference/propagation ? 1 ? ? 8 ? 27 {3,4,5} {4,5,6}
16
Inference/propagation 3 1 ? ? 8 ? 27 {3,4,5} {4,5,6} By symmetry
17
Inference/propagation 3 1 ? ? 8 ? 27 {3,4,5} {4,5,6} And propagate
18
Inference/propagation 3 1 ? ? 8 ? 27 {4,5} {5,6} {4,5,6} More propagation?
19
Inference/propagation 3 1 4 5 8 6 27 A solution
20
The Declarative Approach to Combinatorial Problem Solving Declarative Approach 1. Model the problem using a well-defined language 2. Solve the problem using general-purpose techniques Constraint Programming and SAT solving follow this approach.
21
Constraint programming methodology Model problem Solve model Verify and analyze solution specify in terms of constraints on acceptable solutions define/choose constraint model: variables, domains, constraints define/choose algorithm define/choose heuristics
22
Constraint programming methodology Model problem Solve model Verify and analyze solution specify in terms of constraints on acceptable solutions define/choose constraint model: variables, domains, constraints define/choose algorithm define/choose heuristics Constraint Satisfaction Problem
23
Constraint satisfaction problem A CSP is defined by a set of variables a domain of values for each variable a set of constraints between variables A solution is an assignment of a value to each variable that satisfies the constraints
24
Given a CSP Determine whether it has a solution or not Find any solution Find all solutions Find an optimal solution, given some cost function
25
Constraint model for puzzle variables v 1, …, v 8 domains {1, …, 8} constraints | v 1 – v 2 | 1 | v 1 – v 3 | 1 … | v 7 – v 8 | 1 alldifferent(v 1, …, v 8 ) ? ? ? ? ? ? ??
26
Example: instruction scheduling (a + b) + c Given a basic-block of code and a single-issue pipelined processor, find the minimum schedule
27
Example: evaluate (a + b) + c instructions A r1 a B r2 b C r3 c D r1 r1 + r2 E r1 r1 + r3 33 3 1 AB DC E dependency DAG
28
Example: evaluate (a + b) + c non-optimal schedule Ar1 a Br2 b nop Dr1 r1 + r2 Cr3 c nop Er1 r1 + r3 33 3 1 AB DC E dependency DAG
29
Example: evaluate (a + b) + c optimal schedule Ar1 a Br2 b Cr3 c nop Dr1 r1 + r2 Er1 r1 + r3 33 3 1 AB DC E dependency DAG
30
Constraint model variables A, B, C, D, E domains {1, …, m} constraints D A + 3 D B + 3 E C + 3 E D + 1 alldifferent(A, B, C, D, E) 33 3 1 AB DC E dependency DAG
31
Example: Graph coloring Given k colors, does there exist a coloring of the nodes such that adjacent nodes are assigned different colors
32
Example: 3-coloring variables: v 1, v 2, v 3, v 4, v 5 domains: {1, 2, 3} constraints: v i v j if v i and v j are adjacent v2v2 v3v3 v1v1 v5v5 v4v4
33
Example: 3-coloring A solution v 1 1 v 2 2 v 3 2 v 4 1 v 5 3 v2v2 v3v3 v1v1 v5v5 v4v4
34
Example: n-queens Place n-queens on an n n board so that no pair of queens attacks each other
35
Constraint model 4 3 2 1 x1 x1 x2x2 x3 x3 x4 x4 variables: x 1, x 2, x 3, x 4 domains: {1, 2, 3, 4} constraints: x i x j and | x i - x j | | i - j |
36
Example: 4-queens A solution x 1 2 x 2 4 x 3 1 x 4 3 Q Q Q Q x1 x1 x2x2 x3 x3 x4 x4 4 3 2 1
37
Constraint programming methodology Model problem Solve model Verify and analyze solution specify in terms of constraints on acceptable solutions define/choose constraint model: variables, domains, constraints define/choose algorithm define/choose heuristics
38
Constraint programming methodology Model problem Solve model Verify and analyze solution specify in terms of constraints on acceptable solutions define/choose constraint model: variables, domains, constraints define/choose algorithm define/choose heuristics
39
Application areas Paradigm of choice for many hard combinatorial problems scheduling planning vehicle routing configuration bioinformatics …
40
Commercial applications
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.