68
DCS Lecture how to solve it Patrick Prosser

DCS Lecture how to solve it

  • Upload
    sal

  • View
    29

  • Download
    0

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

Citation preview

Page 1: DCS Lecture how to solve it

DCS Lecture

how to solve it

Patrick Prosser

Page 2: DCS Lecture how to solve it

Put a different number in each circle (1 to 8) suchthat adjacent circles cannot take consecutive numbers

Your Challenge

Page 3: DCS Lecture how to solve it

56

Put a different number in each circle (1 to 8) suchthat adjacent circles cannot take consecutive numbers

That’s illegal, okay?

Page 4: DCS Lecture how to solve it

3

3

Put a different number in each circle (1 to 8) suchthat adjacent circles cannot take consecutive numbers

That’s illegal, okay?

Page 5: DCS Lecture how to solve it

The Puzzle

• Place numbers 1 through 8 on nodes– Each number appears exactly once

?

?

?

?

?

?

??

– No connected nodes have consecutive numbers

You have 4 minutes!

Page 6: DCS Lecture how to solve it

How do we solve it?

Bill Gates asks … how do we solve it?

Page 7: DCS Lecture how to solve it

Heuristic Search

Which nodes are hardest to number?

?

?

?

?

?

?

??

Heuristic: a rule of thumb

Page 8: DCS Lecture how to solve it

Heuristic Search

?

?

?

?

?

?

??

Page 9: DCS Lecture how to solve it

Heuristic Search

?

?

?

?

?

?

??

Which are the least constraining values to use?

Page 10: DCS Lecture how to solve it

Heuristic Search

?

1

?

?

8

?

??

Values 1 and 8

Page 11: DCS Lecture how to solve it

Heuristic Search

?

1

?

?

8

?

??

Values 1 and 8

Symmetry means we don’t need to consider: 8 1

Page 12: DCS Lecture how to solve it

Inference/propagation

We can now eliminate many values for other nodes

?

1

?

?

8

?

??

Inference/propagation: reasoning

Page 13: DCS Lecture how to solve it

Inference/propagation

?

1

?

?

8

?

??

{1,2,3,4,5,6,7,8}

Page 14: DCS Lecture how to solve it

Inference/propagation

?

1

?

?

8

?

??

{2,3,4,5,6,7}

Page 15: DCS Lecture how to solve it

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

Page 16: DCS Lecture how to solve it

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

By symmetry

{3,4,5,6}

Page 17: DCS Lecture how to solve it

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

{3,4,5,6}

{1,2,3,4,5,6,7,8}

Page 18: DCS Lecture how to solve it

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

{3,4,5,6}

{2,3,4,5,6,7}

Page 19: DCS Lecture how to solve it

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

{3,4,5,6}

{3,4,5,6}

Page 20: DCS Lecture how to solve it

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

By symmetry

{3,4,5,6}

{3,4,5,6}

{3,4,5,6}

Page 21: DCS Lecture how to solve it

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

{3,4,5,6,7}

{3,4,5,6}

{3,4,5,6}

{3,4,5,6}

{2,3,4,5,6}

Page 22: DCS Lecture how to solve it

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

{3,4,5,6,7}

{3,4,5,6}

{3,4,5,6}

{3,4,5,6}

{2,3,4,5,6}

Value 2 and 7 are left in just one node’s domain

Page 23: DCS Lecture how to solve it

Inference/propagation

?

1

?

?

8

?

27

{3,4,5,6}

{3,4,5,6,7}

{3,4,5,6}

{3,4,5,6}

{3,4,5,6}

{2,3,4,5,6}

And propagate …

Page 24: DCS Lecture how to solve it

Inference/propagation

?

1

?

?

8

?

27

{3,4,5}

{3,4,5,6,7}

{3,4,5}

{3,4,5,6}

{3,4,5,6}

{2,3,4,5,6}

And propagate …

Page 25: DCS Lecture how to solve it

Inference/propagation

?

1

?

?

8

?

27

{3,4,5}

{3,4,5,6,7}

{3,4,5}

{4,5,6}

{4,5,6}

{2,3,4,5,6}

And propagate …

Page 26: DCS Lecture how to solve it

Inference/propagation

?

1

?

?

8

?

27

{3,4,5}

{3,4,5}

{4,5,6}

{4,5,6}

Guess a value, but be prepared to backtrack … Backtrack?

Page 27: DCS Lecture how to solve it

Inference/propagation

3

1

?

?

8

?

27

{3,4,5}

