5.2 Basic Input Elements

Numbers
Names
Delimiters
White Space
Inserting Comments
Includes Files
Conditional Directives
Option Settings

Numbers

You can enter numbers as real numbers or as integers; MPL uses them all as real (floating point) numbers. Scientific notation is not allowed. Integer numbers can be entered with a decimal point to the right. Numbers between -1.0 and 1.0 can be entered without a leading zero.

Examples of numbers recognized by MPL:

     24
     4.8565
     13.
     -.7854

Names

The names of variables and constraints can be of any length. A name begins with a letter followed by any combination of letters and digits. MPL is case sensitive by default, but you can change that in the MPL Environment Options dialog box in the Option menu. See Chapter 4.9: The Options Menu for further nformation. You cannot use spaces in a name, but the underscore character '_' is allowed. For full list of characters allowed in variable names, refer to Appendix A: Character Set. Examples of legal filenames:

     x1
     Inventory

An alternative way is to use double quotes ("). Then any character can be used, even spaces and other special characters. A quote symbol in quoted name is represented by two adjacent quotes. An empty name (name without any characters in it), which can be useful in name abbreviations, is written by two quotes with nothing between them (" ").

Examples of quoted names:

     "Inventory in April"
     Prod3  ->  "P3"
     x[foods]  ->  ""

Delimiters

MPL detects the end of a name when it encounters a delimiter. A delimiter is any of the following characters:

     !  $  :  ;  {  }  \  %  (  )  *  +  -  /  ,  >  =  <
     .  #  "  ?  [  ]

Furthermore, the space character, the end of an input line, and any character in the ASCII range 0..31 are also treated as delimiters. This manual always specifies ASCII values with decimal (base 10) numbers.

White Space

MPL automatically skips over all white space characters when reading the input. White space characters are:

Inserting Comments

A comment is a part of the input file that MPL does not process. Usually, comments are explanations of the formulation in plain words, but you can also use them to tem-porarily "remove" various parts of the model. Typically, you might want to hide a constraint, which you can later make visible again. Also, you can switch between sets of formulas or constraints. Conditional directives and include files (explained later in this chapter) are also often used for this purpose. You can insert comments anywhere in the input file. There are two basic types of comments:

Single-line comments: !

Block comments: { ... }

Include Files

Include files allows you, instead of storing the entire model in a single large file, to break it up into one or more files that are then included in the main model file. Place the include command on a line by itself, at the point where you wish the include file to be read. For example:

#include filename

In above example filename is the name of the file you wish to include. Include files can be nested up to 8 levels.

Include files make the construction of large models much easier and more reliable. The main advantages of using include files are:

Conditional Directives

This feature in MPL is well known in computer programming. Conditional directives can be just as useful when developing linear programming models as when developing programs. They allow you to define special symbols called directives and then, based on these directives, to include or exclude some part of the model.

All directive commands take one line and must be the first item on that line. They start with the '#' character followed by the command and the symbol in question, where applicable. You can nest the #ifdef's up to any level.

Here is a list of the conditional directives that are allowed:

     #define symbol      ! defines the symbol
     #undef symbol       ! undefines the symbol
     #ifdef symbol       ! include the following if symbol is defined
     #ifndef symbol      ! include if symbol is not defined
     #else               ! else on the last #ifdef
     #endif              ! closes the last #ifdef

To illustrate this, lets say you have a problem with variables which can either be regular or integer variables. You can then use conditional directives to decide whether they are to be defined as integer in the model.

     #define IntegerProblem
              .
              .
              .
     #ifdef IntegerProblem
         INTEGER
             x,y
     #endif

In this example, you define the directive IntegerProblem in the beginning of the model formulation. Then, if you want to make the variables noninteger, you only have to delete or comment out the define for IntegerProblem.

Option Settings

In addition to setting options in the option dialog boxes (See Chapter 4.9: The Options Menu ), MPL allows you to set certain options directly in the model file. This is accomplished by using the keyword OPTIONS anywhere in the model file, followed by a line for each option entry. For example, if you want to specify a different Input Directory for data files and change the model type to linear names you can enter the following:

OPTIONS
    DatafileInputDir="Data"
    Model Type=Nonlinear

The available option entries you can set in the model file are listed below. Each entry is listed with the name string that is used, the original name of the option, and then a short description.

PlainVarDefined: (Plain Variables Must be Defined) Specifies whether plain variables must be defined in the Decision Variable section of the model or can be introduced as they appear in the model. For larger models, requiring plain variables to be defined, can increase the maintainability of the model.

DatafileInputDir: (Data Files Input Directory) Selects the folder where MPL will search for input data files. The default is the current folder.

DatafileOutputDir: (Data Files Output Directory) Selects the folder where MPL will save output data files. The default is the current folder.

CheckDuplicateData: (Check Sparse Data For Duplicate Entries) Specifies whether sparse data files are checked for duplicate index entries. In some cases the user may want to read in a data file without receiving errors even if it has duplicate entries. When there are duplicate entries, the last entry in the file will be used by MPL.

UseQuickSort: (Use quicksort for sparse data) Specifies whether sparse data is sorted with quicksort after it is read in. It is normally faster to use quicksort but if there is an invalid entry, such as duplicates, in the data file MPL will not be able to pinpoint the problem line accurately.

ModelType: (Default model type) Specifies the default model type for MPL language.


Linear (1)      Accept only models that are either linear or mixed integer.

Quadratic (2)   Accept models that are quadratic, in addition, to the standard
                 linear or mixed integer models.

Nonlinear (3)   Accept models that are nonlinear.  For example, models that have
                 variables multiplied together or use nonlinear arithmetic functions
                 such as LOG or EXP on the variables.
  

NameGenType: (Name Generation) Chooses the method MPL uses to generate names for vector variables and constraints. Valid values are either 0, 1, or 2.


0  (Indexed Names)           Generate names using the actual index elements.

1  (Numeric Names)           Generate names as numeric with prefix 'C' for
                             variables and prefix 'R' for constraints.

2  (Prefixed Numeric Names)  Generate names as numeric with the prefix based on the vector
                             name.

MaxVarLen: (Max variable length) Most LP solvers have a restriction on the l ength of variable names. Since MPL, in most cases, sends the matrix directly through memory to the solver, the variable names are normally not needed. If the are needed, the value set here helps you ensure that the variable names generated are within limits.

MaxSubLen: (Max subscript length) This value decides how many characters of indexes are retained in the generated variable name. This allows you to use long index names in the model, but keep variable names concise in the generated input file.

DatabaseType: (Default) Chooses which of the supported databases is the default for the MPL database connection. Valid entries are ODBC, Access, Excel, FoxPro and Dbase.

DatabaseDirectory: (Directory) When the database type is either FoxPro or Dbase you can use this option to specify the directory where the database files are stored.

DatabaseODBC: (ODBC Data Source) When the database type selected is ODBC this option specifies which datasource, as defined in the ODBC control panel, should be used.

DatabaseAccess: (Database File *.mbd) When the database type selected is Access this option specifies which database should be used. Please note that if you use any special characters in the name you might have to enclose it with quotation marks.

For example, if you want to read data from the Access database planning.mdb enter the following options in the model file:


OPTIONS
    DatabaseType=Access
    DatabaseAccess="planning.mdb"

DatabaseExcel: (Workbook File *.xls) When the database type selected is Excel or Excel4 this option specifies which workbook should be used.

DatabaseUsername: (User) When you are working with databases that require a Username to log in, this option can be used to specify it.

DatabasePassword: When you are working with databases that require a Password to log in, this option can be used to specify it.

ExcelWorkbook: (Workbook File *.xls) Allows you to specify the default Excel Workbook filename when reading in Excel ranges.

For example, if you want to read Excel ranges from the Excel workbook file cutstock.xls enter the following options in the model file:


OPTIONS
    ExcelWorkbook="cutstock.xls"

ExcelSheetname: (Worksheet name) When the Excel range data is not on the first default worksheet, you can use this option to specify which sheet to read from.

ExcelSkipOverEmpty: When reading indexes from an Excel range, the default is to skip empty cells. You can use this option to turn this Off causing MPL to stop reading at the first empty cell.


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