Top Banner
620-362 Applied Operations Research (Xpress 620-362 Applied Operations Research (Xpress MP MP lecture) lecture) 1 Semester 2, 2007 Semester 2, 2007 Introduction to Introduction to Modelling with Xpress Modelling with Xpress MP MP 620-362 620-362 Applied Operations Research Applied Operations Research Department of Mathematics and Department of Mathematics and Statistics Statistics The University of Melbourne The University of Melbourne This presentation has been made in accordance with the provisions of Part VB of the copyright act for the This presentation has been made in accordance with the provisions of Part VB of the copyright act for the teaching purposes of the University. teaching purposes of the University. For use of students of the University of Melbourne enrolled in the subject 620-362. For use of students of the University of Melbourne enrolled in the subject 620-362. Copyright© 2004 by Natashia Boland and Heng-Soon Gan Copyright© 2004 by Natashia Boland and Heng-Soon Gan
51

620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

Dec 19, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 11 Semester 2, 2007Semester 2, 2007

Introduction to Modelling with Introduction to Modelling with XpressXpressMPMP

620-362 620-362

Applied Operations ResearchApplied Operations Research

Department of Mathematics and StatisticsDepartment of Mathematics and Statistics

The University of MelbourneThe University of Melbourne

This presentation has been made in accordance with the provisions of Part VB of the copyright act for the This presentation has been made in accordance with the provisions of Part VB of the copyright act for the teaching purposes of the University.teaching purposes of the University.

For use of students of the University of Melbourne enrolled in the subject 620-362.For use of students of the University of Melbourne enrolled in the subject 620-362.

Copyright© 2004 by Natashia Boland and Heng-Soon GanCopyright© 2004 by Natashia Boland and Heng-Soon Gan

Page 2: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 22 Semester 2, 2007Semester 2, 2007

ContentsContents

• Getting started with Xpress-IVE and Mosel LanguageGetting started with Xpress-IVE and Mosel Language– XpressXpressMPMP, Xpress-IVE and Mosel, Xpress-IVE and Mosel– Using Xpress-IVEUsing Xpress-IVE– General Mosel Program StructureGeneral Mosel Program Structure

• Example 1Example 1– Bin-packing Example (general structure demonstration, Bin-packing Example (general structure demonstration,

forall, sum, writeln, getobjval, getsol, variable types, if-then-forall, sum, writeln, getobjval, getsol, variable types, if-then-else)else)

– Output information (B&B tree, MIP search, Stats etc.) and Output information (B&B tree, MIP search, Stats etc.) and DebuggingDebugging

• Example 2 Example 2 – Staff Rostering Example (parameters…end-parameters, Staff Rostering Example (parameters…end-parameters,

working with external input/output data, do…end-working with external input/output data, do…end-do,formatted output,procedure…end-procedure)do,formatted output,procedure…end-procedure)

Page 3: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 33 Semester 2, 2007Semester 2, 2007

Getting StartedGetting Started

with Xpress-IVE and Mosel with Xpress-IVE and Mosel languagelanguage

Page 4: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 44 Semester 2, 2007Semester 2, 2007

Optimisation….Optimisation….

Real WorldReal World

Mathematical Model

Mathematical Model

Computer Program

Computer Program

Problem definition & data for parameters.

Model and parameters.

Output (for verification purposes).

NOTE: We will be using XpressMP

NOTE: We will be using XpressMP

Page 5: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 55 Semester 2, 2007Semester 2, 2007

Glossary of termsGlossary of terms

• Program CodeProgram Code– This is a type-written code to translate your mathematical This is a type-written code to translate your mathematical

model to a format readable by Xpressmodel to a format readable by XpressMPMP..

• Binary CodeBinary Code– This is a generic format of your program code, coded in 0’s This is a generic format of your program code, coded in 0’s

and 1’s, readable by any computer applications.and 1’s, readable by any computer applications.

