Output Statements
The features in this section are for displaying output. In addition to the output functions discussed here, all the reporting functions discussed in Chapter 7, Report Functions, for data and init sections are also available for use in calc section scripts. The one exception is that the @TABLE function is only available for use in data sections.
@SOLU( [0|1[, MODEL_OBJECT[, 'REPORT_HEADER']]])
The @SOLU statement mimics the functionality of the SOLU command-line command. If all arguments are omitted, then @SOLU will display the default, LINGO solution report. All reports are sent to the screen unless an @DIVERT (see below) command is in effect, routing output to a text file.
If the first argument to @SOLU is 0, then only nonzero variables and binding rows will be displayed. If the first argument is 1, then all information will be displayed.
If you wish to narrow the scope of the solution report, then the optional MODEL_OBJECT argument can be either an attribute or row name. In which case, the report will be restricted to the specified object.
The optional third argument, 'REPORT_HEADER', is used when you wish to place a header string on the report.
You can refer to the LOOPOLE model in the Samples folder for an example of a model that uses the @SOLU command
@WRITE( ‘TEXT1’|VALUE1[, …, ‘TEXTN’|VALUEN])
The @WRITE statement is the primary tool you’ll use for displaying output in calc sections. @WRITE can display both text and variable values. Text strings are delimited with single or double-quotes. All output will be directed to the screen unless @DIVERT (discussed below) is used to route output to a file.
@WRITE is useful for both debugging your calc section code and for generating custom reports. As an example, the following product mix model uses @WRITE statements in a calc section to construct a custom report:
MODEL:
[PROFIT] MAX = 200 * WS + 300 * NC;
[CHASSIS1] WS <= 60;
[CHASSIS2] NC <= 40;
[DRIVES] WS + 2 * NC <= 120;
CALC:
@SOLVE();
@WRITE( 'Total profit = ', PROFIT, @NEWLINE( 1));
@WRITE( 'Production:', @NEWLINE( 1));
@WRITE( ' WS = ', WS, @NEWLINE( 1),
' NC = ', NC, @NEWLINE( 1),
'Total units = ', WS + NC,
@NEWLINE( 2)
);
@WRITE( 'Dual analysis:', @NEWLINE( 1),
' Chassis1: ', @DUAL( CHASSIS1),
@NEWLINE( 1),
' Chassis2: ', @DUAL( CHASSIS2),
@NEWLINE( 1),
' Drives: ', @DUAL( DRIVES),
@NEWLINE( 1)
);
ENDCALC
END
Running this model will yield the following report:
Total profit = 21000
Production:
WS = 60
NC = 30
Total units = 90
Dual analysis:
Chassis1: 50
Chassis2: 0
Drives: 150
Note that in addition to the @WRITE statement, we also made use of both the @NEWLINEreport function to produce line feeds and the @DUAL report function to return the dual values, or shadow prices, on the constraints. Additional information on these and other report functions may be found in section Report Functions of Chapter 7.
@PAUSE( ‘TEXT1’|VALUE1[, …, ‘TEXTN’|VALUEN])
The @PAUSE statement has the same syntax as the @WRITE statement, however, @PAUSE causes LINGO to pause execution and wait for a user response. For example, under Windows, the following reference to @PAUSE:
CALC:
@PAUSE( 'An example of @PAUSE running on Windows.');
ENDCALC
will cause the following dialog box to be displayed:
The user has the option of pressing either the Resume button to continue normal processing, or the Interrupt button to immediately terminate execution of the model. On platforms other than Windows, the output will be routed to the terminal and LINGO will wait for the user to press the Enter key.
@DIVERT( [‘FILE_NAME’[, ‘A’]])
By default, output generated by the @WRITE statement will be sent to the screen. However, you may wish to capture this output in a file. @DIVERT allows you to do this. As an example, we modified the product mix example from above to route its custom report to file MYREPORT.TXT as follows:
CALC:
@SOLVE();
@DIVERT( 'MYREPORT.TXT');
@WRITE( 'Total profit = ', PROFIT, @NEWLINE( 1));
@WRITE( 'Production:', @NEWLINE( 1));
@WRITE( ' WS = ', WS, @NEWLINE( 1),
' NC = ', NC, @NEWLINE( 1),
'Total units = ', WS + NC,
@NEWLINE( 2)
);
@WRITE( 'Dual analysis:', @NEWLINE( 1),
' Chassis1: ', @DUAL( CHASSIS1),
@NEWLINE( 1),
' Chassis2: ', @DUAL( CHASSIS2),
@NEWLINE( 1),
' Drives: ', @DUAL( DRIVES),
@NEWLINE( 1)
);
@DIVERT();
ENDCALC
Note the two occurrences of @DIVERT. In the first instance, we specify the file we want to open, and subsequent @WRITE output is diverted to that file. The second reference to @DIVERT closes the file and reverts output back to the terminal device.
@DIVERT also accepts an optional second argument of the letter ‘A’. If this argument is present, LINGO will append output to the end of the file if it already exists. If the argument is omitted, LINGO will overwrite the file if it already exists.
Note: | @DIVERT statements can be nested so that multiple levels of output files may be simultaneously in use. |