best practice in mathematical modeling

31
Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture of T. Hürlimann 1 Tony Hürlimann Department of Informatics Bd. Perolles 90 1700 Freiburg [email protected] Best Practice in Mathematical Modelling Chap 1: Introduction Master Course in Decision Support at the Department of Informatics, University of Fribourg, 2015

Upload: university-of-fribourg

Post on 13-Jan-2017

755 views

Category:

Education


1 download

TRANSCRIPT

Page 1: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture of T. Hürlimann 1

Tony Hürlimann

Department of InformaticsBd. Perolles 901700 [email protected]

Best Practice inMathematical Modelling

Chap 1: Introduction

Master Course in Decision Supportat theDepartment of Informatics, University of Fribourg, 2015

Page 2: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 2

Chap 1: Introduction

Main Objectives of the Course Learn to read and write mathematical indexed

notation To be able to read and

write the code on the right Modelling: skills to translate real problems into

mathematical notation Given a problem in human language, write it in

mathematics. Implement the model in a modelling language

and solve it on a computer We shall use and extensively learn the modeling

language LPL to implement the models.

Chap 1: Introduction

Page 3: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 3

Chap 1: Introduction

Overview of this First Lecture Goal: Relax and listen to the lecture

No need to understand all the formalisms right now

Motivation to use mathematics is given A game Slitherlink Route planning

Mathematics – Reality: strange relation ? Coloring vertices versus scheduling exams

„Real“ Examples Work schedule for bus drivers Cutting of paper rolls Location and logistics (supply-chain) Rostering: Work schedule of 800 persons at the

Zurich airport !

Page 4: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 4

Chap 1: Introduction

A 2-Persons GameProblem : Two players play the following number game:

Each chooses (secretly) a positive number. The numbers are then

uncovered at the same time and compared. If the numbers are equal, neither of the players will get a payoff. If the numbers differ by one, then the player who has chosen the higher number obtains the sum of both, otherwise the player with the smaller number obtains the smaller of both. The play is repeated endlessly. Which number and how often should a player choose a number in each round?

1 1 4 1 2 3 2 1 2 2 1 3 1 4 1 2 5 2 4 2 3 4 4 2 1 2 3 1 4 2 3 1 5 2 4 5 3 5 4 1 1 1 3 1 3 1 4 3 4 4 3 1 3 3 5 3 5 1 3 2 1 4 3 5 3 3 5 3 2 1 4 5 4 4 1 1 5 4 3 5 3 2 1 3 2 5 1 2 3 5 1 1 2 1 3 3 2 1 3 4 4 1 2 1 1 4 4 2 3 3 4 3 2 4 4 1 1 1 1 1 3 1 3 2 2 4 2 2 3 3 5 2 3 2 4 4 3 4 2 3 3 5 3 1 3 2 1 1 3 3 1 5 4 3 5 2 3 4 3 3 1 1 5 2 1 5 2 1 1 5 3 3 1 3 1 2 5 3 2 3 5 2 2 3 1 4 4 1 5 3 1 5 2 1 4 3 1 3 5 3 2 3 1 1 3 5 3 3 3 1 4 1 1 5 4 3 5 1 1 1 1 2 2 2 1 3 3 3 3 4 3 2 2 3 5 3 2 3 3 5 2 2 3 4 3 1 3 4 4 5 1 4 2 2 3 3 5 1 1 1 5 2 5 4 5 2 2 4 1 1 1 3 2 1 1 4 2 2 3 2 1 2 1 4 2 4 3 3 5 1 2 5 3 1 1 1 2 2 1 1 3 4 3 1 5 1 3 1 2 3 1 4 3 2 1 5 1 1 1 1 4 5 1 1 4 5 3 1 3 4 5 3 3 5 4 4 5 5 4 4 1 2 2 1 4 2 4 5 1 5

Table of Numbers from which you can choose (optimally) [ above we choose from the second row ] : (This table is hidden from the class)

