Debugging a preprocessing script

Adding a breakpoint to a preprocessing script

You are going to add a breakpoint to set the debugging mode, then execute the script again, using this time the Debug button.

To add a breakpoint:

  1. In the transp4.mod file, scroll to the line containing the printRoute function in the DISPLAY execute block.
    
    function printRoute(r)
    
  2. Double-click in the grey margin next to the line.

    A blue dot appears in the margin of the editing area to signal the breakpoint.

  3. In the main toolbar, click the arrow of the Debug button Debug button and select 1 transp Even better sparsity to run the script.

    Execution stops at the breakpoint and information appears in the Variables view and the Scripting log.

    Figure 1. Execution stopped at the breakpoint in transp4.mod
    Execution stopped at a breakpoint

Examining the preprocessing call stack

The call stack, showing nested function calls, is displayed in the Debug view. The content of a selected call frame is displayed in the Variables view.

In this example, the call stack contains one call frame, [transp4.mod:67].

Figure 2. Debug view for transp4.mod
Call stack in Debug view
Figure 3. Variables view for call frame [transp4.mod:67] (transp4.mod)
Variables view for transp4.mod in transp example

For a large tuple set, the values may not all be visible within the window. In this case, an ellipsis appears at the end of the cell. Pass the cursor over the column to display all the values in a tooltip.

Click the Step Over Step Over button or Step Into button Step Into button repeatedly to watch the value of the variables change in the call stack. The variables are highlighted when their values change.
Figure 4. The Variables view after stepping
Script Objects window

Stepping out of an execute function

If you are stepping in an execute statement and the current instruction is within a loop (for, forall, while, or repeat), you can make the IDE execute the loop without stopping at instructions by stepping out of the execute function using the Step Return Step Return button button. The IDE executes the entire loop, then stops at the first instruction after the loop.

The Step Return button allows you to step out of a function in a script, to the statement following the function call. For example, if you were to click the Step Return button at this statement:


writeln("Routes":); 

the current instruction becomes:


for (var r in Routes) {
Figure 5. Stepping out of an execute function (transp4.mod)
Stepping out of an execute function
  1. Click the Step Over button Step Over button to execute the instruction.

    If you open the nodes in the call stack, you can see the CPLEX parameter setting listed for the predefined cplex object.

  2. Click Step Over four more times.

    The current instruction is now:

    
    printRoute(r);
    

    Note that Step Over does not move to the statement within the function because it is at a lower level.

Stepping into a function

The Step Into button Step Into button allows you to step into a function. Use it to step to:

  • the first statement, or

  • to the instruction after the current one if there is no function called.

To step into the printRoute(r) function, click the Step Into button.

The IDE executes the current instruction and the blue arrow in the margin moves to the first line in the function:


write("  ",r.p,":");
Figure 6. Stepping into a function (transp4.mod)
Stepping into a function

Stepping out of a lower-level function

Click the Step Return button Step Return button to execute the write and writeln statements, and step out of the printRoute(r) function.

The current instruction becomes:


for (var r in Routes) {

because the loop iteration is completed and so the next instruction is the loop statement.

Figure 7. Stepping out of the PrintRoute(r) function (transp4.mod)
Stepping out of a function

Monitoring a function in a loop

To continue execution, stopping at each pass through the printRoute(r) function, click the Step Into button Step Into button repeatedly.

The routes appear one at a time in the Scripting log.

Note that the Step Into button can continue iterating through the loop as well as stepping into the function. When the loop is completed, the statement is also complete and so the model is solved.

At any point you can continue execution to the end of the script without stopping by clicking the Resume button Continue button in the Debug view.