• No results found

Introduction & Overview

N/A
N/A
Protected

Academic year: 2021

Share "Introduction & Overview"

Copied!
96
0
0

Loading.... (view fulltext now)

Full text

(1)

ID2204: Constraint Programming

Introduction & Overview

Lecture 01, 2015-03-23

Christian Schulte

[email protected]

Software and Computer Systems

School of Information and Communication Technology KTH – Royal Institute of Technology

(2)

Lecture Overview

What is Constraint Programming?

Sudoku is Constraint Programming

... more later

(3)

Sudoku

...is Constraint Programming!

(4)

Sudoku

Assign blank fields digits such that:

digits distinct per rows, columns, blocks

9 2

2 5

9

7 3 6 2

6 9

7

4 9

1 8

6 3 4

6 8

1 8

(5)

Sudoku

Assign blank fields digits such that:

9 2

2 5

9

7 3 6 2

6 9

7

4 9

1 8

6 3 4

6 8

1 8

(6)

Sudoku

Assign blank fields digits such that:

digits distinct per rows, columns, blocks

9 2

2 5

9

7 3 6 2

6 9

7

4 9

1 8

6 3 4

6 8

1 8

(7)

Sudoku

Assign blank fields digits such that:

9 2

2 5

9

7 3 6 2

6 9

7

4 9

1 8

6 3 4

6 8

1 8

(8)

Block Propagation

No field in block can take digits 3,6,8

8

6 3

(9)

Block Propagation

No field in block can take digits 3,6,8

propagate to other fields in block

1,2,4,5,7,9

8

1,2,4,5,7,9

1,2,4,5,7,9

6 3

1,2,4,5,7,9 1,2,4,5,7,9 1,2,4,5,7,9

(10)

Propagation

Prune digits from fields such that:

digits distinct per rows, columns, blocks

9 2

2 5

9

7 3 6 2

6 9

7

4 9

1 8

6 3 4

6 8

1 8

1,2,3,4,5,6,7,8,9

(11)

Propagation

Prune digits from fields such that:

9 2

2 5

9

7 3 6

9 6

2

7

1 9 4

8 6 3

4

6 8

1 8

1,3,5,6,7,8

(12)

Propagation

Prune digits from fields such that:

digits distinct per rows, columns, blocks

9

2 9

5 2

7 3 6 2

6 9

7

4 9

1 8

6 3

8 6

4 1

8

1,3,6,7

(13)

Propagation

Prune digits from fields such that:

9 2

2 5

9

7 3 6 2

6 9

7

4 9

1 8

6 3 4

6 8

1 8

1,3,6

(14)

Iterated Propagation

Iterate propagation for rows, columns, blocks

What if no assignment: search... later

9 2

2 5

9

7 3 6 2

6 9

7

4 9

1 8

6 3 4

6 8

1 8

(15)

Sudoku is Constraint Programming

Modelling: variables, values, constraints

9 2

2 5

9

7 3 6 2

6 9

7

4 9

1 8

6 3 4

6 8

1 8

Variables: fields

take values: digits

maintain set of possible values

Constraints: distinct

relation among variables

(16)

Constraint Programming

Variable domains

finite domain integer, finite sets, multisets, intervals, ...

Constraints

distinct, arithmetic, scheduling, graphs, ...

Solving

propagation, branching, exploration, ...

Modelling

variables, values, constraints, heuristics, symmetries, ...

(17)

Plan of Lecture

Introduction

what is constraint programming?

principles and applications

Overview

course content

course goal

Organizational

(18)

What Is Constraint

Programming?

(19)

Running Example: SMM

Find distinct digits for letters, such that

SEND + MORE

= MONEY

(20)

Constraint Model for SMM

Variables:

S,E,N,D,M,O,R,Y  {0,…,9}

Constraints:

distinct(S,E,N,D,M,O,R,Y)

1000×S+100×E+10×N+D + 1000×M+100×O+10×R+E

= 10000×M+1000×O+100×N+10×E+Y S0 M0

(21)

Solving SMM

Find values for variables

such that

all constraints satisfied

(22)