4 1 12 1 4 4 32 3

How was this table built and why should this strategy be „optimal“? (see next page!)

Let us play in the class room (interactively I show the following number one by one)The students guess one number and I discover one, and so on...

Page 5: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 5

Chap 1: Introduction

The 2-Persons Game: A Mathematical Formulation

model GAME; set i, j := 1..100; parameter p{i,j} := if(i>j+1,-j , i=j+1,i+j , i=j-1,-i-j, i<j-1,i); variable x{i} "Strategy"; constraint R: sum{i} x = 1; maximize gain: min{j}(sum{i} p*x); end

Choose number 1 with frequency 24.75% Choose number 2 with frequency 18.81% Choose number 3 with frequency 26.73% Choose number 4 with frequency 15.84% Choose number 5 with frequency 13.86% Never choose another number ! (Both players can follow this strategy, then in the long run nobody will win!)

The table on the previous page was built on these frequencies !

The optimal strategy of a player is:

Mathematical Formulation

Computer-executable Formulation

Coded in the mathematical modeling language LPL

SEE: lpl.unifr.ch/puzzles/Solver.jsp?name=gameh

Page 6: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 6

Chap 1: Introduction

Another Game : Sudoku I

model sudoku; set i,j,k; set h,g; parameter P{i,j}; parameter S;

binary variable x{i,j,k}; constraint N{i,j}: sum{k} x = 1; R{i,k}: sum{j} x = 1; C{j,k}: sum{i} x = 1; B{h,g,k}: sum{h1 in h,g1 in g} x[(h-1)*S+h1,(g-1)*S+g1,k] = 1; F{i,j,k|P[i,j]=k}: x = 1; solve; end

Model with:15’625 binary variables 2’787 linear constraints

SEE: lpl.unifr.ch/puzzles/Solver.jsp?name=sudoku

A 25x25 Sudoku:

Page 7: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 7

Chap 1: Introduction

And this is a complete mathematical description of the Sudoku game :

Another Game : Sudoku II

Page 8: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 8

Chap 1: Introduction

Another Game like Sudoku : Slitherlink

Find a simple loop that follows the borders of the cells in a way that the number inside a cell represents how many of its four sides are segments in the loop. If the cell is empty, then the number does not matter.

A Slitherlink Puzzle…. .... and its solution

Page 9: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 9

Chap 1: Introduction

Slitherlink: Solution

Try to solve it: Special configuration: 1 at a

corner, 3 and 0! The 2 in a bottom line The 3 in a corner etc.

In the Internet you can run various puzzles:

Solution using a mathematical model!

SEE: lpl.unifr.ch/puzzles/Solver.jsp?name=slitherlink

Page 10: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 10

Chap 1: Introduction

A Practical Small Example:Manufacturing Cans

Manufacturing cans with minimal usage of material How should the relation be between height and width of a can for a

given volume ?

h=height , r=radius

Su

rfa

ce

r=radius

With a radius of 0.8dm the height will be only 0.5dm and the surface then is 6.5dm2, hence 18% higher than in its minimum !

We suppose: The surface is directly proportional to the amount of material used.

Exercise: Verify the solution!

Page 11: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 11

Chap 1: Introduction

Mathematics is everywhere

A modern application is: Ciphering while transfering electronic money: Multipling two large number is easy ! Factoring a large number into its (two) prime numbers is difficult !

One can exploit this asymmetry (easy—difficult) in cryptography

Everybody can (with a little patience) do the following multiplication : 193'707'721 * 761'838'257'287 = 147'573'952'589'676'412'927 !

But: The mathematicien Cole (1861–1926) spent his weekends of 3 years to factor the number 267-1 = 147'573'952'589'676'412'927 into its two prim factors:193'707'721 und 761'838'257'287.

This assymetry in the complexity is used in real-life cryptography, to cipher a text in a simple way. However, the text cannot be easily deciphered !

If you know the two prime factors, you can decipher a text !If you know only the result of the multiplication, you can encipher !

