Writing to Files Using @TEXT
The @TEXT interface function is used for exporting solutions to text files. The @TEXT function can export both set members and attribute values. The syntax of the @TEXT function is:
@TEXT( ['filename', [‘a’]])
where filename is the name of the file you want to export the solution to. If filename is omitted, the solution data will be sent to the standard output device (this is typically the screen). If the second argument of ‘a’ is present, then LINGO will append output to the file, otherwise it will create a new file for subsequent output, erasing any existing file. The @TEXT function may only appear on the left-hand side of a data statement in the data section of a model.
We refer to data statements that use interface functions to generate output as output operations. Output operations are only performed when the solver finishes running a model. The operations are run in the sequence that they were encountered in the model.
Here are some examples of using @TEXT:
Example 1: @TEXT( 'RESULTS.TXT') = X;
Sends the value(s) for variable X to the file RESULTS.TXT. Any existing version of the file is overwritten.
Example 2: @TEXT() = DAYS, START;
In this example, we are exporting all members of the DAYS set and the START attribute. We have routed the output to the screen by omitting the filename argument.
Example 3: @TEXT() = @WRITEFOR( DAYS( D) | START( D) #GT# 0:
DAYS( D), ' ', START( D));
In this example, we use the @WRITEFOR reporting function to loop over the members of the DAYS set. Contrary to the previous example, we only print information for those days where START( D) is greater than 0.
Now, let's turn to a more detailed example of the use of @TEXT in our staff scheduling model.