matrix modelling alan m. frisch and ian miguel (york) brahim hnich, zeynep kiziltan (uppsala) toby...

28
Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Post on 20-Dec-2015

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Matrix Modelling

Alan M. Frisch and Ian Miguel (York)

Brahim Hnich, Zeynep Kiziltan (Uppsala)

Toby Walsh (Cork)

Page 2: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

What is matrix modelling?

Constraint programs with one or more matrix of decision vars

Common patterns in such models Extend modelling

languages & solvers to exploit them

Page 3: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Obvious matrix models

Often the problem has a matrix in the specification

Many timetabling and scheduling problems

Mike Trick schedules the College baseball league using a matrix model!

Page 4: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Sports scheduling.

0 vs 72 vs 72 vs 60 vs 41 vs 63 vs 54 vs 5Period 3

0 vs 5

1 vs 4

3 vs 7

Week 5

3 vs 4

0 vs 6

1 vs 5

Week 6

1 vs 31 vs 22 vs 54 vs 66 vs 7Period 4

5 vs 65 vs 70 vs 31 vs 72 vs 3Period 2

2 vs 4 3 vs 64 vs 70 vs 20 vs 1Period 1

Week 7Week 4Week 3Week 2Week 1

Regin’s Round Robin Tournament model

Page 5: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Matrix modelling

Matrix models are very common in other applications Even if the matrix is not

so obvious in the problem specification

Page 6: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Example: warehouse location

Supply chain management How many warehouses do

we build and where do we build them?

One in the middle of the US One on each coast …

Problem (and solution) taken from OPL manual

Page 7: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Matrix model: variables

0..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..1

Store

WarehouseSupply

0..1 0..1 0..1 0..1

OpenWarehouse

Page 8: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Matrix model:constraints

Each store has a warehouse: row sum Supply=1

Warehouse capacity:column sum Supply <= ci

Channelling constraints:Supply[i,j]=1 implies Open[i]=1

Optimization variable:Cost = matrix sum

Supply[i,j]*distcost[i,j] + opencost * row sum Open

0..1 0..1 0..1 0..1

Open Warehouse

0..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..1

Store

WarehouseSupply

Page 9: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Matrix model: spot the difference!

0..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..1

Store

WarehouseSupply

0..1 0..1 0..1 0..1

Open

=1=1…

<c1 <c2 …

Page 10: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Matrix model: spot the difference!

0..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..10..1 0..1 0..1 0..1

Course

PeriodsSched

0..l 0..1 0..1 0..1

Load

=1=1…

l<<d l<<d …

Page 11: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Balance academic curriculum problem

Very similar matrix model Channelling now to

weighted sum not 0/1 var Optimization var changes

Matrix modelling Exploiting these patterns Provide high level primitives

To state such problems compactly

To reason effectively

Page 12: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Diversity of matrix models

Combinatorial problems BIBDs, magic squares,

projective planes, … Design

Rack configuration, template and slab design, …

Scheduling Classroom, social golfer, …

Assignment Warehouse location,

progressive party, …

Page 13: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Why matrix model?

Ease of problem statement Side constraints, variable indexing, …

Improved constraint propagation Symmetry breaking, indistinguishable values, linear

models, …

Suggests two lines of attack1. Matrix operations should become first class objects in constraint

programming languages. 2. MATLAB should be extended so it is a constraint modelling language

Page 14: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Common constraint types

Row or column sum Weighted row/column

sum Single non-zero entry Matrix sum Scalar product Channelling Ordering rows/matrices

This pretty much describes all the examples!

These constraints should be provided as language primitives?

Efficient and powerful propagators developed?

Page 15: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Ease of problem statement

Steel mill slab design Nasty “colour” constraint

Stops it being simple knapsack problem

Channel into matrix model Colour constraint easily and

efficiently stated

Page 16: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Steel mill slab design

23

1 1 1 1 12

1

• 3 possible slab sizes (1, 3 or 4), 9 orders• 5 colours, but only 2 allowed on any one slab

a b c d e f g h i

Page 17: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Example solution

23

111

1

1

1

f

g i

e

c d

b

h

a

(size 4) (size 3) (size 1)(size 1)(size 3) (size 1)

2

Page 18: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Matrix model for the slab design problem

23

1 1 1 1 12

1oa ob oc od oe of og oh oi

oa ob oc od oe of og oh oi

s1 1

s2 1

Red Green Blue Orange Brown

s1 1

s2 1

…Col sum=1, row sum<slab size

Col sum=1, row sum<2

Page 19: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Example solution

23

1 1 1 1 12

1oa ob oc od oe of og oh oi

oa ob oc od oe of og oh oi

s1 0 0 0 0 0 0 1 1 1

s2 1 0 1 0 0 0 0 0 0

s3 0 1 0 0 0 0 0 0 0

s4 0 0 0 1 1 1 0 0 0

… 0 0 0 0 0 0 0 0 0

Red Green Blue Orange Brown

s1 0 0 0 1 1

s2 1 1 0 0 0

s3 0 1 0 0 0

s4 0 0 1 1 0

… 0 0 0 0 0

s1 = 4, s2 = 3, s3 = 3, s4 = 3

Page 20: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Improved propagation

Warehouse location Could have used 1-d matrix,

Supply(store)=warehouse But then warehouse capacity

constraint Difficult to state

Need to sum demand from all stores such that Supply(store)=warehouse

Difficult to propagate

Page 21: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Improved propagation

Warehouse location Instead of 1-d matrix,

Supply(store)=warehouse We used 2-d matrix,

Supply(store,warehouse)=0/1

2-d matrix allows us to use purely linear constraints

=> can even use LP solver

Page 22: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Symmetry breaking

Often rows or columns (or both) are symmetric

All weeks (cols) can be permuted in a timetable

All slabs (rows) of same size can be permuted

Lex order rows/cols Can do both if row and cols

are both symmetric Efficient O(n) GAC

algorithm, patent pending

Never work with children or animals

Page 23: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

• Lexicographically ordering rows breaks all row symmetry

• Lexicographically ordering cols breaks all col symmetry

Symmetry-breaking

Page 24: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

• Lexicographically ordering both rows & cols does not break all row & col symmetry:

0 1

1 0

1 0

0 1

0 1

1 0

Symmetry-breaking problem

Other techniques for dealing withsymmetry like SBDS also have problems as there are n! symmetries

Page 25: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Indistinguishable values

Values in problem can be indistinguishable

In progressive party problem:Assign(guest,period)=hostBut host boats of same size are

indistinguishable Channel into 0/1 matrix with

extra dimensionAssign3(guest,period,host)=0/1 Value symmetry => variable

symmetry

Page 26: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Transforming value symmetry into variable symmetry

Suppose all values are indistinguishable

{b, d}ca

100

010

100

001a

b

c

d

Now the rows are indistinguishableSo we are in a previously solved case!

Page 27: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Variable indexing

Use variables to index into arrays E.g. channelling in progressive party problem

Assign3(guest,period,Assign(guest,period))=1 compared to

Assign3(guest,period,host)=1 iff Assign(guest,period)=host

Reduces number of constraints from cubic to quadratic

Hooker (and others) argue that such indexing is one of the significant advantages CP has over IP

Page 28: Matrix Modelling Alan M. Frisch and Ian Miguel (York) Brahim Hnich, Zeynep Kiziltan (Uppsala) Toby Walsh (Cork)

Conclusions

Matrix models common Common types of constraints posted on

matrices Row/column sum, symmetry breaking,

channelling, … Matrix operations should be made first-class

objects in modelling languages MATLAB, EXCEL, …