Prime numbers have been considered „useless“ for centuries.Our modern money economy would collapse without them !

example

Page 12: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 12

Chap 1: Introduction

Mathematics: How does it work?An Abstract Problem

„Abstract“ Problem: Vertex coloring Graph consists of vertices and edges Example: net with locations and routes

At least 4 colors are necessary

An abstract problem (just baublery !?)

Is this useful? Well ....

Page 13: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 13

Chap 1: Introduction

Mathematics: How does it work?A Concrete Application

Exams schedule A number of exams, a number of students How to find a Conflict-free Schedule!

Time Window 1 : Exams No.: 1 6 Time Window 2 : Exams No.: 3 4 8 Time Window 3 : Exams No.: 2 9 Time Window 4 : Exams No.: 5 7 10

Correspondence Mathematics – „Reality“ :

Vertex = Exam Edge = Collision Color = Time window Number of colors = Length of schedule

Page 14: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 14

Chap 1: Introduction

Mathematics: How does it work?Another Concrete Application

Use memory for variable in a program 10 variables used in a program at different life-time How much memory to use ?

Memory location 1 : var 1, 3, 10Memory location 2 : var 2, 4, 6, 7, 9Memory location 3 : var 5, 8

Correspondence Mathematics – „Reality“ :

Vertex = program variable Edge = Overlap life-time Color = Memory location Number of colors = Memory size

Page 15: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 15

Chap 1: Introduction

Mathematics: How does it work?Still another Concrete Application

Semaphores at a crossroads Number of traffic lanes, Number of crossing roads Collision-free plan of semaphore phases ?

Time window 1 : Lanes No.: AB BA DC EB EC EDTime window 2 : Lanes No.: AD BD DBTime window 3 : Lanes No.: BC DA EATime window 4 : Lanes No.: AC

Correspondence Mathematics – „Reality“ :

Vertex = Traffic Lane Edge = Collision Color = Time Window Number of colors = Length of phases

Page 16: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 16

Chap 1: Introduction

Alternative Solution

Time window 1 : Lanes No.: AB AC AD Time window 2 : Lanes No.: BA BC BD ED Time window 3 : Lanes No.: DA DB DC Time window 4 : Lanes No.: EA EB EC

Correspondence Mathematics – „Reality“ :

Vertex = Traffic Lane Edge = Collision Color = Time window Number of colors = Length of phases

Semaphores at a crossroads Number of traffic lanes, Number of crossing roads Collision-free plan of phases ?

A more „equilibrarted“ solution

Page 17: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 17

Chap 1: Introduction

For Larger Problems:We need smart Mathematics and fast Computers

More difficult to solve.

Needscomputer power

Needs math. methods !

100 Exams 24 Time windows

Graph density 20%

Page 18: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 18

Chap 1: Introduction

Vertex Coloring: A Mathematical Model

We shall go through this model later in the course !

This model is a first approach. It is no really „smart“ for larger problems

Page 19: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 19

Chap 1: Introduction

Scheduling Bus Drivers:The Problem

Number of excursions planed Monday: 14, Tuesday: 12, Wednesday: 18, Thursday:

16, Friday: 15, Saturday: 16, Sunday: 19

Problem: How many drivers need to be hired? At least 19 (see Sunday)!

Well! It depends on the working plan maximally 5-days working 2 consecutive days off

Page 20: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 20

Chap 1: Introduction

7 working contracts (5 days consecutive) : S1-S7------------------------------------------------------ Mo Tu We Th Fr Sa Su S1 * * * * * S2 * * * * * S3 * * * * * S4 * * * * * S5 * * * * * S6 * * * * * S7 * * * * *

Unknown quantities(Number of drivers under the 7 different working contracts)------------------------------------------------------ S1 S2 S3 S4 S5 S6 S7 x1 x2 x3 x4 x5 x6 x7

