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.

After this, the program finishes by making a call to CPXsolution to obtain the values foreach variable in this optimal solution, printing these values, and writing the problem to adisk file (for possible evaluation by the user) via the call to CPXwriteprob. It thenterminates after freeing all the arrays that have been allocated along the way.Complete ProgramThe complete program, diet.c, appears online in the standard distribution atyour<strong>CPLEX</strong>installation/examples/src.Using Surplus Arguments for Array AllocationsMost of the <strong>ILOG</strong> <strong>CPLEX</strong> query routines in the Callable Library require your application toallocate memory for one or more arrays that will contain the results of the query. In manycases, your application—the calling program—does not know the size of these arrays inadvance. For example, in a call to CPXgetcols requesting the matrix data for a range ofcolumns, your application needs to pass the arrays cmatind and cmatval for<strong>ILOG</strong> <strong>CPLEX</strong> to populate with matrix coefficients and row indices. However, unless yourapplication has carefully kept track of the number of nonzeros in each column throughoutthe problem specification and, if applicable, throughout its modification, the actual length ofthese arrays remains unknown.Fortunately, the <strong>ILOG</strong> <strong>CPLEX</strong> query routines in the Callable Library contain a surplus_pargument that, when used in conjunction with the array length arguments, enables you firstto call the query routine to discover the length of the required array. Then, when the length isknown, your application can properly allocate these arrays. Afterwards, your applicationmakes a second call to the query routine with the correct array lengths to obtain therequested data.For example, consider a program that needs to call CPXgetcols to access a range ofcolumns. Here is the list of arguments for CPXgetcols.CPXgetcols (CPXENVptr env,CPXLPptr lp,int *nzcnt_p,int *cmatbeg,int *cmatind,double *cmatval,int cmatspace,int *surplus_p,int begin,int end);The arrays cmatind and cmatval require one element for each nonzero matrix coefficientin the requested range of columns. The required length of these arrays, specified incmatspace, remains unknown at the time of the query. Your application—the calling128 <strong>ILOG</strong> <strong>CPLEX</strong> <strong>11.0</strong> — USER’ S MANUAL

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

Saved successfully!

Ooh no, something went wrong!