DCS Lecture how to solve it Patrick Prosser

  • Slides: 68
Download presentation
DCS Lecture how to solve it Patrick Prosser

DCS Lecture how to solve it Patrick Prosser

Your Challenge Put a different number in each circle (1 to 8) such that

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

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

That’s illegal, okay? 3 3 Put a different number in each circle (1 to

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

The Puzzle • Place numbers 1 through 8 on nodes – Each number appears

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

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

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

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

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

Heuristic Search ? ?

Heuristic Search ? ?

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

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

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

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

Heuristic Search Values 1 and 8 ? ? ? 1 8 ? ? Symmetry

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

Inference/propagation ? ? ? 1 8 ? ? ? We can now eliminate many

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Inference/propagation ? {3, 4, 5, 6} ? ? 1 8 ? {2, 3, 4, 5, 6} {3, 4, 5, 6, 7} ? ? {3, 4, 5, 6} Value 2 and 7 are left in just one node’s domain

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Inference/propagation {5, 6} 7 3 ? 1 8 ? ? {4, 5} Guess another

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

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

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

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

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

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

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

Inference/propagation 7 {4} 3 5 1 8 4 ? {4, 6} One node has

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

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

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

Solution! 7 3 5 1 8 4 6 2

Solution! 7 3 5 1 8 4 6 2

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

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

A Constraint Satisfaction Problem ? ? • Variable, vi for each node • Domain

A Constraint Satisfaction Problem ? ? • Variable, vi 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 …

How we might input the problem to a program Viewing the problem as a

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

Graph Theory?

Graph Theory?

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

Our Problem as a Graph 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

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

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

A Java (Constraint) Program to solve our problem

A Java (Constraint) Program to solve our problem

Read in the name of the input file

Read in the name of the input file

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

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

Constrain all variables take different values

Constrain all variables take different values

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

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

Solve the problem! Using constraint propagation and backtracking search

Solve the problem! Using constraint propagation and backtracking search

Print out the number of solutions

Print out the number of solutions

Bill Gates wants to know … Why have you read in the puzzle as

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

So that we can be more general 0 1 2 3 8 9 10

So that we can be more general 0 1 2 3 8 9 10 6 5 7 4

This technology is called “constraint programming”

This technology is called “constraint programming”

Constraint programming • Model problem by specifying constraints on acceptable solutions – define variables

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

Some sample problems that use constraint programming • Crew scheduling (airlines) • Railway timetabling

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

BT workforce management

BT workforce management

Constraints are everywhere! • No meetings before 10 am • Network traffic < 100

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

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

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

Bill Gates is watching … You know, we’re doing something on this!

Bill Gates is watching … You know, we’re doing something on this!

So, how do YOU solve it?

So, how do YOU solve it?

Computing Science at Glasgow Learn to program a computer, learn a bit of discrete

Computing 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!

That was a 4 th year lecture … Constraint Programming An Introduction by example

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

That’s all for now folks

That’s all for now folks