Finding a Solution

Compute with possible values

rather than enumerating assignments

Prune inconsistent values

constraint propagation

Search

branch: define search tree

explore: explore search tree for solution

(23)

Constraint Propagation

(24)

Important Concepts

Constraint store

Propagator

Constraint propagation

(25)

Constraint Store

Maps variables to possible values

stores basic constraints

x{3,4,5} y{3,4,5}

(26)

Constraint Store

Maps variables to possible values

Others: finite sets, intervals, trees, ...

x{3,4,5} y{3,4,5}

finite domain constraints

(27)

Propagators

Implement (non-basic) constraints distinct(x1,…,xn)

x + 2*y = z

(28)

Propagators

Amplify store by constraint propagation x{3,4,5} y{3,4,5}

xy y>3

(29)

Propagators

Amplify store by constraint propagation x{3,4,5} y{3,4,5}

xy y>3

(30)

Propagators

Amplify store by constraint propagation x{3,4,5} y{4,5}

xy y>3

(31)

Propagators

Amplify store by constraint propagation x{3,4,5} y{4,5}

xy y>3

(32)

Propagators

Amplify store by constraint propagation x{4,5} y{4,5}

xy y>3

(33)

Propagators

Amplify store by constraint propagation

Disappear when done (subsumed, entailed) x{4,5} y{4,5}

xy y>3

(34)

Propagators

Amplify store by constraint propagation

Disappear when done (subsumed, entailed)

no more propagation possible

x{4,5} y{4,5}

xy

(35)

Propagation for SMM

Results in store

S{9} E{4,…,7} N{5,…,8} D{2,…,8}

M{1} O{0} R{2,…,8} Y{2,…,8}

Propagation alone not sufficient!

create simpler sub-problems

branching

(36)

Constraints and Propagators

Constraints state relations among variables

which value combinations satisfy constraint

Propagators implement constraints

prune values in conflict with constraint

Constraint propagation drives propagators for several constraints

(37)

Search

(38)

Important Concepts

Branching

Exploration

Branching heuristics

Best-solution search

(39)

Search: Branching

Create subproblems with additional information

enable further constraint propagation x{4,5} y{4,5}

xy

x{4} y{4}

xy

x{5} y{4,5}

xy

x=4 x4

(40)

Example Branching Strategy

Pick variable x with at least two values

Pick value n from domain of x

Branch with

x=n and xn

Part of model

(41)

Search: Exploration

Iterate propagation and branching

Orthogonal: branching  exploration Nodes:

(42)

SMM: Unique Solution

SEND + MORE

= MONEY 9567 + 1085

= 10652

(43)

Heuristics for Branching

Which variable

least possible values (first-fail)

application dependent heuristic

Which value

minimum, median, maximum

x=m or xm

split with median m

x<m or xm

Problem specific

(44)

SMM: Solution With First-fail

SEND + MORE

= MONEY 9567 + 1085

= 10652

(45)

Send Most Money (SMM++)

Find distinct digits for letters, such that

and MONEY maximal

SEND + MOST

= MONEY

(46)

Best Solution Search

Naïve approach:

compute all solutions

choose best

Branch-and-bound approach:

compute first solution

add “betterness” constraint to open nodes

next solution will be “better”

prunes search space

(47)

Branch-and-bound Search

(48)

Branch-and-bound Search

Explore with additional constraint

(49)

Branch-and-bound Search

(50)

Branch-and-bound Search

Guarantees better solutions

(51)

Branch-and-bound Search

(52)

Branch-and-bound Search

Last solution best

(53)

Branch-and-bound Search

(54)

Modelling SMM++

Constraints and branching as before

Order among solutions with constraints

so-far-best solution S,E,N,D,M,O,T,Y

current node S,E,N,D,M,O,T,Y

constraint added

10000×M+1000×O+100×N+10×E+Y

<

10000×M+1000×O+100×N+10×E+Y

(55)

SMM++: Branch-and-bound

SEND + MOST

= MONEY 9782 + 1094

= 10876

(56)

SMM++: All Solution Search

SEND + MOST

= MONEY 9782 + 1094

