QSopt QSadd_rows QSopt > Callable Library > Function List
  QSopt
  Downloads
  LP Info
  Software
  Problem Formats
  Callable Library
  Overview
Function List
  Rational Solver
  Beta
  Contact Info
Purpose
Add a set of rows (constraints) to the problem.
Synopsis
int QSadd_rows (QSprob p, int num, int *rmatcnt, int *rmatbeg,
    int *rmatind, double *rmatval, double *rhs, char *sense,
    char **names)
Arguments
p a handle to an initialized problem.
num the number of rows to be added.
rmatcnt an array of length num; the ith entry specifies the number of non-zero coefficients in the ith row to be added to the LP problem.
rmatbeg an array of length num; the ith entry specifies the location of the start of the ith row in the rmatind and rmatval arrays.
rmatind an array that contains the column indices of the non-zero coefficients in the rows to be added. The indices for the ith row must be stored consecutively starting at entry number rmatbeg[i] (there are rmatcnt[i] indices for the ith row).
rmatval an array that contains the values of the non-zero coefficients in the rows to be added. The coefficients for the ith row must be stored consecutively starting at entry number rmatbeg[i] (there are rmatcnt[i] non-zero coefficients for the ith row).
rhs an array of length num; the ith entry is the right-hand-side value of the ith constraint.
sense an array of length num; 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'.
names an array of length num; the ith entry is a string that specifies the name of the ith constraint to be added (the names field can be NULL).
Returns
A zero value if the function terminated correctly, and a non-zero value if an error occurred.
Description

Use QSadd_rows to add a collection of constraints to an LP problem, including the non-zero coefficients of the constraints in the existing columns of the problem. The arguments to specify the non-zero coefficients follow the same pattern as in QSload_prob.

When specifying rmatval and rhs, 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.

Note that to add single constraint, it is simpler to use QSadd_row.)

Example
/* Assume p is initialized to the problem in the QSload_prob example. */
/* Add two new rows to obtain the following LP.                       */
/*       Maximize  3.0x + 2.0y + 4.0z                                 */
/*       Subject to                                                   */
/*                 3.1x + 2.3y + 1.4z <= 12.2                         */
/*                 5.0x + 1.1y         = 10.0                         */
/*                 0.5x + 2.0y + 4.0z >=  6.0    New                  */
/*                        3.0y + 2.0z <=  8.0    New                  */
/*                 x >= 2.0                                           */
/*                 y free                                             */
/*                 1.0 <= z <= 10.0                                   */
/*                                                                    */

int rval;
int rmatcnt[2] = { 3, 2 };
int rmatbeg[2] = { 0, 3 };
int rmatind[5] = { 0, 1, 2, 1, 2 };
double rmatval[5] = { 0.5, 2.0, 4.0, 3.0, 2.0 };
double rhs[2] = { 6.0, 8.0 };
char sense[2] = { 'G', 'L' };

rval = QSadd_rows (p, 2, rmatcnt, rmatbeg, rmatind, rmatval, rhs,
                   sense, (char **) NULL);
if (rval) {
    fprintf (stderr, "Add rows failed, error code %d\n", rval);
} else {
    rval = QSwrite_prob (p, "new2small.lp", "LP");
    if (rval) {
        fprintf (stderr, "Could not write LP, error code %d\n", rval);
    }
}
 
QSopt | Problem Formats | Downloads Back
Last Updated: November 2003