• CompileCompile– This is when XpressThis is when XpressMPMP converts the program code to a binary converts the program code to a binary

code.code.

• ArrayArray– This is how you would express and store a list of items in a This is how you would express and store a list of items in a

program code.program code.

Page 6: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 66 Semester 2, 2007Semester 2, 2007

Glossary of terms (cont’d)Glossary of terms (cont’d)

• MemoryMemory– This is where the computer stores your model’s information, This is where the computer stores your model’s information,

such as input parameters. such as input parameters. – Information stored in memory can be retrieved during the Information stored in memory can be retrieved during the

execution of your program code.execution of your program code.

• Mathematical operatorsMathematical operators

• DebuggingDebugging– This is a term used to describe the procedure of finding This is a term used to describe the procedure of finding

errors in your program code.errors in your program code.– The program code errors are referred to as “bugs”.The program code errors are referred to as “bugs”.

• LoopingLooping– This term is used when a repetitive task is performed.This term is used when a repetitive task is performed.

Operator Symbol Used Operator Symbol UsedAdd + Subtract -

Multiply * Exponent ("Power of") ^Divide /

Page 7: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 77 Semester 2, 2007Semester 2, 2007

XpressXpressMPMP, Xpress-IVE and Mosel, Xpress-IVE and Mosel

• XpressXpressMPMP: : – Large-scale optimisation software developed by Dash (Large-scale optimisation software developed by Dash (http://http://

www.dashoptimization.comwww.dashoptimization.com))

• Xpress-IVE: Xpress-IVE: – IVE stands for IVE stands for IInteractive nteractive VVisual isual EEnvironmentnvironment– Provides a friendly user interface for model coding, code Provides a friendly user interface for model coding, code

debugging and result display. (Windows environment)debugging and result display. (Windows environment)– Student versions can be downloaded from Student versions can be downloaded from http://http://

www.dashoptimization.comwww.dashoptimization.com (It’s FREE!) (It’s FREE!)

• Xpress-Mosel: Xpress-Mosel: – a programming language that translates your mathematical a programming language that translates your mathematical

programs/algorithms to a format readable by Xpress programs/algorithms to a format readable by Xpress Optimiser.Optimiser.

– File extension: *.mosFile extension: *.mos

Page 8: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 88 Semester 2, 2007Semester 2, 2007

Coding WindowCoding Window

Project Bar

Project Bar

Run BarRun Bar

Information BarInformation Bar

Run modelRun model

Compile modelCompile model

Switch between models

Switch between models

Execution optionsExecution options

Page 9: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 99 Semester 2, 2007Semester 2, 2007

Using Xpress-IVEUsing Xpress-IVE

• We have the option to show or hide line We have the option to show or hide line numbers in our Mosel code.numbers in our Mosel code.

Page 10: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 1010 Semester 2, 2007Semester 2, 2007

The (balanced) transportation problemThe (balanced) transportation problem

• Recall the following problem:Recall the following problem:

((Adapted from Section 7.1, pg. 360, Winston – 2004Adapted from Section 7.1, pg. 360, Winston – 2004))

Powerco has 3 electric power plants that supply the Powerco has 3 electric power plants that supply the needs of 4 cities. The supply limit, demand amount and needs of 4 cities. The supply limit, demand amount and the unit transportation costs are given as follows:the unit transportation costs are given as follows:

Formulate an LP to minimise the cost of meeting each Formulate an LP to minimise the cost of meeting each city’s power demand.city’s power demand.

From City 1 City 2 City 3 City 4 Supply (million kWh)Plant 1 $8 $6 $10 $9 35Plant 2 $9 $12 $13 $7 50Plant 3 $14 $9 $16 $5 40Demand (million kWh) 45 20 30 30

To

Page 11: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 1111 Semester 2, 2007Semester 2, 2007

The (balanced) transportation problem (cont’d)The (balanced) transportation problem (cont’d)

