Chapter 5. Language Overview

The Problem Title
The Definition Part
The Model Part

The MPL model file is divided into two main parts; the definition and the model. In the definition part you define various items that are then used throughout the model. The model part, on the other hand, contains the actual model formulation. Each part is further divided into sections, which are as follows:

The Definition Part

TITLE- The problem name
INDEX- Dimensions of the problem
DATA- Scalars, datavectors and files
DECISION VARIABLES- Vector variables
MACRO- Macros for repetitive parts

The Model Part

    MODEL
       MAX or MIN           -  The objective function.
       SUBJECT TO           -  The constraints.
       BOUNDS               -  Simple upper and lower bounds.
       FREE                 -  Free variables.
       INTEGER              -  Integer variables.
       BINARY               -  Binary (0/1) variables.
    END

None of the sections are actually required in MPL, but in order to have a valid optimization model you will need at least the objective function and the constraints. MPL allows you to place the sections in any order, but since any item must be declared before it is used in the model, the above order is used most of the time. Multiple entries of each section are allowed. The keywords MODEL, SUBJECT TO and END are optional, but used most of the time to aid readability. As an example of how simple the model in MPL can be, here is one tiny but still perfectly legal input:

    MAX  x + y ;

    x + 2y  >=  10 ;

In this chapter each of the aforementioned sections is explained in full detail. On the next page is the MPL model file 'planning.mpl' that we will use as an example.

    {   Planning.mpl   }

    {   Aggregate production planning for 12 months   }

    TITLE
        Production_Planning;

    INDEX
        product = 1..3;
        month   = (January,February,March,April,May,June,July,
                   August,September,October,November,December);

    DATA
        price[product]              := (105.09, 234.00, 800.00);
        Demand[month,product]       := 1000 DATAFILE(demand.dat);
        ProductionCapacity[product] := 1000 (10, 42, 14);
        ProductionCost[product]     := (64.30, 188.10, 653.20);
        InventoryCost               := 8.8 ;

    DECISION VARIABLES
        Inventory[product,month]     ->  Invt
        Production[product,month]    ->  Prod
        Sales[product,month]         ->  Sale

    MACRO
        Revenues  := SUM(product,month: price * Sales);
        TotalCost := SUM(product,month: InventoryCost * Inventory
                                      + ProductionCost * Production);
    MODEL

        MAX   Profit  =  Revenues - TotalCost ;

    SUBJECT TO
        InventoryBalance[product,month]  ->  IBal :
        Inventory  =  Inventory[month-1] + Production - Sales ;

    BOUNDS
        Sales  <=  Demand ;
        Production  <=  ProductionCapacity ;
        Inventory[month=January..November] < 90000 ;
        Inventory[month=December] = 20000 ;
    END

Figure 5.1: The Planning.mpl Model File

The Problem Title

The title section is used to give each problem a name which we strongly reccomend. When you use a name, MPL places it in the generated file where appropriate, which helps you keep track of files and printouts. Your title section starts with the keyword TITLE, followed by the problem name. The name can be of any length but cannot contain spaces or other delimiters. You may place a semicolon after the name, although it is not necessary. If you omit the title, it defaults to the name Problem.

Example:

    TITLE  Production_Planning ;

The Definition Part

The Definition Part is used to define various items to be used later in the model. Here you can, for example, define subscripted variables, data to be imported from other programs and macros for repetitive parts of the model.

The first section, after the title, is the index section, starting with the keyword INDEX. This is where you define the indexes and the sets for the model. This will be covered in Chapter 6: Defining Sets and Indexes.

After the indexes, the next step is to setup the data for the model in the DATA section. You can specify both data defined directly in the model and also read in data from either external data files or databases. This will be covered in Chapter 7: Data for the Model.

Following the data section you normally define the variables for the model in the DECISION VARIABLES section. If you need to make the variables dependent on a certain sparse data vector you do this using the WHERE command. See Chapter 8.1: Declaring Decision Variables for further information.

The last section in the Definition Part is the MACROS section. The macros can be used to give complex expressions a distinctive name and then refer to these complex expressions throughout the model by the macro. See Chapter 8.2: Defining Macros for further information.

Each section in the definition part, except the problem title, can appear as often as you want. These sections normally appear in the order listed above, but they can appear in any order you choose. Please note though that each item must be defined before it is referred. In the following chapters each section will be discussed in detail.

The Model Part

The model part contains the actual problem formulation. Although the keyword MODEL is optional, it is useful to mark the beginning of the problem formulation.

The layout of the model is straightforward. The first step is the objective function. Either the keyword MAX or keyword MIN is used, depending on whether it is a maximization or minimization problem.

After the objective function, the next step is to list the constraints. The keyword SUBJECT TO is used as a separator between the objective function and the constraints.

The next step is to enter simple upper and lower bounds on variables if they are used. You use the keyword BOUNDS to mark the beginning of the bounds section.

Free variables are entered following the FREE keyword. Integer and binary variables are entered after the INTEGER and BINARY keywords, respectively. SOS sets of variables are entered after the SOS keywords. These last five sections (including bounds) are all optional and can be placed in any order.

The END keyword is optional and marks the end of the model. Everything that follows it is ignored.


Back To Top | Maximal Home Page | Table of Contents | Previous Page | Next Page