Operation schedule(Number of drivers per day)------------------------------------------------------Mo : x1 + x4 + x5 + x6 + x7 ≥ 14Tu : x1 + x2 + x5 + x6 + x7 ≥ 12. . .

model Plans "Schedule of Drivers"; integer variable x1; x2; x3; x4; x5; x6; x7; constraint mon: x1 + x4 + x5 + x6 + x7 >= 14; tue: x1 + x2 + x5 + x6 + x7 >= 12; wen: x1 + x2 + x3 + x6 + x7 >= 18; thu: x1 + x2 + x3 + x4 + x7 >= 16; fri: x1 + x2 + x3 + x4 + x5 >= 15; sat: x2 + x3 + x4 + x5 + x6 >= 16; son: x3 + x4 + x5 + x6 + x7 >= 19; minimize obj: x1 + x2 + x3 + x4 + x5 + x6 + x7;end

Mathematical Model

Solution on a computer

S1 = work from Monday to Friday, then 2 days offx1 = number of drivers working under contract S1

Scheduling Bus Drivers:The Formulation

Page 21: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 21

Chap 1: Introduction

2 Mo Tu We Th Fr Sa Su 1 14 14 2 19 19 19 19 19 33 drivers , 123 total salaryDEMAND 14 12 18 16 15 16 19Actual 14 14 19 19 19 19 19Overplus 0 2 1 3 4 3 0 ------------------------------------------ 3 Mo Di Mi Do Fr Sa So 1 3 3 3 3 2 11 11 3 16 16 16 16 16 30 drivers , 114 total salaryDEMAND 14 12 18 16 15 16 19Actual 14 14 19 16 16 16 19 Overplus 0 2 1 0 1 0 0 ------------------------------------------ 4 Mo Di Mi Do Fr Sa So 1 5 5 5 5 5 2 8 8 8 8 3 6 6 6 6 6 4 5 5 5 5 5 24 drivers , 112 total salaryDEMAND 14 12 18 16 15 16 19 Actual 14 13 18 16 16 16 19Overplus 0 1 0 0 1 0 0

5 Mo Di Mi Do Fr Sa So 1 3 3 3 3 3 2 7 7 7 7 3 2 2 4 9 9 9 9 9 5 6 6 6 27 drivers , 110 total salaryDEMAND 14 12 18 16 15 16 19Actual 14 12 18 16 15 16 19 Overplus 0 0 0 0 0 0 0 ------------------------------------------ 6 Mo Di Mi Do Fr Sa So 1 4 4 4 4 4 2 8 8 8 8 8 3 2 2 2 2 2 4 2 2 2 2 2 5 3 3 3 3 3 6 3 3 3 3 3 22 drivers , 110 total salaryDEMAND 14 12 18 16 15 16 19 Actual 14 12 18 16 15 16 19Overplus 0 0 0 0 0 0 0

5 Rostering systems with 2 to 6 different working contracts (schedules):

Scheduling Bus Drivers:Various Solutions

Page 22: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 22

Chap 1: Introduction

Cutting Material:The Problem

Given widths of the rolls: 152cm , 122cm , 102cm.

Demanded sizes (rectangles) : 20000 pieces of 24x 33 cm , 15000 pieces of 36x 80 cm , 5000 pieces of 29x100 cm 5000 pieces of 39x103 cm , 5000 pieces of 29x100 cm , 5000 pieces of 39x 93 cm 5000 pieces of 19x 75 cm , 15000 pieces of 29x 68 cm , 15000 pieces of 19x 29 cm

Conditions:• 2-stage Guillotine-cuts• First generate larger rectangles of length between 19 and 170cm (how?)• Rotatation of rectangles of 90º is ok.

Problem: How many and in what length should the larger rectangles be cut into and how should the final rectangles then be cut from them in order to minimize the waste ?

Page 23: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 23

Chap 1: Introduction

Case Study: Cutting SheetsSolution Approach