Balanced Transportation Balanced Transportation Problem (BTP)Problem (BTP)

jix

jdx

isxts

xcMinimise

ij

ji

ij

ij

ij

i jijij

,,0

,

,..

3

1

4

1

3

1

4

1

j

i

cij

point demand

topoint supply from

cost portation unit trans

i

sipoint supply

oflimit supply

j

d j

point demand

ofamount demand

j

i

xij

point

demand topoint supply

ed transportunits ofnumber

Page 12: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 1212 Semester 2, 2007Semester 2, 2007

General Mosel Program StructureGeneral Mosel Program Structure

WARNING: Mosel is WARNING: Mosel is case-sensitivecase-sensitive!!

Page 13: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 1313 Semester 2, 2007Semester 2, 2007

ModulesModules

Page 14: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 1414 Semester 2, 2007Semester 2, 2007

DeclarationsDeclarations

declarationsdeclarationsSet1 Set1 = 1..10= 1..10Set2 Set2 = 1..5= 1..5

Var1: Var1: mpvarmpvarVar2: Var2: array(array(Set1Set1) of mpvar) of mpvarVar3: Var3: array(array(Set1,Set2Set1,Set2) of mpvar) of mpvar

InputParam1: InputParam1: realrealInputParam2: InputParam2: array(array(Set1Set1) of integer) of integerInputParam3: InputParam3: array(array(Set1,Set2Set1,Set2) of real) of real

end-declarationsend-declarations

Page 15: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 1515 Semester 2, 2007Semester 2, 2007

Declarations (cont’d)Declarations (cont’d)

• For BTP…For BTP…

Page 16: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 1616 Semester 2, 2007Semester 2, 2007

InitialisationInitialisation

declarationsdeclarationsSet1 Set1 = 1..3= 1..3Set2 Set2 = 1..2= 1..2

InputParam1: InputParam1: array(array(Set1Set1) of integer) of integerInputParam2: InputParam2: array(array(Set1,Set2Set1,Set2) of real) of realInputParam3: InputParam3: array(array(Set2,Set2,Set2Set2,Set2,Set2) of real) of real

end-declarationsend-declarations

! Initialise input parameters! Initialise input parametersInputParam1InputParam1:::: [ [11,,22,,33]] ! initialisation for InputParam1! initialisation for InputParam1InputParam2InputParam2:::: [ [1111,,1212,,2121,,2222,,3131,,3232] ] ! initialisation for InputParam2! initialisation for InputParam2InputParam3InputParam3:::: [ [111111,,112112,,121121,,122122,,211211,,212 212 ,,221221,,222222] ] ! initialisation for InputParam3! initialisation for InputParam3

NOTE: NOTE: Data input Data input from filefrom file is another method of parameter initialisation. is another method of parameter initialisation. This topic will be covered later in the course.This topic will be covered later in the course.

Page 17: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 1717 Semester 2, 2007Semester 2, 2007

Initialisation (cont’d)Initialisation (cont’d)

• For BTP…For BTP…

Page 18: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 1818 Semester 2, 2007Semester 2, 2007

Objective FunctionObjective Function

ObjectiveNameObjectiveName:=:= functionfunction

NOTE:NOTE:““function”function” can be be expressed in can be be expressed in a format very similar to a mathe-a format very similar to a mathe-matical function, e.g. the objective for BTPmatical function, e.g. the objective for BTP

can be expressed in Mosel ascan be expressed in Mosel asTotalCostTotalCost:=:= sum(sum(i i inin SUPPLY, j SUPPLY, j inin DEMAND DEMAND) ) cc((i,ji,j))**xx((i,ji,j))

NOTE: Declaration is not necessary for TotalCost. NOTE: Declaration is not necessary for TotalCost.

3

1

4

1i jijijxcTotalCost

Page 19: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 1919 Semester 2, 2007Semester 2, 2007

ConstraintsConstraints

The following constraintThe following constraint

can be expressed in Mosel ascan be expressed in Mosel as