= 10876

(57)

Summary

(58)

Summary: Key Ideas and Principles

Modelling

variables with domain

constraints to state relations

branching strategy

solution ordering

Solving

constraint propagation

constraint branching

search tree exploration

applications

principles

(59)

Widely Applicable

Timetabling

Scheduling

Crew rostering

Resource allocation

Workflow planning and optimization

Gate allocation at airports

Sports-event scheduling

Railroad: track allocation, train allocation, schedules

Automatic composition of music

Genome sequencing

Frequency allocation

(60)

Draws on Variety of Techniques

Artificial intelligence

basic idea, search, ...

Operations research

scheduling, flow, ...

Algorithms

graphs, matching, networks, ...

Programming languages

programmability, extensionability, ...

(61)

Essential Aspect

Compositional middleware for combining

smart algorithmic

problem substructures

components (propagators)

scheduling

graphs

flows

plus

(62)

Principles

Models for constraint propagation

properties and guarantees

Strong constraint propagation

global constraints with strong algorithmic methods

mantra: search kills, search kills, search k…

Branching strategies

Exploration strategies

(63)

SMM: Strong Propagation

SEND + MORE

= MONEY 9567 + 1085

= 10652

(64)

Scheduling Resources

Modelling

Propagation

Strong propagation

(65)

Scheduling Resources: Problem

Tasks

duration

resource

Precedence constraints

determine order among two tasks

Resource constraints

at most one task per resource

(66)

Scheduling: Bridge Example

Infamous:

additional side

constraints!

(67)

Scheduling: Solution

Start time for each task

All constraints satisfied

Earliest completion time

minimal make-span

(68)

Scheduling: Model

Variable for start-time of task a start(a)

Precedence constraint: a before b start(a) + dur(a) start(b)

(69)

Propagating Precedence

start(a){0,…,7}

start(b){0,…,5}

a b

a before b

(70)

Propagating Precedence

start(a){0,…,7}

start(b){0,…,5}

a b

a

b

a before b

start(a){0,…,2}

start(b){3,…,5}

(71)

Scheduling: Model

Variable for start-time of task a start(a)

Precedence constraint: a before b start(a) + dur(a) start(b)

Resource constraint:

a before b or

b before a

(72)

Scheduling: Model

Variable for start-time of task a start(a)

Precedence constraint: a before b start(a) + dur(a) start(b)

Resource constraint:

start(a) + dur(a) start(b) or

b before a

(73)

Scheduling: Model

Variable for start-time of task a start(a)

Precedence constraint: a before b start(a) + dur(a) start(b)

Resource constraint:

start(a) + dur(a) start(b) or

start(b) + dur(b) start(a)

(74)

Reified Constraints

Use control variable b{0,1}

c b=1

Propagate

c holds propagate b=1

c holds propagate b=0

b=1 holds propagate c

b=0 holds propagate c

(75)

Reified Constraints

Use control variable b{0,1}

c b=1

Propagate

c holds propagate b=1

c holds propagate b=0

b=1 holds propagate c

b=0 holds propagate c

not easy!

(76)

Reification for Disjunction

Reify each precedence

[start(a) + dur(a) start(b)] b0=1 and

[start(b) + dur(b) start(a)] b1=1

Model disjunction b0 + b1  1

(77)

Model Is Too Naive

Local view

individual task pairs

O(n2) propagators for n tasks

Global view ("global" constraints)

all tasks on resource

single propagator

smarter algorithms possible

(78)

Example: Edge Finding

Find ordering among tasks (“edges”)

For each subset of tasks {a}B

assume: a before B

deduce information for a and B

assume: B before a

deduce information for a and B

join computed information

can be done in O(n2)

(79)

Summary

Modeling

easy but not always efficient

constraint combinators (reification)

global constraints

smart heuristics

More on constraint-based scheduling

Baptiste, Le Pape, Nuijten. Constraint-based Scheduling, Kluwer, 2001.

(80)

Course Overview

(81)

Content Overview

As to be expected, no surprises:

applications principles pragmatics limitations

(82)

Modeling with CP

