280 likes | 418 Views
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.
E N D
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
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!
Week 1 Week 2 Week 3 Week 4 Week 5 Week 6 Week 7 Period 1 0 vs 1 0 vs 2 4 vs 7 3 vs 6 3 vs 7 1 vs 5 2 vs 4 Period 2 2 vs 3 1 vs 7 0 vs 3 5 vs 7 1 vs 4 0 vs 6 5 vs 6 Period 3 4 vs 5 3 vs 5 1 vs 6 0 vs 4 2 vs 6 2 vs 7 0 vs 7 Period 4 6 vs 7 4 vs 6 2 vs 5 1 vs 2 0 vs 5 3 vs 4 1 vs 3 Sports scheduling . Regin’s Round Robin Tournament model
Matrix modelling • Matrix models are very common in other applications • Even if the matrix is not so obvious in the problem specification
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 Example: warehouse location
Open 0..1 0..1 0..1 0..1 Warehouse Supply 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Store 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Warehouse Matrix model: variables
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 Open 0..1 0..1 0..1 0..1 Warehouse Supply 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Store 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Warehouse Matrix model:constraints
Open 0..1 0..1 0..1 0..1 Warehouse Supply 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Store 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Matrix model: spot the difference! =1 =1 … <c1 <c2 …
Load 0..l 0..1 0..1 0..1 Periods Sched 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Course 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 0..1 Matrix model: spot the difference! =1 =1 … l<<d l<<d …
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
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, …
Why matrix model? • Ease of problem statement • Side constraints, variable indexing, … • Improved constraint propagation • Symmetry breaking, indistinguishable values, linear models, … Suggests two lines of attack • Matrix operations should become first class objects in constraint programming languages. • MATLAB should be extended so it is a constraint modelling language
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? Common constraint types
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
Steel mill slab design • 3 possible slab sizes (1, 3 or 4), 9 orders • 5 colours, but only 2 allowed on any one slab 3 2 2 1 1 1 1 1 1 a b c d e f g h i
Example solution 2 h 3 1 e 2 1 b f a 1 1 1 1 g c d i (size 4) (size 3) (size 3) (size 1) (size 1) (size 1)
Matrix model for the slab design problem 3 2 2 1 1 1 1 1 1 oa ob oc od oe of og oh oi Col sum=1, row sum<slab size Col sum=1, row sum<2
Example solution 3 2 2 1 1 1 1 1 1 oa ob oc od oe of og oh oi s1 = 4, s2 = 3, s3 = 3, s4 = 3
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
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
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
Symmetry-breaking • Lexicographically ordering rows breaks all row symmetry • Lexicographically ordering cols breaks all col symmetry
Symmetry-breaking problem • Lexicographically ordering both rows & cols does not break all row & col symmetry: Other techniques for dealing with symmetry like SBDS also have problems as there are n! symmetries
Indistinguishable values • Values in problem can be indistinguishable • In progressive party problem: Assign(guest,period)=host But host boats of same size are indistinguishable • Channel into 0/1 matrix with extra dimension Assign3(guest,period,host)=0/1 • Value symmetry => variable symmetry
Transforming value symmetry into variable symmetry • Suppose all values are indistinguishable a b c d 1 0 0 0 0 1 a c {b, d} 0 1 0 0 0 1 Now the rows are indistinguishable So we are in a previously solved case!
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
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, …