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: 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 are likely to see the message `Compilation failed. Please check for errors.' The bottom window displays the error messages generated by Mosel, for instance as shown in the following figure (Figure Logging output with error messages).

Figure 4.4: Logging output with error messages
When typing in the model from the previous section (there printed in its correct form), we have deliberately introduced some common mistakes that we shall now correct—see the example file foliolperr.mos for the erroneous model.
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 taking a very close look: 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.
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
If a model is correct from Mosel's point of view, this does of course not guarantee that it really does 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 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.

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.

Figure 4.6: Debug run with breakpoint
The debugger controls at the top of the Debugger window (step over: , step into:
, step out:
) allow you to step through the model line-by-line or resume/pause its execution (
).