{3,4,5}

{4,5,6}

{4,5,6}

Guess a value, but be prepared to backtrack …

Page 28: DCS Lecture how to solve it

Inference/propagation

3

1

?

?

8

?

27

{3,4,5}

{3,4,5}

{4,5,6}

{4,5,6}

And propagate …

Page 29: DCS Lecture how to solve it

Inference/propagation

3

1

?

?

8

?

27

{4,5}

{5,6}

{4,5,6}

And propagate …

Page 30: DCS Lecture how to solve it

Inference/propagation

3

1

?

?

8

?

27

{4,5}

{5,6}

{4,5,6}

Guess another value …

Page 31: DCS Lecture how to solve it

Inference/propagation

3

1

?

5

8

?

27

{4,5} {4,5,6}

Guess another value …

Page 32: DCS Lecture how to solve it

Inference/propagation

3

1

?

5

8

?

27

{4,5} {4,5,6}

And propagate …

Page 33: DCS Lecture how to solve it

Inference/propagation

3

1

?

5

8

?

27

{4} {4,6}

And propagate …

Page 34: DCS Lecture how to solve it

Inference/propagation

3

1

4

5

8

?

27

{4} {4,6}

One node has only a single value left …

Page 35: DCS Lecture how to solve it

Inference/propagation

3

1

4

5

8

6

27

{6}

Page 36: DCS Lecture how to solve it

Solution!

3

1

4

5

8

6

27

Page 37: DCS Lecture how to solve it

How does a computer solve

it?

Bill Gates says … how does a computer solve it?

Page 38: DCS Lecture how to solve it

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

?

?

?

?

?

?

??

A Constraint Satisfaction Problem

Page 39: DCS Lecture how to solve it

How we might input the problem to a program

Viewing the problem as a “graph” with 8 “vertices” and 17 “edges”

Page 40: DCS Lecture how to solve it
Page 41: DCS Lecture how to solve it

Graph Theory?

Page 42: DCS Lecture how to solve it
Page 43: DCS Lecture how to solve it
Page 44: DCS Lecture how to solve it
Page 45: DCS Lecture how to solve it

8 vertices, 17 edges

vertex 0 is adjacent to vertex 1

vertex 3 is adjacent to vertex 7

0

1 2

6 7

5 4

3

Our Problem as a Graph

Page 46: DCS Lecture how to solve it

Computer scientists count

from zero

By the way, Bill Gates says …

Page 47: DCS Lecture how to solve it

A Java (Constraint) Programto solve our problem

Page 48: DCS Lecture how to solve it

Read in the name of the input file

Page 49: DCS Lecture how to solve it

Make a “Problem” and attach“variables” to it

Note: variables represent our vertices

Page 50: DCS Lecture how to solve it

Constrain all variables take different values

Page 51: DCS Lecture how to solve it

Read in edges and constrain correspondingvariables/vertices non-consecutive

Page 52: DCS Lecture how to solve it

Solve the problem!

Using constraint propagation and backtracking search

Page 53: DCS Lecture how to solve it

Print out the number of solutions

Page 54: DCS Lecture how to solve it

Why have you read in the

puzzle as a file?

Bill Gates wants to know …

Page 55: DCS Lecture how to solve it

So that we can be more general

0

1 2

8 9

7 6

10

3

5

4

Page 56: DCS Lecture how to solve it

This technology is called

“constraint programming”

Page 57: DCS Lecture how to solve it

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

Page 58: DCS Lecture how to solve it

• 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

Page 59: DCS Lecture how to solve it

BT workforce management

Page 60: DCS Lecture how to solve it

Constraints are everywhere!

• No meetings before 10am• Network traffic < 100

Gbytes/sec• PCB width < 21cm• Salary > 45k Euros…

Page 61: DCS Lecture how to solve it

A Commercial Reality

• First-tier software vendors use CP technology

Page 62: DCS Lecture how to solve it

You know, we’re doing

something on this!

Bill Gates is watching …

Page 63: DCS Lecture how to solve it
Page 64: DCS Lecture how to solve it
Page 65: DCS Lecture how to solve it

So, how do YOU solve it?

Page 66: DCS Lecture how to solve it

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

Page 67: DCS Lecture how to solve it

Constraint ProgrammingAn Introduction

by example

with help from Toby Walsh, Chris Beck,Barbara Smith, Peter van Beek, Edward Tsang, ...

That was a 4th year lecture …

Page 68: DCS Lecture how to solve it

That’s all for now folks