forall(forall(j j inin SET1 SET1)) sum(sum(i i inin SET2 SET2)) x x((i,ji,j) ) <= 1<= 1

wherewhere

SET1 and SET2 are range sets and x(i,j) is a two-SET1 and SET2 are range sets and x(i,j) is a two-dimensional decision variable.dimensional decision variable.

jxn

iij

,11

Page 20: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 2020 Semester 2, 2007Semester 2, 2007

Constraints (“forall” loop description)Constraints (“forall” loop description)

• The idea behind a “forall” loop:The idea behind a “forall” loop:– Consider the following constraints (specific version):Consider the following constraints (specific version):

– The corresponding generic version is The corresponding generic version is

nixi ,...,2,1,1

1

1

1

1

1

2

1

n

n

x

x

x

x

Page 21: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 2121 Semester 2, 2007Semester 2, 2007

Constraints (“forall” loop description)Constraints (“forall” loop description)

– If “forall” If “forall” does notdoes not exist, you will have to type in exist, you will have to type in every single constraint every single constraint (n(n times times)) expressed in the expressed in the specific version of the constraint, i.e.specific version of the constraint, i.e.

xx((11)) <= 1<= 1

xx((22)) <= 2<= 2

..

..

xx((nn)) <= 2<= 2– Fortunately, “forall” loop can simplify this task. We Fortunately, “forall” loop can simplify this task. We

only need the following line of codeonly need the following line of code

forall(forall(i i inin SET SET)) x x((ii) ) <= 1<= 1

where where SETSET= 1..n= 1..n

Page 22: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 2222 Semester 2, 2007Semester 2, 2007

Constraints (cont’d)Constraints (cont’d)

……and the following constraintand the following constraint

can be expressed in Mosel as can be expressed in Mosel as

forall(forall(i i inin SET1 SET1, , j j inin SET2 | i SET2 | i << j j)) x x((i,ji,j)) <= 1<= 1

……and if x(i,j) is a binary variable (0-1 variable), then the following and if x(i,j) is a binary variable (0-1 variable), then the following constraint must be added:constraint must be added:

forall(forall(i i inin SET1 SET1, , j j inin SET2 SET2) ) xx((i,ji,j)) is_binaryis_binary

When the constraint above is not stated, When the constraint above is not stated, xxijij is is by defaultby default a non- a non-

negative real number. If negative real number. If xxijij is an integer variable, then is an integer variable, then is_integeris_integer

should replace should replace is_binaryis_binary in the above constraint. in the above constraint.

jixij ,1

Page 23: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 2323 Semester 2, 2007Semester 2, 2007

Constraints (cont’d)Constraints (cont’d)

• For BTP…For BTP…

jix

jdx

isxts

xcMinimise

ij

ji

ij

ij

ij

i jijij

,,0

,

,..

3

1

4

1

3

1

4

1

Page 24: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 2424 Semester 2, 2007Semester 2, 2007

This is the easy bit:This is the easy bit:

If the objective function, If the objective function,

say , is to be say , is to be

minimisedminimised, then the following statement is , then the following statement is needed:needed:

minimiseminimise((TotalCostTotalCost))

Optimisation StatementOptimisation Statement

3

1

4

1i jijijxcTotalCost

Page 25: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 2525 Semester 2, 2007Semester 2, 2007

OutputOutput

To display the objective value:To display the objective value:

writelnwriteln((“Objective value is ”“Objective value is ”,, getobjvalgetobjval,, “.”“.”))

The output is “Objective value is ##.”, The output is “Objective value is ##.”, displayed at the “Output/Input” pane of the displayed at the “Output/Input” pane of the Run Bar.Run Bar.

To display the value taken by a decision variable:To display the value taken by a decision variable:

writelnwriteln((“The value of “The value of xx is ” is ”,, getsolgetsol((xx), ), “.”“.”))

