IBM ILOG Solver Debugger User's Manual > Debugging and Performance Tuning for Solver-based Applications > Instrumenting Your Own Code

This section explains how to customize the Debugger for Solver or Scheduler applications.

Customizing a Pure Solver C++ Application

To customize the Debugger for a pure Solver C++ application, proceed as follows. You need one include file before the solver declaration:

#include <ilsolver/solverdebugger.h> 
 
IloEnv env; 
try { 
  IloSolver solver(env); 
  1. Instantiate the Debugger and let it connect your application to the GUI before model extraction.
IlcSolverDebugger debugger(solver); 
  1. State the model using Ilo modeling objects.
IloModel model(env); 
  1. Name your Ilo objects (setName API).
myVar.setName("myVar");
  1. Register the variables you are interested in for model browsing, domain monitoring, etc. (Optional).
debugger.registerVariable(myVar); 
If you want domain visualization, specify it.
debugger.registerVariable(myVar2, IloTrue, IloTrue, IlcVisualizeDomain);
  1. Extract the model Ilo objects as Ilc objects.
solver.extract(model); 
  1. Initialize the Debugger for each running session and solve by placing your optimization loop inside the debugging loop.
  while (debugger.initialize()) { // debugging loop 
    solver.startNewSearch(myGoal); 
    while (solver.next()) { // optimization loop 
      ostrstream text; 
      text << solver.getValue(makespan)<< endl << ends; 
      debugger.sendSolution(text.str()); 
    } 
    solver.endSearch(); 
  } 
  1. Close the connection to the GUI and release memory.
  debugger.close(); 
} catch (IloException& ex) { 
  cerr << "Error: " << ex << endl; 
} 
env.end(); 

Customizing a Pure Scheduler C++ Application

To customize the Debugger for a pure Scheduler C++ application, proceed as follows. You need two include files before the solver declaration:

#include <ilsolver/solverdebugger.h> 
#include <ilsched/schedulerdebugger.h> 
 
try { 
  IloEnv env; 
  IloSolver solver(env); 
  1. Instantiate the Debugger.
  IlcSolverDebugger debugger(solver); 
  1. State the model using Ilo modeling objects.
  IloModel model(env); 
  IloSchedulerEnv schedEnv(env); 
  IloInt horizon = 0; 
  IloInt k; 
  for (k = 0; k < numberOfActivities; k++) 
    horizon += durations[k];

Warning
Make sure that you set the global horizon for every activity:

schedEnv.setHorizon(horizon);

  1. Name your Ilo objects (setName API).
  2. Create a Scheduler Debugger to handle specific panels.
  IlcScheduler schedule(solver); 
  IlcSchedulerDebugger schedDebug(debugger,schedule); 
  1. Register the Ilo objects with the Solver Debugger and the Scheduler Debugger.
  debugger.registerVariable(makespan,IloTrue,IloTrue,IlcVisualizeDomain); 
  schedDebug.registerActivity(activity,IloTrue,IloTrue,IlcVisualizeDomain);
  1. Inform the Activity Panel of the horizon to display.
  schedDebugger.setHorizon(horizon); 
  1. Extract the model Ilo objects as Ilc objects.
  solver.extract(model); 
  1. Initialize the Debugger for each running session and solve by placing your optimization loop inside the debugging loop.
  while (debugger.initialize()) { // debugging loop 
    solver.startNewSearch(myGoal); 
    while (solver.next()) { // optimization loop 
     ostrstream text; 
     text << solver.getValue(makespan)<< endl << ends; 
     debugger.sendSolution(text.str()); 
    } 
    solver.endSearch(); 
  } 
  env.end(); 
  1. Close the connection to the GUI and release memory.
  debugger.close(); 
  } catch (IloException& ex) { 
    cerr << "Error: " << ex << endl; 
}