1. First generate a number of „interesting“ larger rectangles (the sheet patterns). Cut the demanded rectangles from these larger pieces of widths (102,122,152) and lengths [19..170], using dynamic programming. -- this is a well known and well studied problem: 2-stage unconstrained guillotine cuts from rectangles given a number of smaller rectangles.-- in the second step these rectangles are given as patterns.

2. Using these patterns, decide how many rectangles to cut from the rolls.-- the demanded rectangles must be produced.-- minimize the waste using linear optimization.

Decompose the problem into two sequential steps

Page 24: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 24

Chap 1: Introduction

Location & Transport LogisticsA Real Problem

Page 25: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 25

Chap 1: Introduction

Location & Transport LogisticsThe Model Context

Holcim – a large company – uses mathematical optimization in its strategic and operative logistics.

Problem: Decide where to produce and to pack ciment and in what quantities and how to transport it to the clients in order to minimize costs.

Solution: (1) The mathematical structure (the business logic) is easily formulated in pure mathematics (as a linear programming model). The data are read/written to/from databases. The whole model consists of more than 10‘000 variables and constraints and can be solved in two minutes on a current personal computer.(2) Build an easy-to-use interface to database on top of the model and the database interface.

Page 26: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 26

Chap 1: Introduction

Rostering (Airport of Zurich)The Problem

800 persons with different skills and contracts. 250 work shifts: Check-in (Swiss), announcement,

ticket controls, etc. Find a monthly plan (30 days): Who works at which

day in which shift ? Demand must be fulfilled Working laws and collective contracts must be observed

and the skills must match. Maximize „Satisfaction“ (fullfill workers wishes)

This is a current project with FH Winterthur+Software company+client at the airport ZH

Page 27: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 27

Chap 1: Introduction

Use a large mathematical optimization problem with 500‘000 variables 20‘000-40‘000 linear constraints

Such problems can be treated and „solved“ with current techniques of Operations Research.

To compare the size of the model above, look at this following small

trivial example with 2 variables and 2 linear constraints :

„My grandfather and grandmother are together 150 years old. Their ages differ by 4 years. How old are they?“

The model is :

(x = Age of grandfather, y = Age of grandmother)

The solution is :

Rostering (Airport of Zurich)The Solution Approach

Page 28: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 28

Chap 1: Introduction

Find an efficient way to „translate“ the problem into the „right“ mathematical structure (Modelling).

Use mathematical toolboxes to solve the problem: Operations Research develops powerful methods since 60 years (Solution Methods).

Implement the approach together with user-interfaces and data binding (Needs Programming).

Use fast computers (Hardware).

At the present time, 20 persons are in charge of planifying the schedules.

De

crea

sin

g im

po

rta

nce

!Rostering (Airport of Zurich)How to approach such a large problem

Page 29: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 29

Chap 1: Introduction

Day in month

Per

sons

Overtime (in 1/4 hours)Violates time constraint

Distance between shifts too shortviolates working contracts

Unsatisfying solution: Working time is partially massively exceeded !

Rostering (Airport of Zurich)Extract of a (not-so-good) solution

Does not fullfill a workers wishto get a free day on Tuesday

Worker 57 is on shiftno 79 on this Sunday

Page 30: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 30

Chap 1: Introduction

Better solution. However still violations of working laws.

Rostering (Airport of Zurich)Extract of a (better) solution

Page 31: Best Practice in Mathematical Modeling

Department of Informatics, University of Fribourg Best Practices in Mathematical Modelling : Lecture f T. Hürlimann 31

Chap 1: Introduction

Summary How to attack complex and real problems ?

For standard problems use standard software: Text processing, accounting, etc. „Packages of various industries“ ...

For relatively well structured problems use specialized software packages Time-tabling in high school, tour planing. Machine control processes

For complex decision problems no standard solution exists Schedules of all sorts

Layout-, Location- rostering-, processes-

Good Modeling skills are in high demand !Good Solution methods needed !Software skills: Rapid-Prototyping !Hardware: the faster the better !