 |
int QSget_rows (QSprob p, int **rowcnt, int **rowbeg, int **rowind,
double **rowval, double **rhs, char **sense, char ***names)
|
 |
A complete description of the constraints for the problem can be obtained using this function. Each of the arguments returns an array that is allocated by QSget_rows; if some piece of information is not needed, the corresponding argument for the function should be set to NULL . The calling function should free the memory for each of the arrays (and for the strings in the names array) when the information is no longer needed; since the memory for the arrays and strings is allocated by the QSopt library, the memory must be freed with calls to QSfree and not by the system free() function. The form of the row information is the same as that used in the QSadd_rows function.
|
 |
/* p is an initialized QSprob, a handle to an existing LP problem */
double *rowval = NULL, *rhs = NULL;
int *rowcnt = NULL, *rowbeg = NULL, *rowind = NULL;
char *sense = NULL, **names = NULL;
int nrows, i, j, rval;
nrows = QSget_rowcount (p);
rval = QSget_rows (p, &rowcnt, &rowbeg, &rowind, &rowval, &rhs, &sense,
&names);
if (rval) {
fprintf (stderr, "could not obtain rows, error code %d\n", rval);
} else {
for (i = 0; i < nrows; i++) {
printf ("%s RHS = %f, SENSE = %c\n",
names[i], rhs[i], sense[i]);
printf (" Coefficients: ");
for (j = rowbeg[i]; j < rowbeg[i] + rowcnt[i]; j++) {
printf ("(%d, %f) ", rowind[j], rowval[j]);
}
printf ("\n");
}
}
QSfree (rowcnt); QSfree (rowbeg); QSfree (rowind); QSfree (rowval);
QSfree (rhs); QSfree (sense);
if (names) {
for (i = 0; i < nrows; i++) {
QSfree (names[i]);
}
QSfree (names);
}
|