Title: DCS Lecture
1DCS Lecture how to solve it
Patrick Prosser
2Your Challenge
Put a different number in each circle (1 to 8)
such that adjacent circles cannot take
consecutive numbers
3Thats illegal, okay?
5
6
Put a different number in each circle (1 to 8)
such that adjacent circles cannot take
consecutive numbers
4Thats illegal, okay?
3
3
Put a different number in each circle (1 to 8)
such that adjacent circles cannot take
consecutive numbers
5The Puzzle
- Place numbers 1 through 8 on nodes
- Each number appears exactly once
- No connected nodes have consecutive numbers
?
?
?
?
?
?
?
?
You have 4 minutes!
6Bill Gates asks how do we solve it?
How do we solve it?
7Heuristic Search
Which nodes are hardest to number?
?
?
?
?
?
?
?
?
Heuristic a rule of thumb
8Heuristic Search
?
?
?
?
?
?
?
?
9Heuristic Search
Which are the least constraining values to use?
?
?
?
?
?
?
?
?
10Heuristic Search
Values 1 and 8
?
?
1
8
?
?
?
?
11Heuristic Search
Values 1 and 8
?
?
1
8
?
?
?
?
Symmetry means we dont need to consider 8 1
12Inference/propagation
We can now eliminate many values for other nodes
Inference/propagation reasoning
13Inference/propagation
1,2,3,4,5,6,7,8
?
?
1
8
?
?
?
?
14Inference/propagation
2,3,4,5,6,7
?
?
1
8
?
?
?
?
15Inference/propagation
3,4,5,6
?
?
1
8
?
?
?
?
16Inference/propagation
3,4,5,6
?
?
1
8
?
?
?
?
3,4,5,6
By symmetry
17Inference/propagation
3,4,5,6
1,2,3,4,5,6,7,8
?
?
1
8
?
?
?
?
3,4,5,6
18Inference/propagation
3,4,5,6
2,3,4,5,6,7
?
?
1
8
?
?
?
?
3,4,5,6
19Inference/propagation
3,4,5,6
3,4,5,6
?
?
1
8
?
?
?
?
3,4,5,6
20Inference/propagation
3,4,5,6
3,4,5,6
?
?
1
8
?
?
?
?
3,4,5,6
3,4,5,6
By symmetry
21Inference/propagation
3,4,5,6
3,4,5,6
?
?
1
8
?
?
2,3,4,5,6
3,4,5,6,7
?
?
3,4,5,6
3,4,5,6
22Inference/propagation
3,4,5,6
3,4,5,6
?
?
1
8
?
?
2,3,4,5,6
3,4,5,6,7
?
?
3,4,5,6
3,4,5,6
Value 2 and 7 are left in just one nodes domain
23Inference/propagation
3,4,5,6
3,4,5,6
?
?
1
8
2
7
2,3,4,5,6
3,4,5,6,7
?
?
3,4,5,6
3,4,5,6
And propagate
24Inference/propagation
3,4,5
3,4,5,6
?
?
1
8
2
7
2,3,4,5,6
3,4,5,6,7
?
?
3,4,5
3,4,5,6
And propagate
25Inference/propagation
3,4,5
4,5,6
?
?
1
8
2
7
2,3,4,5,6
3,4,5,6,7
?
?
3,4,5
4,5,6
And propagate
26Inference/propagation
3,4,5
4,5,6
?
?
1
8
2
7
?
?
3,4,5
4,5,6
Guess a value, but be prepared to backtrack
Backtrack?
27Inference/propagation
3,4,5
4,5,6
3
?
1
8
2
7
?
?
3,4,5
4,5,6
Guess a value, but be prepared to backtrack
28Inference/propagation
3,4,5
4,5,6
3
?
1
8
2
7
?
?
3,4,5
4,5,6
And propagate
29Inference/propagation
5,6
3
?
1
8
2
7
?
?
4,5
4,5,6
And propagate
30Inference/propagation
5,6
3
?
1
8
2
7
?
?
4,5
4,5,6
Guess another value
31Inference/propagation
3
5
1
8
2
7
?
?
4,5
4,5,6
Guess another value
32Inference/propagation
3
5
1
8
2
7
?
?
4,5
4,5,6
And propagate
33Inference/propagation
3
5
1
8
2
7
?
?
4
4,6
And propagate
34Inference/propagation
3
5
1
8
2
7
4
?
4
4,6
One node has only a single value left
35Inference/propagation
3
5
1
8
2
7
4
6
6
36Solution!
3
5
1
8
2
7
4
6
37How does a computer solve it?
Bill Gates says how does a computer solve it?
38A Constraint Satisfaction Problem
- Variable, vi for each node
- Domain of 1, , 8
- Constraints
- All values used
- Alldifferent(v1 v2 v3 v4 v5 v6 v7 v8)
- No consecutive numbers for adjoining nodes
- v1 - v2 gt 1
- v1 - v3 gt 1
-
39How we might input the problem to a program
Viewing the problem as a graph with 8
vertices and 17 edges
40(No Transcript)
41Graph Theory?
42(No Transcript)
43(No Transcript)
44(No Transcript)
45Our Problem as a Graph
8 vertices, 17 edges
1
2
0
6
7
3
5
4
46Computer scientists count from zero ?
By the way, Bill Gates says
47A Java (Constraint) Program to solve our problem
48Read in the name of the input file
49Make a Problem and attach variables to it
Note variables represent our vertices
50Constrain all variables take different values
51Read in edges and constrain corresponding variable
s/vertices non-consecutive
52Solve the problem!
Using constraint propagation and backtracking
search
53Print out the number of solutions
54Why have you read in the puzzle as a file?
Bill Gates wants to know
55So that we can be more general
56This technology is called constraint
programming
57Constraint 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
It is used for solving the following kinds of
problems
58Some sample problems that use constraint
programming
- Crew scheduling (airlines)
- Railway timetabling
- Factory/production scheduling
- Vehicle routing problems
- Network design problems
- Design of locks and keys
- Spatial layout
- workforce management
59BT workforce management
60Constraints are everywhere!
- No meetings before 10am
- Network traffic lt 100 Gbytes/sec
- PCB width lt 21cm
- Salary gt 45k Euros
61A Commercial Reality
- First-tier software vendors use CP technology
62You know, were doing something on this!
Bill Gates is watching
63(No Transcript)
64(No Transcript)
65So, how do YOU solve it?
66Computing Science at Glasgow
Learn to program a computer, learn a bit of
discrete maths, algorithmics, learn about
hardware, security and data protection, computer
graphics, information management, project
management, interactive systems, computer
networks, operating systems, professional
issues, software engineering, machine learning,
bioinformatics, grid computing and of course
constraint
programming!
67That was a 4th year lecture
Constraint Programming An Introduction by
example with help from Toby Walsh, Chris
Beck, Barbara Smith, Peter van Beek, Edward
Tsang, ...
68Thats all for now folks