QSopt QSload_prob QSopt > Callable Library > Function List
  QSopt
  Downloads
  LP Info
  Software
  Problem Formats
  Callable Library
  Overview
Function List
  Rational Solver
  Beta
  Contact Info
Purpose
Build a problem from user data.
Synopsis
QSprob QSload_prob (const char *probname, int ncols, int nrows,
    int *cmatcnt, int *cmatbeg, int *cmatind, double *cmatval,
    int objsense, double *obj, double *rhs, char *sense, double *lower,
    double *upper, const char **colnames, const char **rownames)
Arguments
probname a string containing the name of the problem (can be NULL).
ncols specifies the number of columns.
nrows specifies the number of rows.
cmatcnt an array of length ncols; the jth entry specifies the number of non-zeros in the jth column.
cmatbeg an array of length ncols; the jth entry specifies the location of the start of the entries for the jth column in the arrays cmatind and cmatval.
cmatind an array that contains the row indices of the non-zero entries in the constraint matrix. The indices of the jth column must be stored consecutively starting at entry number cmatbeg[j] (there are cmatcnt[j] entries for the jth column).
cmatval an array that contains the values of the non-zero entries in the constraint matrix. The non-zero values of the jth column must be stored consecutively starting at entry number cmatbeg[j] (there are cmatcnt[j] entries for the jth column).
objsense specifies if the problem is a minimization problem or a maximization problem; to specify a minimization problem set objsense to QS_MIN (that is, 1) and to specify a maximization problem set objsense to QS_MAX (that is, -1).
obj an array of length ncols; the jth entry is the coefficient of the jth variable in the objective function.
rhs an array of length nrows; the ith entry is the right-hand-side value of the ith constraint.
sense an array of length nrows; the ith entry specifies the sense of the ith constraint; to specify an equation use 'E', to specify a = constraint use 'L', and to specify a ≤ constraint use 'G'.
lower an array of length ncols; the jth entry is the lower bound for the jth variable (use -QS_MAXDOUBLE if the jth variable has no lower bound).
upper an array of length ncols; the jth entry is the upper bound for the jth variable (use QS_MAXDOUBLE if the jth variable has no upper bound).
colnames an array of length ncols; the jth entry is a string that specifies the name of the jth variable (the colnames field can be NULL).
rownames an array of length nrows; the ith entry is a string that specifies the name of the ith constraint (the rownames field can be NULL).
Returns
An initialized QSprob object, providing a handle to the problem described by the specified data. If an error occurred, the QSprob object is set to NULL.
Description

The arguments to QSload_prob provide a method to completely describe an LP problem; the cost of this completeness is the frightening appearance of the argument list itself. Most applications can be written more cleanly using QScreate_prob to initialize an empty QSprob, and then filling-in the LP data piece by piece with the problem modification routines described in the Modifying an LP Problem section from the Callable Function List.

In some cases, however, it is convenient to load everything in a single stroke. For example, if an application stores all data for an LP in a problem-specific format, then it is natural to use QSload_prob to load all of the information into the QSopt solver. Note that the specification of both cmatcnt and cmatbeg is an overkill, since if the data arrays are packed densely, then the cmatbeg values can be determined by the cmatcnt values. The point in using both cmatcnt and cmatbeg is to allow applications the freedom of providing gaps in the data arrays. (This may be helpful, for example, when a application builds its LP data before exact counts of the number of non-zeros in each column are available.) When specifying the constraint coefficients, objective coefficients, right-and-aside values, and upper and lower bounds, it is important not to give any value larger in magnitude than QS_MAXDOUBLE (1e30). This restriction is due to the internal structures used in the QSopt solvers.

Example
/*                                                      */
/*  Using QSload_prob to load the following LP problem  */
/*       Maximize  3.0x + 2.0y + 4.0z                   */
/*       Subject to                                     */
/*                 3.1x + 2.3y + 1.4z <= 12.2           */
/*                 5.0x + 1.1y         = 10.0           */
/*                 x >= 2.0                             */
/*                 y free                               */
/*                 1.0 <= z <= 10.0                     */
/*                                                      */

int rval;
QSprob p;
int cmatcnt[3]    = { 2, 2, 1 };
int cmatbeg[3]    = { 0, 2, 4 };
int cmatind[5]    = { 0, 1, 0, 1, 0 };
double cmatval[5] = { 3.1, 5.0, 2.3, 1.1, 1.4 };
double obj[3]     = { 3.0, 2.0, 4.0 };
double rhs[2]     = { 12.2, 10.0 };
char sense[2]     = { 'L', 'E' };
double lower[3]   = { 2.0, -QS_MAXDOUBLE, 1.0 };
double upper[3]   = { QS_MAXDOUBLE, QS_MAXDOUBLE, 10.0 };
const char *colnames[3] = { "x", "y", "z" };

p = QSload_prob ("small", 3, 2, cmatcnt, cmatbeg, cmatind, cmatval,
                  QS_MAX, obj, rhs, sense, lower, upper, colnames,
                  (char **) NULL);

if (p == (QSprob) NULL) {
    fprintf (stderr, "Unable to load the LP problem\n");
} else {
    /* As a check, write the LP to a file */
    rval = QSwrite_prob (p, "small.lp", "LP");
    if (rval) {
        fprintf (stderr, "Could not write LP, error code %d\n", rval);
    }
}
 
QSopt | Problem Formats | Downloads Back
Last Updated: November 2003