Download presentation
Presentation is loading. Please wait.
Published byMeryl Chambers Modified over 9 years ago
1
Constraints and Search Toby Walsh Cork Constraint Computation Centre (4C) tw@4c.ucc.ie Logic & AR Summer School, 2002
2
Outline What is Constraint Computation? –aka Constraint Programming (CP) How do we search for a solution? –Useful not just for constraint programming –But also for theorem proving, …
3
A Puzzle Place numbers 1 through 8 on nodes –Each number appears exactly once ? ? ? ? ? ? ?? –No connected nodes have consecutive numbers You have 8 minutes!
4
Heuristic Search Which nodes are hardest to number? ? ? ? ? ? ? ??
5
Heuristic Search ? ? ? ? ? ? ??
6
? ? ? ? ? ? ?? Which are the least constraining values to use?
7
Heuristic Search ? 1 ? ? 8 ? ?? Values 1 and 8
8
Heuristic Search ? 1 ? ? 8 ? ?? Values 1 and 8 Symmetry means we don’t need to consider: 8 1
9
Inference/propagation ? 1 ? ? 8 ? ?? We can now eliminate many values for other nodes
10
Inference/propagation ? 1 ? ? 8 ? ?? {1,2,3,4,5,6,7,8}
11
Inference/propagation ? 1 ? ? 8 ? ?? {2,3,4,5,6,7}
12
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6}
13
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6} By symmetry {3,4,5,6}
14
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6} {1,2,3,4,5,6,7,8}
15
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6} {2,3,4,5,6,7}
16
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6}
17
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6} By symmetry {3,4,5,6}
18
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6} {3,4,5,6,7} {3,4,5,6} {2,3,4,5,6}
19
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6} {3,4,5,6,7} {3,4,5,6} {2,3,4,5,6} Value 2 and 7 are left in just one variable domain each
20
Inference/propagation ? 1 ? ? 8 ? 27 {3,4,5,6} {3,4,5,6,7} {3,4,5,6} {2,3,4,5,6} And propagate …
21
Inference/propagation ? 1 ? ? 8 ? 27 {3,4,5} {3,4,5,6,7} {3,4,5} {3,4,5,6} {2,3,4,5,6} And propagate …
22
Inference/propagation ? 1 ? ? 8 ? 27 {3,4,5} {3,4,5,6,7} {3,4,5} {4,5,6} {2,3,4,5,6} And propagate …
23
Inference/propagation ? 1 ? ? 8 ? 27 {3,4,5} {4,5,6} Guess a value, but be prepared to backtrack …
24
Inference/propagation 3 1 ? ? 8 ? 27 {3,4,5} {4,5,6} Guess a value, but be prepared to backtrack …
25
Inference/propagation 3 1 ? ? 8 ? 27 {3,4,5} {4,5,6} And propagate …
26
Inference/propagation 3 1 ? ? 8 ? 27 {4,5} {5,6} {4,5,6} And propagate …
27
Inference/propagation 3 1 ? ? 8 ? 27 {4,5} {5,6} {4,5,6} Guess another value …
28
Inference/propagation 3 1 ? 5 8 ? 27 {4,5} {4,5,6} Guess another value …
29
Inference/propagation 3 1 ? 5 8 ? 27 {4,5} {4,5,6} And propagate …
30
Inference/propagation 3 1 ? 5 8 ? 27 {4} {4,6} And propagate …
31
Inference/propagation 3 1 4 5 8 ? 27 {4} {4,6} One node has only a single value left …
32
Inference/propagation 3 1 4 5 8 6 27 {6}
33
Solution 3 1 4 5 8 6 27
34
The Core of Constraint Computation Modelling –Deciding on variables/domains/constraints Heuristic Search Inference/Propagation Symmetry Backtracking
35
A Commercial Reality First-tier software vendors use CP technology
36
Supply chain management The puzzle is actually a hard problem –NP-complete Can apply the same technology to core supply chain management problems –Vehicle routing –Scheduling –Warehouse location
37
Example: Vehicle Routing Depot 10 15 [10 20]
38
Example: Vehicle Routing Depot 10 15 [10 20]
39
Example: Vehicle Routing Depot 10 15 [15 15] [10 20]
40
Example: Vehicle Routing Depot 10 15 [10 20] [20 20] [10 10]
41
Constraint programming Ongoing “dream” of declarative programming –State the constraints –Solver finds a solution Paradigm of choice for many hard combinatorial problems –Scheduling, assignment, routing, …
42
Constraint programming Model problem by specifying constraints on acceptable solutions –define variables and domains –post constraints on these variables Solve model –choose algorithm incremental assignment / backtracking search complete assignments / stochastic search –design heuristics
43
Constraints are everywhere! No meetings before 10am Network traffic < 100 Gbytes/sec PCB width < 21cm Salary > 45k Euros …
44
Constraint satisfaction Constraint satisfaction problem (CSP) is a triple where: –V is set of variables –Each X in V has set of values, D_X Usually assume finite domain {true,false}, {red,blue,green}, [0,10], … –C is set of constraints Goal: find assignment of values to variables to satisfy all the constraints
45
Example CSP Variable, v i for each node Domain of {1, …, 8} Constraints –All values used Alldifferent(v 1 v 2 v 3 v 4 v 5 v 6 v 7 v 8 ) –No consecutive numbers for adjoining nodes |v 1 - v 2 | > 1 |v 1 - v 3 | > 1 … ? ? ? ? ? ? ??
46
Example CSP Course timetabling –Variable for each course X1, X2.. –Domain are possible times for course Wed9am, Fri10am,.. –Constraints: X1 \= Wed9am Capacity constraints: atmost(3,[X1,X2..],Wed9am) Lecturer constraints: alldifferent([X1,X5,…])
47
Constraint optimization CSP + objective function –E.g. objective is Profit = Income - Costs Find assignment of vals to vars that: –Satisfies constraints –Maximizes (minimizes) objective Often solved as sequence of satisfaction problems Profit > 0, Profit > Ans1, Profit > Ans2, …
48
Constraint programming v. Constraint logic programming Constraints declaratively specify problem –Logic programming natural approach Assert constraints, call “labelling” strategy (backtracking search predicate) But can also define constraint satisfaction or optimization within an imperative of functional language Popular toolkits in C++, Java, CAML, …
49
Constraints Constraints are tuples where –S is the scope, [X1,X2, … Xm] list of variables to which constraint applies –R is relation specifying allowed values (goods) Subset of D_X1 x D_X2 x … x D_Xm May be specified intensionally or extensionally
50
Constraints Extensional specification –List of goods (or for tight constraints, nogoods) Intensional specification –X1 =/= X2 –5*X1 + 6*X2 < X3 –alldifferent([X1,X2,X3,X4]), …
51
Constraint tightness Informally, tight constraints admit few tuples –E.g. on 0/1 vars X1 =/= X2 is loose as half tuples satisfy X1+X2+X3+X4+X5 <= 1 is tight as only 5 out of 32 tuples satisfy More formal definition later
52
Binary v non-binary Binary constraint –Scope covers 2 variables –E.g. not-equals constraint: X1 =/= X2. –E.g. ordering constraint: X1 < X2 Non-binary constraint –Scope covers 3 or more variables –E.g. alldifferent(X1,X2,X3). –E.g. tour(X1,X2,X3,X4). “Non-binary constraints” usually do not include unary constraints!
53
Constraint graph Nodes = variables Edge between 2 nodes iff constraint between 2 associated variables –Few constraints, sparse constraint graph –Lots of constraints, dense constraint graph
54
Some non-binary examples Timetabling –Variables: Lecture1, Lecture2, … –Values: time1, time2, … –Constraint that lectures taught by same lecturer do not conflict: alldifferent(Lecture1,Lecture5,…).
55
Some non-binary examples Scheduling –Variables: Job1. Job2, … –Values: machine1, machine2, … –Constraint on number of jobs on each machine: atmost(2,[Job1,Job2,…],machine1), atmost(1,[Job1,Job2,…],machine2).
56
Why use non-binary constraints? Binary constraints are NP-complete –Any non-binary constraint can be represented using binary constraints –E.g. alldifferent(X1,X2,X3) is “equivalent” to X1 =/= X2, X1 =/= X3, X2 =/= X3 In theory therefore they’re not needed –But in practice, they are!
57
Modelling with non-binary constraints Benefits include: –Compact, declarative specifications (discussed now) –Efficient constraint propagation (discussed next time)
58
Modelling with non-binary constraints Consider writing your own alldifferent constraint: alldifferent([]). alldifferent([Head|Tail]):- onediff(Head,Tail), alldifferent(Tail). onediff(El,[]). onediff(El,[Head|Tail]):- El #\= Head, onediff(El,Tail).
59
Modelling with non-binary constraints It’s possible but it’s not very pleasant! Nor is it very compact –alldifferent([X1,…Xn]) expands into n(n-1)/2 binary not-equals constraints, Xi \= Xj –one non-binary constraint or O(n^2) binary constraints? And there exist very efficient algorithms for reasoning efficiently with many specialized non-binary constraints
60
Constraint solvers Two main approaches –Systematic, tree search algorithms –Local search or repair based procedures Other more exotic possibilities –Hybrid algorithms –Quantum algorithms
61
Systematic solvers Tree search –Assign value to variable –Deduce values that must be removed from future/unassigned variables Constraint propagation –If future variable has no values, backtrack else repeat Number of choices –Variable to assign next, value to assign Some important refinements like nogood learning, non-chronological backtracking, …
62
Local search Repair based methods –Generate complete assignment –Change value to some variable in a violated constraint Number of choices –Violated constraint, variable within it, … Unable to exploit powerful constraint propagation techniques
63
To remember: CSP Constraint satisfaction problem (CSP) is a triple where: –V is set of variables –Each variable X in V has a (finite) domain of values, D_X –C is set of constraints Values for sets of variables which are not allowed Goal: find assignment of values to variables to satisfy all the constraints
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.