Checking and debugging problem data

Describes routines to verify problem data and diagnose bugs in an application of the C API.

If you inadvertently make an error entering problem data, the problem object will not correspond to your intentions. One possible result may be a segmentation fault or other disruption of your application. In other cases, CPLEX may solve a different model from the one you intended, and that situation may or may not result in error messages from CPLEX.

Using the data checking parameter

To help you detect this kind of error, you can set the data consistency checking and modeling assistance parameter CPX_PARAM_DATACHECK(int) to the value CPX_ON to activate additional checking of array arguments for CPXcopyData, CPXreadData, and CPXchgData routines (where Data varies). The additional checks include:

  • invalid sense /ctype /sostype values

  • indices out of range, for example, rowind numrows

  • duplicate entries

  • matbeg or sosbeg array with decreasing values

  • NANs in double arrays

  • NULLs in name arrays

This additional checking may entail overhead (time and memory). When the parameter is set to CPX_OFF, only simple checks are performed, for example, checking for the existence of the environment.

Using diagnostic routines for debugging

CPLEX also provides diagnostic routines to look for common errors in the definition of problem data. In the standard distribution of CPLEX, the file check.c contains the source code for these routines:

Each of those routines performs a series of diagnostic tests of the problem data and issues warnings or error messages whenever it detects a potential error. To use them, you must compile and link the file check.c. After compiling and linking that file, you will be able to step through the source code of these routines with a debugger to help isolate problems.

If you have observed anomalies in your application, you can exploit this diagnostic capability by calling the appropriate routines just before a change or copy routine. The diagnostic routine can then detect errors in the problem data that could subsequently cause inexplicable behavior.

Those checking routines send all messages to one of the standard CPLEX message channels. You capture that output by setting a parameter (that is, the messages to screen switch CPX_PARAM_SCRIND) if you want messages directed to your screen or by calling the routine CPXXsetlogfilename if you want to direct messages to a log file.