Download presentation
Presentation is loading. Please wait.
1
620-362 Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 620-362 Applied Operations Research Department of Mathematics and Statistics The University of Melbourne This presentation has been made in accordance with the provisions of Part VB of the copyright act for the teaching purposes of the University. For use of students of the University of Melbourne enrolled in the subject 620-362. Copyright© 2004 by Natashia Boland and Heng-Soon Gan
2
620-362 Applied Operations Research (Xpress MP lecture)2Semester 2, 2007 Contents Getting started with Xpress-IVE and Mosel LanguageGetting started with Xpress-IVE and Mosel Language –Xpress MP, Xpress-IVE and Mosel –Using Xpress-IVE –General Mosel Program Structure Example 1Example 1 –Bin-packing Example (general structure demonstration, forall, sum, writeln, getobjval, getsol, variable types, if-then- else) –Output information (B&B tree, MIP search, Stats etc.) and Debugging Example 2Example 2 –Staff Rostering Example (parameters…end-parameters, working with external input/output data, do…end- do,formatted output,procedure…end-procedure)
3
620-362 Applied Operations Research (Xpress MP lecture)3Semester 2, 2007 Getting Started with Xpress-IVE and Mosel language
4
620-362 Applied Operations Research (Xpress MP lecture)4Semester 2, 2007 Optimisation…. Real World Mathematical Model Computer Program Problem definition & data for parameters. Model and parameters. Output (for verification purposes). NOTE: We will be using Xpress MP
5
620-362 Applied Operations Research (Xpress MP lecture)5Semester 2, 2007 Glossary of terms Program CodeProgram Code –This is a type-written code to translate your mathematical model to a format readable by Xpress MP. Binary CodeBinary Code –This is a generic format of your program code, coded in 0’s and 1’s, readable by any computer applications. CompileCompile –This is when Xpress MP converts the program code to a binary code. ArrayArray –This is how you would express and store a list of items in a program code.
6
620-362 Applied Operations Research (Xpress MP lecture)6Semester 2, 2007 Glossary of terms (cont’d) MemoryMemory –This is where the computer stores your model’s information, such as input parameters. –Information stored in memory can be retrieved during the execution of your program code. Mathematical operatorsMathematical operators DebuggingDebugging –This is a term used to describe the procedure of finding errors in your program code. –The program code errors are referred to as “bugs”. LoopingLooping –This term is used when a repetitive task is performed.
7
620-362 Applied Operations Research (Xpress MP lecture)7Semester 2, 2007 Xpress MP, Xpress-IVE and Mosel Xpress MP :Xpress MP : –Large-scale optimisation software developed by Dash (http://www.dashoptimization.com) http://www.dashoptimization.com Xpress-IVE:Xpress-IVE: –IVE stands for Interactive Visual Environment –Provides a friendly user interface for model coding, code debugging and result display. (Windows environment) –Student versions can be downloaded from http://www.dashoptimization.com (It’s FREE!) http://www.dashoptimization.com Xpress-Mosel:Xpress-Mosel: –a programming language that translates your mathematical programs/algorithms to a format readable by Xpress Optimiser. –File extension: *.mos
8
620-362 Applied Operations Research (Xpress MP lecture)8Semester 2, 2007 Coding Window Project Bar Run Bar Information Bar Run model Compile model Switch between models Execution options
9
620-362 Applied Operations Research (Xpress MP lecture)9Semester 2, 2007 Using Xpress-IVE We have the option to show or hide line numbers in our Mosel code.We have the option to show or hide line numbers in our Mosel code.
10
620-362 Applied Operations Research (Xpress MP lecture)10Semester 2, 2007 The (balanced) transportation problem Recall the following problem: Recall the following problem: (Adapted from Section 7.1, pg. 360, Winston – 2004) Powerco has 3 electric power plants that supply the needs of 4 cities. The supply limit, demand amount and the unit transportation costs are given as follows: Formulate an LP to minimise the cost of meeting each city’s power demand.
11
620-362 Applied Operations Research (Xpress MP lecture)11Semester 2, 2007 The (balanced) transportation problem (cont’d) Balanced Transportation Problem (BTP)
12
620-362 Applied Operations Research (Xpress MP lecture)12Semester 2, 2007 General Mosel Program Structure WARNING: Mosel is case-sensitive!
13
620-362 Applied Operations Research (Xpress MP lecture)13Semester 2, 2007 Modules
14
620-362 Applied Operations Research (Xpress MP lecture)14Semester 2, 2007 Declarations declarations Set1 = 1..10 Set2 = 1..5 Var1: mpvar Var2: array(Set1) of mpvar Var3: array(Set1,Set2) of mpvar InputParam1: real InputParam2: array(Set1) of integer InputParam3: array(Set1,Set2) of real end-declarations
15
620-362 Applied Operations Research (Xpress MP lecture)15Semester 2, 2007 Declarations (cont’d) For BTP…For BTP…
16
620-362 Applied Operations Research (Xpress MP lecture)16Semester 2, 2007 Initialisation declarations Set1 = 1..3 Set2 = 1..2 InputParam1: array(Set1) of integer InputParam2: array(Set1,Set2) of real InputParam3: array(Set2,Set2,Set2) of real end-declarations ! Initialise input parameters InputParam1:: [1,2,3]! initialisation for InputParam1 InputParam2:: [11,12,21,22,31,32] ! initialisation for InputParam2 InputParam3:: [111,112,121,122,211,212,221,222] ! initialisation for InputParam3 NOTE: Data input from file is another method of parameter initialisation. This topic will be covered later in the course.
17
620-362 Applied Operations Research (Xpress MP lecture)17Semester 2, 2007 Initialisation (cont’d) For BTP…For BTP…
18
620-362 Applied Operations Research (Xpress MP lecture)18Semester 2, 2007 Objective Function ObjectiveName:= function NOTE: “function” can be be expressed in a format very similar to a mathe- matical function, e.g. the objective for BTP can be expressed in Mosel as TotalCost:= sum(i in SUPPLY, j in DEMAND) c(i,j)*x(i,j) NOTE: Declaration is not necessary for TotalCost.
19
620-362 Applied Operations Research (Xpress MP lecture)19Semester 2, 2007 Constraints The following constraint can be expressed in Mosel as forall(j in SET1) sum(i in SET2) x(i,j) <= 1 where SET1 and SET2 are range sets and x(i,j) is a two- dimensional decision variable.
20
620-362 Applied Operations Research (Xpress MP lecture)20Semester 2, 2007 Constraints (“forall” loop description) The idea behind a “forall” loop:The idea behind a “forall” loop: –Consider the following constraints (specific version): –The corresponding generic version is
21
620-362 Applied Operations Research (Xpress MP lecture)21Semester 2, 2007 Constraints (“forall” loop description) –If “forall” does not exist, you will have to type in every single constraint (n times) expressed in the specific version of the constraint, i.e. x(1) <= 1 x(2) <= 2.. x(n) <= 2 –Fortunately, “forall” loop can simplify this task. We only need the following line of code forall(i in SET) x(i) <= 1 where SET= 1..n where SET= 1..n
22
620-362 Applied Operations Research (Xpress MP lecture)22Semester 2, 2007 Constraints (cont’d) …and the following constraint can be expressed in Mosel as forall(i in SET1, j in SET2 | i < j) x(i,j) <= 1 …and if x(i,j) is a binary variable (0-1 variable), then the following constraint must be added: forall(i in SET1, j in SET2) x(i,j) is_binary When the constraint above is not stated, x ij is by default a non- negative real number. If x ij is an integer variable, then is_integer should replace is_binary in the above constraint.
23
620-362 Applied Operations Research (Xpress MP lecture)23Semester 2, 2007 Constraints (cont’d) For BTP…For BTP…
24
620-362 Applied Operations Research (Xpress MP lecture)24Semester 2, 2007 This is the easy bit: If the objective function, say, is to be minimised, then the following statement is needed: minimise(TotalCost) Optimisation Statement
25
620-362 Applied Operations Research (Xpress MP lecture)25Semester 2, 2007 Output To display the objective value: writeln(“Objective value is ”, getobjval, “.”) writeln(“Objective value is ”, getobjval, “.”) The output is “Objective value is ##.”, displayed at the “Output/Input” pane of the Run Bar. To display the value taken by a decision variable: writeln(“The value of x is ”, getsol(x), “.”) writeln(“The value of x is ”, getsol(x), “.”) The output is “The value of x is ##.”. NOTE: “write” can also be used, instead of “writeln”. “writeln” inserts a “new line” at the end of the output, “write” does not.
26
620-362 Applied Operations Research (Xpress MP lecture)26Semester 2, 2007 Output (cont’d) For BTP…For BTP…
27
620-362 Applied Operations Research (Xpress MP lecture)27Semester 2, 2007 Example 1 A Bin Packing Problem
28
620-362 Applied Operations Research (Xpress MP lecture)28Semester 2, 2007 Example1: 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.
29
620-362 Applied Operations Research (Xpress MP lecture)29Semester 2, 2007 Bin Packing (Cont’d) IP formulation
30
620-362 Applied Operations Research (Xpress MP lecture)30Semester 2, 2007 Bin Packing (Cont’d) Bin Packing Mosel file (click here) ::
31
620-362 Applied Operations Research (Xpress MP lecture)31Semester 2, 2007 Bin Packing (Cont’d)
32
620-362 Applied Operations Research (Xpress MP lecture)32Semester 2, 2007 if condition then Action_ifelseAction_otherwiseend-if Bin Packing (Cont’d) if condition then Action_ifend-if
33
620-362 Applied Operations Research (Xpress MP lecture)33Semester 2, 2007 –This form of “forall” loop must be used when several statements are included within the loop. –However, for simplicity, this form of “forall” can be used regardlessly (even for constraints). Bin Packing (cont’d) forall(i in SET) do Statementend-do
34
620-362 Applied Operations Research (Xpress MP lecture)34Semester 2, 2007 Bin Packing (Cont’d)
35
620-362 Applied Operations Research (Xpress MP lecture)35Semester 2, 2007 Bin Packing (Cont’d)
36
620-362 Applied Operations Research (Xpress MP lecture)36Semester 2, 2007 Bin Packing (Cont’d) - Debugging If there are errors in your Mosel code, e.g. instead of “forall”, you typed “Forall” (recall that Mosel is case-sensitive), the following message will appear at the Information Bar during compilation:If there are errors in your Mosel code, e.g. instead of “forall”, you typed “Forall” (recall that Mosel is case-sensitive), the following message will appear at the Information Bar during compilation: Click on one of the error messages, Xpress-IVE will navigate to the line with error and the line highlighted.Click on one of the error messages, Xpress-IVE will navigate to the line with error and the line highlighted. USEFUL TIP: Always check the error message on top of the list first. The proceeding errors may be due to the earlier error.USEFUL TIP: Always check the error message on top of the list first. The proceeding errors may be due to the earlier error.
37
620-362 Applied Operations Research (Xpress MP lecture)37Semester 2, 2007 Bin Packing (Cont’d) - Debugging To check if input parameters are assigned the correct values, you can refer to the Project BarTo check if input parameters are assigned the correct values, you can refer to the Project Bar –Double click on your selection NOTE: contents in the Project Bar will only appear after you run the model.NOTE: contents in the Project Bar will only appear after you run the model.
38
620-362 Applied Operations Research (Xpress MP lecture)38Semester 2, 2007 Example 2 A Staff Rostering Problem
39
620-362 Applied Operations Research (Xpress MP lecture)39Semester 2, 2007 Example2: A Staff Rostering Problem Problem definitionProblem definition –We wish to create a staff roster with minimal total staffing cost. –The organisation operates 7 days/week. –There are n staffs. –Each staff is paid at an agreed daily rate, according to the skills they possess. –Skills can be categorised into s types. –On any day, a minimal number of staffs are needed for each skill. –Each staff can at most work Q days/week and must at least work P days/week. –On any day, there must be at least R staffs working.
40
620-362 Applied Operations Research (Xpress MP lecture)40Semester 2, 2007 Rostering (Cont’d)
41
620-362 Applied Operations Research (Xpress MP lecture)41Semester 2, 2007 Rostering (Cont’d)
42
620-362 Applied Operations Research (Xpress MP lecture)42Semester 2, 2007 Rostering (Cont’d) A few Mosel codes to note in this example:A few Mosel codes to note in this example: –parameter…end-parameter Constants (or RHS values) of constraints and bounds are defined here, e.g. in the bin-packing problem, the number of bins and items can be declared here, i.e. MAXBIN=8 and MAXITEM=8 respectively. MAXBIN and MAXITEM can then be used in other parts of the code.Constants (or RHS values) of constraints and bounds are defined here, e.g. in the bin-packing problem, the number of bins and items can be declared here, i.e. MAXBIN=8 and MAXITEM=8 respectively. MAXBIN and MAXITEM 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 “#define” in C-language.FYI: this is analogous to “#define” in C-language. –initializations from “in_file”…end-initializations Input parameters, where their values are to be read from an external file, are inserted and initialised within this block.Input parameters, where their values are to be read from an external file, are inserted and initialised within this block. “in_file” is the external file containing the initialisation values.“in_file” is the external file containing the initialisation values.
43
620-362 Applied Operations Research (Xpress MP lecture)43Semester 2, 2007 Rostering (Cont’d) –fopen(“out_file”,mode) and fclose(mode) fopen is to used to initialise the access of “out_file”, so that data and results can be written to it.fopen is to used to initialise the access of “out_file”, so that data and results can be written to it. If over-writing the contents in “out_file”, use mode F_OUTPUT.If over-writing the contents in “out_file”, use mode F_OUTPUT. If appending to the “out_file”, use mode F_OUTPUT+F_APPEND.If appending to the “out_file”, use mode F_OUTPUT+F_APPEND. fclose is used to terminate the access to “out_file”.fclose is used to terminate the access to “out_file”. –dynamic object and finalize(LIST) 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 is not fixed, as follows:BIN: set of stringThe size of a range set, e.g. BIN in the bin packing problem, can be set dynamically, i.e. the size of the range is not fixed, as follows:BIN: set of string The size of BIN can be determined after initialisation from an external file. BIN can then be made static by inserting the statement finalize(BIN).The size of BIN can be determined after initialisation from an external file. BIN can then be made static by inserting the statement finalize(BIN).
44
620-362 Applied Operations Research (Xpress MP lecture)44Semester 2, 2007 Rostering (Cont’d) –procedure MyProcedure…end-procedure Functions and looping statements that will be used many times in your model can be coded in this block.Functions and looping statements that will be used many times in your model can be coded in this block. MyProcedure can be called anywhere in your code.MyProcedure can be called anywhere in your code. This block is inserted usually before “end-model”.This block is inserted usually before “end-model”. –forward procedure MyProcedure should be placed before the first call of MyProcedureshould be placed before the first call of MyProcedure –strfmt(str,space,dec) This function indicates the minimum space reserved for printing a string.This function indicates the minimum space reserved for printing a string. str is the string to be formatted, space specifies the minimum space reserved and dec specifies the number digits after decimal point.str is the string to be formatted, space specifies the minimum space reserved and dec specifies the number digits after decimal point. A negative value for space means left-justified printing.A negative value for space means left-justified printing.
45
620-362 Applied Operations Research (Xpress MP lecture)45Semester 2, 2007 Rostering (Cont’d) Staff Rostering Mosel file (click here)
46
620-362 Applied Operations Research (Xpress MP lecture)46Semester 2, 2007 Rostering (Cont’d)
47
620-362 Applied Operations Research (Xpress MP lecture)47Semester 2, 2007 Rostering (Cont’d)
48
620-362 Applied Operations Research (Xpress MP lecture)48Semester 2, 2007 Rostering (Cont’d)
49
620-362 Applied Operations Research (Xpress MP lecture)49Semester 2, 2007 Rostering (Cont’d)
50
620-362 Applied Operations Research (Xpress MP lecture)50Semester 2, 2007 Rostering (Cont’d)
51
620-362 Applied Operations Research (Xpress MP lecture)51Semester 2, 2007 Rostering (Cont’d)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.