ILOG CPLEX 11.0 User's Manual > Languages and APIs > ILOG CPLEX Callable Library > Example: Optimizing the Diet Problem in the Callable Library > Program Description

All definitions needed for a ILOG CPLEX Callable Library program are imported by including file <ilcplex/cplex.h> at the beginning of the program. After a number of lines that establish the calling sequences for the routines that are to be used, the program's main function begins by checking for correct command line arguments, printing a usage reminder and exiting in case of errors.

Next, the data defining the problem are read from a file specified in the command line at run time. The details of this are handled in the routine readdata. In this file, cost, lower bound, and upper bound are specified for each type of food; then minimum and maximum levels of several nutrients needed in the diet are specified; finally, a table giving levels of each nutrient found in each unit of food is given. The result of a successful call to this routine is two variables nfoods and nnutr containing the number of foods and nutrients in the data file, arrays cost, lb, ub containing the information on the foods, arrays nutrmin, nutrmax containing nutritional requirements for the proposed diet, and array nutrper containing the nutritional value of the foods.

Preparations to build and solve the model with ILOG CPLEX begin with the call to CPXopenCPLEX. This establishes an ILOG CPLEX environment to contain the LP problem, and succeeds only if a valid ILOG CPLEX license is found.

After calls to set parameters, one to control the output that comes to the user's terminal, and another to turn on data checking for debugging purposes, a problem object is initialized through the call to CPXcreateprob. This call returns a pointer to an empty problem object, which now can be populated with data.

Two alternative approaches to filling this problem object are implemented in this program, populatebyrow and populatebycolumn, and which one is executed is set at run time by an argument on the command line. The routine populatebyrow operates by first defining all the columns through a call to CPXnewcols and then repeatedly calls CPXaddrows to enter the data of the constraints. The routine populatebycolumn takes the complementary approach of establishing all the rows first with a call to CPXnewrows and then sequentially adds the column data by calls to CPXaddcols.