dcs lecture how to solve it patrick prosser. put a different number in each circle (1 to 8) such...

Post on 28-Mar-2015

213 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

DCS Lecture

how to solve it

Patrick Prosser

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

Your Challenge

56

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

That’s illegal, okay?

3

3

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

That’s illegal, okay?

The Puzzle

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

?

?

?

?

?

?

??

– No connected nodes have consecutive numbers

You have 4 minutes!

How do we solve it?

Bill Gates asks … how do we solve it?

Heuristic Search

Which nodes are hardest to number?

?

?

?

?

?

?

??

Heuristic: a rule of thumb

Heuristic Search

?

?

?

?

?

?

??

Heuristic Search

?

?

?

?

?

?

??

Which are the least constraining values to use?

Heuristic Search

?

1

?

?

8

?

??

Values 1 and 8

Heuristic Search

?

1

?

?

8

?

??

Values 1 and 8

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

Inference/propagation

We can now eliminate many values for other nodes

?

1

?

?

8

?

??

Inference/propagation: reasoning

Inference/propagation

?

1

?

?

8

?

??

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

Inference/propagation

?

1

?

?

8

?

??

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

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

By symmetry

{3,4,5,6}

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

{3,4,5,6}

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

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

{3,4,5,6}

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

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

{3,4,5,6}

{3,4,5,6}

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

By symmetry

{3,4,5,6}

{3,4,5,6}

{3,4,5,6}

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}

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

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 …

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 …

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 …

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?

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 …

Inference/propagation

3

1

?

?

8

?

27

{3,4,5}

{3,4,5}

{4,5,6}

{4,5,6}

And propagate …

Inference/propagation

3

1

?

?

8

?

27

{4,5}

{5,6}

{4,5,6}

And propagate …

Inference/propagation

3

1

?

?

8

?

27

{4,5}

{5,6}

{4,5,6}

Guess another value …

Inference/propagation

3

1

?

5

8

?

27

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

Guess another value …

Inference/propagation

3

1

?

5

8

?

27

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

And propagate …

Inference/propagation

3

1

?

5

8

?

27

{4} {4,6}

And propagate …

Inference/propagation

3

1

4

5

8

?

27

{4} {4,6}

One node has only a single value left …

Inference/propagation

3

1

4

5

8

6

27

{6}

Solution!

3

1

4

5

8

6

27

How does a computer solve

it?

Bill Gates says … how does a computer 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

How we might input the problem to a program

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

Graph Theory?

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

Computer scientists count

from zero

By the way, Bill Gates says …

A Java (Constraint) Programto solve our problem

Read in the name of the input file

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

Note: variables represent our vertices

Constrain all variables take different values

Read in edges and constrain correspondingvariables/vertices non-consecutive

Solve the problem!

Using constraint propagation and backtracking search

Print out the number of solutions

Why have you read in the

puzzle as a file?

Bill Gates wants to know …

So that we can be more general

0

1 2

8 9

7 6

10

3

5

4

This technology is called

“constraint programming”

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

• 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

BT workforce management

Constraints are everywhere!

• No meetings before 10am• Network traffic < 100

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

A Commercial Reality

• First-tier software vendors use CP technology

You know, we’re doing

something on this!

Bill Gates is watching …

So, how do YOU 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

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 …

That’s all for now folks

top related