12.07.2015 Views

ILOG CPLEX 11.0 User's Manual

ILOG CPLEX 11.0 User's Manual

ILOG CPLEX 11.0 User's Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

along with a label indicating which channel sent the message. It also creates a user channelto receive output generated by the program itself. The user channel accepts user-generatedmessages, displays them on screen with a label, and records them in a file without the label.The complete program lpex5.c appears online in the standard distribution atyour<strong>CPLEX</strong>installation/examples/src. This example derives from lpex1.c, aprogram in the <strong>ILOG</strong> <strong>CPLEX</strong> Getting Started manual. There are a few differences betweenthe two examples:◆◆◆In this example, the function ourmsgfunc (rather than the C functions printf orfprintf(stderr, . . .)) manages all output. The program itself or CPXmsg fromthe <strong>ILOG</strong> <strong>CPLEX</strong> Callable Library calls ourmsgfunc. In fact, CPXmsg is a replacementfor printf, allowing a message to appear in more than one place, for example, both onscreen and in a file.Only after you initialize the <strong>ILOG</strong> <strong>CPLEX</strong> environment by calling CPXopen<strong>CPLEX</strong> canyou call CPXmsg. And only after you call CPXgetchannels can you use the default<strong>ILOG</strong> <strong>CPLEX</strong> channels. Therefore, calls to ourmsgfunc print directly any messagesthat occur before the program gets the address of cpxerror (a channel). After a call toCPXgetchannels gets the address of cpxerror, and after a call to CPXaddfuncdestassociates the message function ourmsgfunc with cpxerror, then error messages aregenerated by calls to CPXmsg.After the TERMINATE: label, any error must be generated with care in case the errormessage function has not been set up properly. Thus, ourmsgfunc is also called directlyto generate any error messages there.A call to the <strong>ILOG</strong> <strong>CPLEX</strong> Callable Library routine CPXaddchannel initializes thechannel ourchannel. The Callable Library routine fopen opens the file lpex5.out toaccept solution information. A call to the <strong>ILOG</strong> <strong>CPLEX</strong> Callable Library routineCPXaddfpdest associates that file with that channel. Solution information is alsodisplayed on screen since ourmsgfunc is associated with that new channel, too. Thus inthe loops near the end of main, when the solution is printed, only one call to CPXmsgsuffices to put the output both on screen and into the file. A call to CPXdelchanneldeletes ourchannel.Although CPXclose<strong>CPLEX</strong> will automatically delete file- and function-destinations forchannels, it is a good practice to call CPXdelfpdest and CPXdelfuncdest at the endof your programs.<strong>ILOG</strong> <strong>CPLEX</strong> <strong>11.0</strong> — USER’ S MANUAL 153

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!