File|Open

 

 

The Open command reads a saved file from disk and places it in a LINGO Window. The file can be a LINGO model file (*.LG4), or any other file. If the file is not in LG4 format, it must be in ASCII text format.

After issuing the Open command, you will be presented with a dialog box resembling the following:

page95xp

You can enter a file name in the File name edit box, or select a file name from the list of existing files by double-clicking on a file. Press the Open button to open the file, the Cancel button to exit without opening a file, or the Help button for assistance.  You may select a different file type from the Files of type list box causing LINGO to list only the files of that type.  Once you have  read in a LINGO model file (a LG4 or LNG file), you may use the Solver|Solve command to solve the model.

In addition to its native LG4 and LNG file formats, LINGO supports the following three additional file formats :

MPS - The MPS file format is an industry standard format developed by IBM, which is useful for passing linear and quadratic models from one solver or platform to another.
MPI -  The MPI format was developed by LINDO Systems as a portable format for representing arbitrary math programming models.
LP - The LP file format is another industry standard file format, as is MPS, for storing linear and quadratic model.  However,  with LP format equations are stored using standard algebraic format, making LP files much easier to read and interpret than MPS files.  At present, LINGO only supports linear models when reading LP format files.

If the file to be opened has an extension of .MPS, .MPI or .LP, then LINGO will invoke, respectively, its MPS, MPI or LP reader to parse the file.  When importing a non-native file, LINGO reads the file from disk, converts it to an equivalent LINGO model, and places the model into a new model window.  More details follow immediately below.  LINGO can also write MPS and MPI format files (but not LP files); this is discussed in the File|Export File section below.

Importing MPS, MPI or LP Files

When LINGO reads an MPS, MPI or LP file, it converts the formulation to an equivalent LINGO model.  As an example, consider the following, simple model:

ObjRow) Maximize 20X  + 30Y

Subject To:

  Row1) X < 50

  Row2) Y < 60

  Row3) X + 2Y < 120

The MPS file for this model is:

NAME           SAMPLE

OBJSENSE

   MAX

ROWS

 N OBJROW

 L ROW1

 L ROW2

 L ROW3

COLUMNS

   X         ROW3         1.0000000

   X         OBJROW      20.0000000

   X         ROW1         1.0000000

   Y         OBJROW      30.0000000

   Y         ROW2         1.0000000

   Y         ROW3         2.0000000

RHS

   RHS       ROW1        50.0000000

   RHS       ROW2        60.0000000

   RHS       ROW3       120.0000000

ENDATA

The MPI version of the model is:

BEGINMODEL   SAMPLE      

! Number of Objective Functions:         1

! Number of Constraints        :         3

! Number of Variables          :         2

VARIABLES

!  Name                  Lower Bound        Initial Point          Upper Bound     Type

  X                               0              1.23457               1e+030        C

  Y                               0              1.23457               1e+030        C

OBJECTIVES

 OBJROW      MAXIMIZE

   EP_USRCOD            -101

   EP_PUSH_NUM       20

   EP_PUSH_VAR  X

   EP_MULTIPLY

   EP_PUSH_NUM       30

   EP_PUSH_VAR  Y

   EP_MULTIPLY

   EP_PLUS    

CONSTRAINTS

 ROW1    L        

   EP_USRCOD            -101

   EP_PUSH_VAR  X

   EP_PUSH_NUM       50

   EP_MINUS  

 ROW2    L        

   EP_USRCOD            -101

   EP_PUSH_VAR  Y

   EP_PUSH_NUM       60

   EP_MINUS  

 ROW3    L        

   EP_USRCOD            -101

   EP_PUSH_VAR  X

   EP_PUSH_NUM       2

   EP_PUSH_VAR  Y

   EP_MULTIPLY

   EP_PLUS    

   EP_PUSH_NUM       120

   EP_MINUS  

ENDMODEL

And, the LP format version of the model is:

\ LP format example

Maximize

 objrow: 20x + 30y

Subject To

 row1: x <= 50

 row2: y <= 60

 row3: x + 2y <= 120

End

One thing to notice at this point is that MPS and MPI formats are not very compact methods for storing a model - they are designed for portability, as opposed to efficiency.

Using the File|Open command to read either of these three versions of the model into LINGO, we are presented with the following window containing an equivalent LINGO model:

page105xp

Note how the model is automatically converted from MPS, MPI or LP format to native LINGO format.  Should you wish to save the file again using either MPS or MPI format rather than LINGO format, you must use the File|Export File|MPS Format… command.

Note:The MPS, MPI and LP file formats are intended primarily for exporting (importing) models to (from) other applications or platforms. These file formats are purely scalar in nature—all set-based information is lost upon saving a LINGO model in either MPS or MPI format (LINGO does not currently write LP format files). Thus, when saving copies of a model on your own machine, you should always use the File|Save command in order to save models in a native LINGO format (LG4 or LNG) in order to preserve your model in its entirety.

When it comes to acceptable constraint and variable names, the MPS, MPI and LP formats are less restrictive than LINGO. To compensate for this fact, LINGO attempts to patch names when reading a file, so that all the incoming names are compatible with its syntax. LINGO does this by substituting an underscore for any character in a name that is not admissible. In most cases, this will work out OK. However, there is a chance for name collisions where two or more names get mapped into one. For instance, the variable names X.1 and X%1 would both get mapped into the single LINGO name X_1. Of course, situations such as this entirely alter the structure of the model, rendering it incorrect.  However, you will be warned whenever LINGO has to patch a name with the following error message:

page106axp

This message displays the number of variable and row names that were patched to get them to conform to LINGO syntax.

If name collisions are a problem, then LINGO has an option that will ensure that all names remain unique. This option involves using RC format for names encountered during MPS I/O. RC format involves renaming each row (constraint) in a model to be Rn, where n is the row’s index. Similarly, each column (variable) is renamed to Cn. In addition, LINGO renames the objective row to be ROBJ. To switch to RC format for MPS names, run the Solver|Options command, select the General Solver tab, then click the checkbox titled Use R/C format names for MPS I/O, as illustrated here:

page106b2xp

As an example, we will once again import the same MPS format model as above. However, this time we will use RC naming conventions. Here is the model as it appears after importing it into LINGO:

page106cxp

Notice how the variable names now use RC format, guaranteeing that name collisions will not occur.

Another potential conflict is that MPS and MPI allow variable names to be duplicated as constraint names and vice versa. LINGO does not allow for this. When you go to solve the model, you will receive either error message 28 (Invalid use of a row name), or error message 37 (Name already in use). Once again, you can switch to using RC name format to avoid this conflict.

As a final note, LINGO only supports free format MPS files, and does not support fixed format MPS files. Therefore, variable and row names may not contain embedded blanks.