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

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

Java Script Session1 INTRODUCTION.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Chapter 7: User-Defined Functions II
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
The Web Warrior Guide to Web Design Technologies
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
Introduction to a Programming Environment
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Introduction to C Programming
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
GAMS Anwendung Nutzeroberfläche eigene Programme Modellierungs- System GAMS AMPL ILOG Studio … Solver CPLEX, CONOPT, MINOS, COIN, BARON,...
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
Chapter 6: User-Defined Functions
Sharda University P. K. Mishra (Asst.Prof) Department of Computer Science & Technology Subject Name: Programming Using C Sub Code: CSE-106 Programming.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Michal Koháni Departement of Transportation Networks Faculty of Management Science and Informatics University of Zilina, Slovakia Høgskolen i Molde, September.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Control Structures (A) Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing.
Name of the model & options Parameters Declarations (decision variables, arrays, etc.) Data input Objective function Constraints Output & results How to.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.
Starting Out with C++ Early Objects ~~ 7 th Edition by Tony Gaddis, Judy Walters, Godfrey Muganda Modified for CMPS 1044 Midwestern State University 6-1.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
The Hashemite University Computer Engineering Department
Michal Koháni Department of Transportation Networks Faculty of Management Science and Informatics University of Zilina, Slovakia XPRESS – IVE Seminary.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Development Environment
Chapter 9: Value-Returning Functions
Chapter 2 - Introduction to C Programming
The Selection Structure
Chapter 2 - Introduction to C Programming
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Topics Introduction to File Input and Output
WEB PROGRAMMING JavaScript.
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
A QUICK START TO OPL IBM ILOG OPL V6.3 > Starting Kit >
Topics Introduction to File Input and Output
Introduction to C Programming
Introduction to Computer Programming IT-104
Getting Started With Coding
Presentation transcript:

Applied Operations Research (Xpress MP lecture)1Semester 2, 2007 Introduction to Modelling with Xpress MP 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 Copyright© 2004 by Natashia Boland and Heng-Soon Gan

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)

Applied Operations Research (Xpress MP lecture)3Semester 2, 2007 Getting Started with Xpress-IVE and Mosel language

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

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.

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.

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 ( 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 (It’s FREE!) Xpress-Mosel:Xpress-Mosel: –a programming language that translates your mathematical programs/algorithms to a format readable by Xpress Optimiser. –File extension: *.mos

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

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.

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.

Applied Operations Research (Xpress MP lecture)11Semester 2, 2007 The (balanced) transportation problem (cont’d) Balanced Transportation Problem (BTP)

Applied Operations Research (Xpress MP lecture)12Semester 2, 2007 General Mosel Program Structure WARNING: Mosel is case-sensitive!

Applied Operations Research (Xpress MP lecture)13Semester 2, 2007 Modules

Applied Operations Research (Xpress MP lecture)14Semester 2, 2007 Declarations declarations Set1 = 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

Applied Operations Research (Xpress MP lecture)15Semester 2, 2007 Declarations (cont’d) For BTP…For BTP…

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.

Applied Operations Research (Xpress MP lecture)17Semester 2, 2007 Initialisation (cont’d) For BTP…For BTP…

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.

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.

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

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

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.

Applied Operations Research (Xpress MP lecture)23Semester 2, 2007 Constraints (cont’d) For BTP…For BTP…

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

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.

Applied Operations Research (Xpress MP lecture)26Semester 2, 2007 Output (cont’d) For BTP…For BTP…

Applied Operations Research (Xpress MP lecture)27Semester 2, 2007 Example 1 A Bin Packing Problem

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.

Applied Operations Research (Xpress MP lecture)29Semester 2, 2007 Bin Packing (Cont’d) IP formulation

Applied Operations Research (Xpress MP lecture)30Semester 2, 2007 Bin Packing (Cont’d) Bin Packing Mosel file (click here) ::

Applied Operations Research (Xpress MP lecture)31Semester 2, 2007 Bin Packing (Cont’d)

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

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

Applied Operations Research (Xpress MP lecture)34Semester 2, 2007 Bin Packing (Cont’d)

Applied Operations Research (Xpress MP lecture)35Semester 2, 2007 Bin Packing (Cont’d)

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.

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.

Applied Operations Research (Xpress MP lecture)38Semester 2, 2007 Example 2 A Staff Rostering Problem

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.

Applied Operations Research (Xpress MP lecture)40Semester 2, 2007 Rostering (Cont’d)

Applied Operations Research (Xpress MP lecture)41Semester 2, 2007 Rostering (Cont’d)

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.

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).

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.

Applied Operations Research (Xpress MP lecture)45Semester 2, 2007 Rostering (Cont’d) Staff Rostering Mosel file (click here)

Applied Operations Research (Xpress MP lecture)46Semester 2, 2007 Rostering (Cont’d)

Applied Operations Research (Xpress MP lecture)47Semester 2, 2007 Rostering (Cont’d)

Applied Operations Research (Xpress MP lecture)48Semester 2, 2007 Rostering (Cont’d)

Applied Operations Research (Xpress MP lecture)49Semester 2, 2007 Rostering (Cont’d)

Applied Operations Research (Xpress MP lecture)50Semester 2, 2007 Rostering (Cont’d)

Applied Operations Research (Xpress MP lecture)51Semester 2, 2007 Rostering (Cont’d)