Basic solving methods

constraint propagation

search

Typical techniques for modeling in different application areas

redundant constraints, symmetry elimination

Refining models by strong algorithmic methods

Heuristic search methods

Application to hard real-size problems

(83)

Principles Underlying CP

Models for

propagation

search

and their essential properties

Different levels of consistency (propagation strength)

Different constraint domains

finite domains, finite sets, ...

(84)

Strong Algorithmic Methods

Régin's distinct algorithm

Edge-finding

Integration

achieving required properties for propagation

(85)

Relation to Other Techniques

Integer programming

Local search

Discussion of merits and weaknesses

Hybrid approaches

(86)

Goals: Learning Outcomes

explain and apply basic modeling techniques for constraint

problems, including the selection of variables, constraints, and optimization criteria.

describe and apply depth-first search and branch-and-bound search for solving constraint problems.

describe and define constraint propagation, search branching, and search tree exploration

prove correctness, consistency, and completeness of propagators implementing constraints.

define and prove correctness of branching strategies.

describe optimizations of constraint propagation based on fixpoint reasoning.

(87)

Goals: Learning Outcomes

describe advanced modeling techniques, analyze combinatorial problems for the applicability of these techniques, and apply and combine them

techniques include: general symmetries, value and variable

symmetries, symmetry breaking with constraints, symmetry breaking during search, domination constraints, redundant constraints,

redundant modeling and channeling, using strong algorithmic techniques, and branching heuristics.

describe and apply Régin's algorithm for the distinct constraint as an example of strong constraint propagation

explain algorithms for the element constraint, linear constraints, and disjunctive scheduling constraints.

implement a simple propagation algorithm.

describe the main strength and weaknesses of constraint

(88)

Organizational

(89)

Material

Lecture notes (slides)

available before the lectures…

Additional material

book excerpts

scientific articles

notes written by me

Modeling and Programming with Gecode

(90)

How to Pass?

Pass exam

has 200 (3 hour exam) exam points

100 total points needed

grading scale linear (see www)

Total pts = exam pts + bonus pts

Bonus points

from assignments

at most 20 points

(91)

Assignments

Four assignments

each 5 bonus points if submitted in time

one to three weeks for solving

Points only valid in this academic year!

(92)

Assignment Tasks

Exploration tasks

small tryouts

need to be done in order to do…

Submission tasks

submit in time, get bonus points

do them, do them

submit to me by email [email protected]

Both practical and principles

(93)

Software: Gecode

Gecode C++ library

course web: links to Gecode page

Download and install

at least version 4.4.0 (available on Monday)

Start reading

“Modeling and Programming with Gecode”

at the beginning of Part M are reading instructions

(94)

Contacting…

Christian Schulte [email protected]

other options (urgent cases), see my homepage

(95)

Summary

Constraint programming…

…is exciting!

…is fun!

Understanding of principles and applications necessary

Read the webpage

https://www.kth.se/social/course/ID2204/

(96)

Acknowledgments

I am grateful to Pierre Flener for helpful

comments and bugreports on these slides

References

Related documents

Might pass global optima after reaching it adverse effect (easy to avoid by keeping track of 7 g best-ever state) CS 470/670 Artificial Intelligence B lt hi Boltzmann machines B

Then, the designer applies a sequence of five algorithm to this firewall decision dia- gram to generate a compact sequence of firewall rules while maintaining the consistency

the branching objects do not carry labels. The labels assigned to branching objects by a branching rule can and should, however, be kept after the application of a branching rule.

We apply the probabilistic approach to the tree search using the K best algorithm: to do that, we have imposed a search radius constraint that should be satisfied by

more surprising that the German legislator then, in Section 33g of the Act against Restraints of Competition (Gesetz gegen Wettbewerbsbeschränkungen, GWB) set forth a separate

Cost-Benefit Analysis of Construction Information Management System Implementation: Case Study. Impact of BIM-enabled design-to-fabrication on

Figure 5-1: Evolution of average demand and delays from July 2007 onwards This reduction of airport demand at both JFK and EWR between 2007 and 2010 is primarily due, we believe, to