Program description
Describes the architecture of an application from the C API solving the diet problem.
All definitions needed for a Callable Library application are imported
when your application includes the file <ilcplex/cplex.h> at
the beginning of the application. After a number of lines that establish
the calling sequences for the routines that are to be used, the main
function of the application 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 about 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 CPLEX begin with
the call to CPXopenCPLEX.
This establishes a CPLEX environment to contain the LP problem.
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.