Initializing help system before first use

Correcting errors and debugging a model

Having entered the model printed in the previous section, we now wish to execute it, that is, solve the optimization problem and retrieve the results. Choose Run » Run foliolp.mos or alternatively, click on the run button: Chapi123/butrun.png making sure that the desired model filename is selected in the dropdown box next to it.

At a first attempt to run a model, you might see the message `Compilation failed. Please check for errors.' In this case, the bottom window displays the error messages generated by Mosel, for instance as shown in the following figure (Figure Logging output with error messages).

Chapi123/wblperr.png

Figure 4.4: Logging output with error messages

The model from the previous section is printed in its correct form. We have provided an example file foliolperr.mos containing some common mistakes that we shall now correct.

The first message:

 Mosel: E-100 at (26,32) of `foliolperr.mos': Syntax error.

takes us to the line

 RET:: [5,17,26,12,8,9,7,6,31,21

We need to add the closing bracket to terminate the definition of RET (if the definition continues on the next line, we need to add a comma at the end of this line to indicate continuation).

The next messages that appear after re-running the model:

 Mosel: E-100 at (29,9) of `foliolperr.mos': Syntax error before `='.
 Mosel: E-123 at (29,9) of `foliolperr.mos': `Return' is not defined.
 Mosel: E-124 at (29,42) of `foliolperr.mos': An expression cannot be used as a statement.

take us to the line

 Return = sum(s in SHARES) RET(s)*frac(s)

Finding the error here requires close examination: instead of := we have used =. Since Return should have been defined by assigning it the sum on the right side, this statement now does not have any meaning.

After correcting this error, we try to run the model again, but we are still left with one error message:

 Mosel: E-123 at (44,17) of `foliolperr.mos': `maximize' is not defined.

located in the line

 maximize(Return)

The procedure maximize is defined in the module mmxprs but we have forgotten to add the line

 uses "mmxprs"

at the beginning of the Mosel model. After adding this line, the model compiles correctly.

The module browser enables you to quickly see what is provided by a module. Select the Modules tab on the right of the editor window to display the list of modules available in your Xpress installation. It also allows you to check in detail the functionality (subroutines, constants) added by each module to the Mosel language.

If you do not remember the correct name of a Mosel keyword while typing in a model, then you may use the code completion feature of the Workbench editor: while you are typing the editor brings up a list of suggestions with Mosel keywords and subroutines.

Debugging

A syntactically correctly Mosel model still might not do what we would like it to do. For instance, we may have forgotten to initialize data, or variables and constraints are not created correctly (they may be part of complex expressions, including logical tests etc.). To check what has indeed been generated by Mosel, we may pause the execution of the model immediately before it terminates by running the model in debug mode: select button Chapi123/butdebug.png to run the model. The model will pause on the last statement to allow you to inspect the model entities in the Debugger window on the right side of the workspace window. Expand the entries under the heading Variables to view the definitions of individual model objects.

Chapi123/wbdebug.png

Figure 4.5: Workbench debugger

If you wish to display or trace the values of model entities at other locations you can set breakpoints by clicking onto the grey area in front of the line numbers and re-run the model in debug mode.

Chapi123/wbbreakpnt.png

Figure 4.6: Debug run with breakpoint

The debugger controls at the top of the Debugger window (step over: Chapi123/butstepover.png, step into: Chapi123/butstepinto.png, step out: Chapi123/butstepout.png) allow you to step through the model line-by-line or resume/pause its execution (Chapi123/butresumedbg.png).


© 2001-2024 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.