Preparations to build and solve the model with CPLEX begin with the call to CPXopenCPLEX()
. This establishes a CPLEX environment in which to contain the LP problem, and succeeds only if a valid CPLEX license is found.
After some calls to set parameters, one to control the output that comes to the user's terminal, and the other 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 determined at run time by a calling parameter 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()
.
The model is at this point ready to be solved, and this is accomplished through the call to CPXlpopt()
, which by default uses the dual simplex optimizer.
After this, the program finishes by making a call to CPXsolution()
to obtain the values for each variable in this optimal solution, printing these values, and writing the problem to a disk file (for possible evaluation by the user) via the call to CPXwriteprob()
. It then terminates after freeing all the arrays that have been allocated along the way.