The output is “The value of The output is “The value of xx is ##.”. is ##.”.NOTE: “write” can also be used, instead of “writeln”. “writeln” NOTE: “write” can also be used, instead of “writeln”. “writeln” inserts a “new line” at the end of the output, “write” does not.inserts a “new line” at the end of the output, “write” does not.

Page 26: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 2626 Semester 2, 2007Semester 2, 2007

Output (cont’d)Output (cont’d)

• For BTP…For BTP…

Page 27: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 2727 Semester 2, 2007Semester 2, 2007

Example 1Example 1

A Bin Packing ProblemA Bin Packing Problem

Page 28: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 2828 Semester 2, 2007Semester 2, 2007

Example1: A Bin Packing ProblemExample1: A Bin Packing Problem

…………

PROBLEM DEFINITION:What is the minimum number of bins needed to contain all items?All items are of different sizes and every bin has a limit on its capacity.

Page 29: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 2929 Semester 2, 2007Semester 2, 2007

Bin Packing (Cont’d)Bin Packing (Cont’d)

IP formulation

jy

jix

jQxq

ix

jiyxts

yMinimise

j

ij

j

n

jiji

n

jij

jij

n

jj

,1,0

,,1,0

,

,1

,,..

1

1

1

otherwise,0

bin in item if,1 jixij

otherwise,0

used is bin if,1 jy j

jQ j bin ofcapacity :

iqi item of size :

Page 30: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 3030 Semester 2, 2007Semester 2, 2007

Bin Packing (Cont’d)Bin Packing (Cont’d)

jiyx jij ,, jiyx jij ,,

ixn

jij

,11

ixn

jij

,11

jQxq j

n

jiji

,1

jQxq j

n

jiji

,1

n

jjy

1

n

jjy

1

Bin Packing Mosel file (click here)

::::

Page 31: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 3131 Semester 2, 2007Semester 2, 2007

Bin Packing (Cont’d)Bin Packing (Cont’d)

Page 32: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 3232 Semester 2, 2007Semester 2, 2007

ifif conditioncondition thenthen

Action_ifAction_if

elseelse

Action_otherwiseAction_otherwise

end-ifend-if

Bin Packing (Cont’d)Bin Packing (Cont’d)

ifif conditioncondition thenthen

Action_ifAction_if

end-ifend-if

Page 33: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 3333 Semester 2, 2007Semester 2, 2007

– This form of “forall” loop must be used when several This form of “forall” loop must be used when several statements are included within the loop.statements are included within the loop.

– However, for simplicity, this form of “forall” can be However, for simplicity, this form of “forall” can be used regardlessly (even for constraints).used regardlessly (even for constraints).

Bin Packing (cont’d)Bin Packing (cont’d)

forall(forall(ii inin SETSET) do) do

StatementStatement

end-doend-do

Page 34: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 3434 Semester 2, 2007Semester 2, 2007

Bin Packing (Cont’d)Bin Packing (Cont’d)

Page 35: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 3535 Semester 2, 2007Semester 2, 2007

Bin Packing (Cont’d)Bin Packing (Cont’d)

Page 36: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 3636 Semester 2, 2007Semester 2, 2007

Bin Packing (Cont’d) - DebuggingBin Packing (Cont’d) - Debugging

• If there are errors in your Mosel code, e.g. instead of “forall”, If there are errors in your Mosel code, e.g. instead of “forall”, you typed “Forall” (recall that Mosel is case-sensitive), the you typed “Forall” (recall that Mosel is case-sensitive), the following message will appear at the following message will appear at the Information Bar Information Bar during during compilation:compilation:

• Click on one of the error messages, Xpress-IVE will navigate to Click on one of the error messages, Xpress-IVE will navigate to the line with error and the line highlighted.the line with error and the line highlighted.

• USEFUL TIP: Always check the error message on top of the list USEFUL TIP: Always check the error message on top of the list first. The proceeding errors may be due to the earlier error.first. The proceeding errors may be due to the earlier error.

