The DIVERT command opens a file and causes LINGO to route all subsequent reports (e.g., SOLUTION , RANGE, and LOOK commands) from the screen to the file. This command captures the reports in text format in the file you specify. Since the files created by the DIVERT command are in text format, they may be read into other programs, such as word processors and spreadsheets, or they may be queued to your printer.

The syntax for the DIVERT command is:

DIVERT filename

where filename is the name of the file you wish to create.

The RVRT command reverses a DIVERT command by closing the DIVERT file and then rerouting output back to the screen.

In the following example, we create a small model with the MODEL command, solve it with the GO command, and then use the DIVERT command to create a file containing the formulation and solution:

: !Enter a small model

: MODEL

? MAX = 20*X + 30*Y;

? X <= 50;

? Y <= 60;

? X + 2*Y <= 120;

? END

: !Solve the model

: TERSE

: GO

 

Global optimal solution found at step:         1

Objective value:                        2050.000

 

 

: !Create a DIVERT file with

: !the formulation & solution

: DIVERT MYFILE.TXT  !Opens the file

: LOOK ALL           !Sends model to file

: SOLU               !Sends solution to file

: RVRT               !Closes DIVERT file

:

Opening the DIVERT file created in this example, we find the following file with the formulation and solution:

  1]MAX = 20*X + 30*Y;

  2]X <= 50;

  3]Y <= 60;

  4]X + 2*Y <= 120;

 

Variable           Value        Reduced Cost

       X        50.00000            0.000000

       Y        35.00000            0.000000

 

     Row    Slack or Surplus      Dual Price

       1        2050.000            1.000000

       2        0.000000            5.000000

       3        25.00000            0.000000

       4        0.000000            15.00000

Note:Keep in mind that, when a DIVERT command is in effect, you will see little or no output on your screen. This is because the majority of output is being routed to the DIVERT file rather than to the screen.

 

Note:Also, be sure you choose a DIVERT filename different from your model filename. If not, you will overwrite your model file, and will be unable to retrieve it!