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.

Here’s another way to visualize a column, such as column j in this example:foodCost[j]nutrper[0][j]nutrper[1][j]...nutrper[m-1][j]Program DescriptionAll definitions needed for a <strong>ILOG</strong> <strong>CPLEX</strong> Callable Library program are imported byincluding file at the beginning of the program. After a number oflines that establish the calling sequences for the routines that are to be used, the program’smain function begins by checking for correct command line arguments, printing a usagereminder and exiting in case of errors.Next, the data defining the problem are read from a file specified in the command line at runtime. 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 ofseveral nutrients needed in the diet are specified; finally, a table giving levels of each nutrientfound in each unit of food is given. The result of a successful call to this routine is twovariables 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, nutrmaxcontaining nutritional requirements for the proposed diet, and array nutrper containing thenutritional value of the foods.Preparations to build and solve the model with <strong>ILOG</strong> <strong>CPLEX</strong> begin with the call toCPXopen<strong>CPLEX</strong>. This establishes an <strong>ILOG</strong> <strong>CPLEX</strong> environment to contain the LP problem,and succeeds only if a valid <strong>ILOG</strong> <strong>CPLEX</strong> license is found.After calls to set parameters, one to control the output that comes to the user's terminal, andanother to turn on data checking for debugging purposes, a problem object is initializedthrough 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 byan argument on the command line. The routine populatebyrow operates by first definingall the columns through a call to CPXnewcols and then repeatedly calls CPXaddrows toenter the data of the constraints. The routine populatebycolumn takes the complementaryapproach of establishing all the rows first with a call to CPXnewrows and then sequentiallyadds the column data by calls to CPXaddcols.Solving the Model with CPXlpoptThe model is at this point ready to be solved, and this is accomplished through the call toCPXlpopt, which by default uses the dual simplex optimizer.<strong>ILOG</strong> <strong>CPLEX</strong> <strong>11.0</strong> — USER’ S MANUAL 127

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

Saved successfully!

Ooh no, something went wrong!