Download presentation

Presentation is loading. Please wait.

Published byIsabel Frazier Modified over 2 years ago

1
DCS Lecture how to solve it Patrick Prosser

2
Put a different number in each circle (1 to 8) such that adjacent circles cannot take consecutive numbers Your Challenge

3
56 Put a different number in each circle (1 to 8) such that adjacent circles cannot take consecutive numbers Thats illegal, okay?

4
3 3 Put a different number in each circle (1 to 8) such that adjacent circles cannot take consecutive numbers Thats illegal, okay?

5
The Puzzle Place numbers 1 through 8 on nodes –Each number appears exactly once ? ? ? ? ? ? ?? –No connected nodes have consecutive numbers You have 4 minutes!

6
How do we solve it? Bill Gates asks … how do we solve it?

7
Heuristic Search Which nodes are hardest to number? ? ? ? ? ? ? ?? Heuristic: a rule of thumb

8
Heuristic Search ? ? ? ? ? ? ??

9
? ? ? ? ? ? ?? Which are the least constraining values to use?

10
Heuristic Search ? 1 ? ? 8 ? ?? Values 1 and 8

11
Heuristic Search ? 1 ? ? 8 ? ?? Values 1 and 8 Symmetry means we dont need to consider: 8 1

12
Inference/propagation We can now eliminate many values for other nodes ? 1 ? ? 8 ? ?? Inference/propagation: reasoning

13
Inference/propagation ? 1 ? ? 8 ? ?? {1,2,3,4,5,6,7,8}

14
Inference/propagation ? 1 ? ? 8 ? ?? {2,3,4,5,6,7}

15
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6}

16
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6} By symmetry {3,4,5,6}

17
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6} {1,2,3,4,5,6,7,8}

18
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6} {2,3,4,5,6,7}

19
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6}

20
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6} By symmetry {3,4,5,6}

21
Inference/propagation ? 1 ? ? 8 ? ?? {3,4,5,6} {3,4,5,6,7} {3,4,5,6} {2,3,4,5,6}

22
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 nodes domain

23
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 …

24
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 …

25
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 …

26
Inference/propagation ? 1 ? ? 8 ? 27 {3,4,5} {4,5,6} Guess a value, but be prepared to backtrack … Backtrack?

27
Inference/propagation 3 1 ? ? 8 ? 27 {3,4,5} {4,5,6} Guess a value, but be prepared to backtrack …

28
Inference/propagation 3 1 ? ? 8 ? 27 {3,4,5} {4,5,6} And propagate …

29
Inference/propagation 3 1 ? ? 8 ? 27 {4,5} {5,6} {4,5,6} And propagate …

30
Inference/propagation 3 1 ? ? 8 ? 27 {4,5} {5,6} {4,5,6} Guess another value …

31
Inference/propagation 3 1 ? 5 8 ? 27 {4,5} {4,5,6} Guess another value …

32
Inference/propagation 3 1 ? 5 8 ? 27 {4,5} {4,5,6} And propagate …

33
Inference/propagation 3 1 ? 5 8 ? 27 {4} {4,6} And propagate …

34
Inference/propagation ? 27 {4} {4,6} One node has only a single value left …

35
Inference/propagation {6}

36
Solution!

37
How does a computer solve it? Bill Gates says … how does a computer solve it?

38
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 … ? ? ? ? ? ? ?? A Constraint Satisfaction Problem

39
How we might input the problem to a program Viewing the problem as a graph with 8 vertices and 17 edges

40

41
Graph Theory?

42

43

44

45
8 vertices, 17 edges vertex 0 is adjacent to vertex 1 vertex 3 is adjacent to vertex Our Problem as a Graph

46
Computer scientists count from zero By the way, Bill Gates says …

47
A Java (Constraint) Program to solve our problem

48
Read in the name of the input file

49
Make a Problem and attach variables to it Note: variables represent our vertices

50
Constrain all variables take different values

51
Read in edges and constrain corresponding variables/vertices non-consecutive

52
Solve the problem! Using constraint propagation and backtracking search

53
Print out the number of solutions

54
Why have you read in the puzzle as a file? Bill Gates wants to know …

55
So that we can be more general

56
This technology is called constraint programming

57
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 It is used for solving the following kinds of problems

58
Crew scheduling (airlines) Railway timetabling Factory/production scheduling Vehicle routing problems Network design problems Design of locks and keys Spatial layout workforce management … Some sample problems that use constraint programming

59
BT workforce management

60
Constraints are everywhere! No meetings before 10am Network traffic < 100 Gbytes/sec PCB width < 21cm Salary > 45k Euros …

61
A Commercial Reality First-tier software vendors use CP technology

62
You know, were doing something on this! Bill Gates is watching …

63

64

65
So, how do YOU solve it?

66
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! Computing Science at Glasgow

67
Constraint Programming An Introduction by example with help from Toby Walsh, Chris Beck, Barbara Smith, Peter van Beek, Edward Tsang,... That was a 4 th year lecture …

68
Thats all for now folks

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google