1 / 68

DCS Lecture how to solve it

DCS Lecture how to solve it. Patrick Prosser. Your Challenge. Put a different number in each circle (1 to 8) such that adjacent circles cannot take consecutive numbers. That’s illegal, okay?. 6. 5. Put a different number in each circle (1 to 8) such

sal
Download Presentation

DCS Lecture how to solve it

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DCS Lecture how to solve it Patrick Prosser

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

  3. That’s illegal, okay? 6 5 Put a different number in each circle (1 to 8) such that adjacent circles cannot take consecutive numbers

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

  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. Bill Gates asks … how do we solve it? How do we solve it?

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

  8. Heuristic Search ? ? ? ? ? ? ? ?

  9. Heuristic Search Which are the least constraining values to use? ? ? ? ? ? ? ? ?

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

  11. Heuristic Search Values 1 and 8 ? ? ? 1 8 ? ? ? Symmetry means we don’t need to consider: 8 1

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

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

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

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

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

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

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

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

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

  21. Inference/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}

  22. Inference/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 node’s domain

  23. Inference/propagation {3,4,5,6} {3,4,5,6} ? ? 7 1 8 2 {2,3,4,5,6} {3,4,5,6,7} ? ? {3,4,5,6} {3,4,5,6} And propagate …

  24. Inference/propagation {3,4,5} {3,4,5,6} ? ? 7 1 8 2 {2,3,4,5,6} {3,4,5,6,7} ? ? {3,4,5} {3,4,5,6} And propagate …

  25. Inference/propagation {3,4,5} {4,5,6} ? ? 7 1 8 2 {2,3,4,5,6} {3,4,5,6,7} ? ? {3,4,5} {4,5,6} And propagate …

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

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

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

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

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

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

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

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

  34. Inference/propagation 3 5 7 1 8 2 4 ? {4} {4,6} One node has only a single value left …

  35. Inference/propagation 3 5 7 1 8 2 4 6 {6}

  36. Solution! 3 5 7 1 8 2 4 6

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

  38. A 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 | > 1 |v1 - v3 | > 1 …

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

  40. Graph Theory?

  41. Our Problem as a Graph vertex 0 is adjacent to vertex 1 vertex 3 is adjacent to vertex 7 8 vertices, 17 edges 1 2 0 6 7 3 5 4

  42. By the way, Bill Gates says … Computer scientists count from zero 

  43. A Java (Constraint) Program to solve our problem

  44. Read in the name of the input file

  45. Make a “Problem” and attach “variables” to it Note: variables represent our vertices

  46. Constrain all variables take different values

More Related