Page 37: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 3737 Semester 2, 2007Semester 2, 2007

Bin Packing (Cont’d) - DebuggingBin Packing (Cont’d) - Debugging

• To check if input To check if input parameters are parameters are assigned the correct assigned the correct values, you can refer values, you can refer to the to the Project BarProject Bar– Double click on your Double click on your

selectionselection

• NOTE: contents in NOTE: contents in the the Project BarProject Bar will will only appear after you only appear after you run the model.run the model.

Page 38: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 3838 Semester 2, 2007Semester 2, 2007

Example 2Example 2

A Staff Rostering ProblemA Staff Rostering Problem

Page 39: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 3939 Semester 2, 2007Semester 2, 2007

Example2: A Staff Rostering ProblemExample2: A Staff Rostering Problem

• Problem definitionProblem definition– We wish to create a staff roster with minimal total We wish to create a staff roster with minimal total

staffing cost.staffing cost.– The organisation operates 7 days/week.The organisation operates 7 days/week.– There are There are nn staffs. staffs.– Each staff is paid at an agreed daily rate, according Each staff is paid at an agreed daily rate, according

to the skills they possess.to the skills they possess.– Skills can be categorised into Skills can be categorised into ss types. types.– On any day, a minimal number of staffs are needed On any day, a minimal number of staffs are needed

for each skill.for each skill.– Each staff can at most work Each staff can at most work QQ days/week and must days/week and must

at least work at least work PP days/week. days/week.– On any day, there must be at least On any day, there must be at least RR staffs working. staffs working.

Page 40: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 4040 Semester 2, 2007Semester 2, 2007

Rostering (Cont’d)Rostering (Cont’d)

Skill/Day MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAYA 4 2 1 3 3 2 3B 4 3 4 3 4 3 2C 3 1 4 1 2 2 3D 1 3 4 2 3 4 3E 3 2 3 4 1 3 4

A B C D EAMY 81$ 1 0 0 1 0BOB 117$ 0 1 1 1 0CATHY 127$ 1 0 1 1 0DAVE 158$ 1 0 1 1 1EVE 130$ 0 1 1 1 1FRED 48$ 0 0 0 1 0GUY 186$ 1 1 0 1 1HUGH 122$ 0 1 0 1 1IVY 41$ 1 0 0 0 0JACK 152$ 1 1 1 0 1

Skill TypeWage/DayStaff

Page 41: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 4141 Semester 2, 2007Semester 2, 2007

Rostering (Cont’d)Rostering (Cont’d)

kix

kRx

iQxP

kjdxats

xcMinimise

ik

n

iik

kik

jk

n

iikij

n

i kiki

,,1,0

,

,

,,..

1

7

1

1

1

7

1

otherwise,0

day on works staff if,1 kixik

otherwise,0

skill possesses staff if,1 jiaij

ici stafffor daily wage

kjd jk day on skillfor tsrequiremen

Page 42: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 4242 Semester 2, 2007Semester 2, 2007

Rostering (Cont’d)Rostering (Cont’d)

• A few Mosel codes to note in this example:A few Mosel codes to note in this example:– parameter…end-parameterparameter…end-parameter

• Constants (or RHS values) of constraints and bounds are Constants (or RHS values) of constraints and bounds are defined here, e.g. in the bin-packing problem, the number defined here, e.g. in the bin-packing problem, the number of bins and items can be declared here, i.e. of bins and items can be declared here, i.e. MAXBINMAXBIN=8=8 and and MAXITEMMAXITEM=8=8 respectively. MAXBIN and MAXITEM respectively. MAXBIN and MAXITEM can then be used in other parts of the code.can then be used in other parts of the code.

• Should be inserted after the “uses” statement.Should be inserted after the “uses” statement.• FYI: this is analogous to “FYI: this is analogous to “#define#define” in C-language.” in C-language.

– initializations from initializations from ““in_filein_file””…end-initializations…end-initializations• Input parameters, where their values are to be read from Input parameters, where their values are to be read from

an external file, are inserted and initialised within this an external file, are inserted and initialised within this block.block.

• ““in_filein_file” is the external file containing the initialisation ” is the external file containing the initialisation values.values.

Page 43: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 4343 Semester 2, 2007Semester 2, 2007

Rostering (Cont’d)Rostering (Cont’d)

– fopenfopen(“(“out_fileout_file”,mode) and ”,mode) and fclosefclose(mode)(mode)• fopenfopen is to used to initialise the access of “ is to used to initialise the access of “out_fileout_file”, so ”, so

that data and results can be written to it.that data and results can be written to it.• If over-writing the contents in “If over-writing the contents in “out_fileout_file”, use mode ”, use mode

F_OUTPUT.F_OUTPUT.• If appending to the “If appending to the “out_fileout_file”, use mode ”, use mode

F_OUTPUT+F_APPEND.F_OUTPUT+F_APPEND.• fclosefclose is used to terminate the access to “ is used to terminate the access to “out_fileout_file”.”.

– dynamic object and dynamic object and finalizefinalize(LIST)(LIST)• The size of a range set, e.g. BIN in the bin packing The size of a range set, e.g. BIN in the bin packing

problem, can be set dynamically, i.e. the size of the range problem, can be set dynamically, i.e. the size of the range is not fixed, as follows:is not fixed, as follows:BIN:BIN: set of stringset of string

• The size of BIN can be determined after initialisation from The size of BIN can be determined after initialisation from an external file. BIN can then be made static by inserting an external file. BIN can then be made static by inserting the statement the statement finalizefinalize((BINBIN)) . .

Page 44: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 4444 Semester 2, 2007Semester 2, 2007

Rostering (Cont’d)Rostering (Cont’d)

– procedureprocedure MyProcedureMyProcedure…end-procedure…end-procedure• Functions and looping statements that will be used many Functions and looping statements that will be used many

times in your model can be coded in this block.times in your model can be coded in this block.• MyProcedureMyProcedure can be called anywhere in your code. can be called anywhere in your code.• This block is inserted usually before “end-model”.This block is inserted usually before “end-model”.

– forward procedureforward procedure MyProcedureMyProcedure• should be placed before the first call of should be placed before the first call of MyProcedureMyProcedure

– strfmt(strfmt(strstr,,spacespace,,decdec))• This function indicates the minimum space reserved for This function indicates the minimum space reserved for

printing a string.printing a string.• strstr is the string to be formatted, is the string to be formatted, spacespace specifies the specifies the

minimum space reserved and minimum space reserved and decdec specifies the number specifies the number digits after decimal point.digits after decimal point.

• A negative value for A negative value for spacespace means left-justified printing. means left-justified printing.

Page 45: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 4545 Semester 2, 2007Semester 2, 2007

Rostering (Cont’d)Rostering (Cont’d)

Staff Rostering Mosel file (click here)

Page 46: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 4646 Semester 2, 2007Semester 2, 2007

Rostering (Cont’d)Rostering (Cont’d)

Page 47: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 4747 Semester 2, 2007Semester 2, 2007

Rostering (Cont’d)Rostering (Cont’d)

Page 48: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 4848 Semester 2, 2007Semester 2, 2007

Rostering (Cont’d)Rostering (Cont’d)

Page 49: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 4949 Semester 2, 2007Semester 2, 2007

Rostering (Cont’d)Rostering (Cont’d)

Page 50: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 5050 Semester 2, 2007Semester 2, 2007

Rostering (Cont’d)Rostering (Cont’d)

Page 51: 620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department.

620-362 Applied Operations Research (Xpress620-362 Applied Operations Research (XpressMPMP lecture) lecture) 5151 Semester 2, 2007Semester 2, 2007

Rostering (Cont’d)Rostering (Cont’d)