dbl_qsopt.c

Go to the documentation of this file.
00001 /****************************************************************************/
00002 /*                                                                          */
00003 /*  This file is part of QSopt_ex.                                          */
00004 /*                                                                          */
00005 /*  (c) Copyright 2006 by David Applegate, William Cook, Sanjeeb Dash,      */
00006 /*  and Daniel Espinoza                                                     */
00007 /*                                                                          */
00008 /*  Sanjeeb Dash ownership of copyright in QSopt_ex is derived from his     */
00009 /*  copyright in QSopt.                                                     */
00010 /*                                                                          */
00011 /*  This code may be used under the terms of the GNU General Public License */
00012 /*  (Version 2.1 or later) as published by the Free Software Foundation.    */
00013 /*                                                                          */
00014 /*  Alternatively, use is granted for research purposes only.               */
00015 /*                                                                          */
00016 /*  It is your choice of which of these two licenses you are operating      */
00017 /*  under.                                                                  */
00018 /*                                                                          */
00019 /*  We make no guarantees about the correctness or usefulness of this code. */
00020 /*                                                                          */
00021 /****************************************************************************/
00022 
00023 /* RCS_INFO = "$RCSfile: dbl_qsopt.c,v $ $Revision: 1.2 $ $Date: 2003/11/05 16:49:52 $"; */
00024 static int TRACE = 0;
00025 
00026 /****************************************************************************/
00027 /*                                                                          */
00028 /*                     User-level Functions                                 */
00029 /*                                                                          */
00030 /*  EXPORTED FUNCTIONS                                                      */
00031 /*                                                                          */
00032 /*    int dbl_QSopt_primal (dbl_QSdata *p, int *status)                             */
00033 /*    int dbl_QSopt_dual (dbl_QSdata *p, int *status)                               */
00034 /*    dbl_QSdata *dbl_QScreate_prob (const char *name, int objsense)                */
00035 /*    dbl_QSdata *dbl_QSread_prob (const char *filename, const char *filetype)      */
00036 /*    dbl_QSdata *dbl_QSload_prob (const char *probname, int ncols, int nrows,      */
00037 /*        int *cmatcnt, int *cmatbeg, int *cmatind, double *cmatval,        */
00038 /*        int objsense, double *obj, double *rhs, char *sense,              */
00039 /*        double *lower, double *upper, const char **colnames,              */
00040 /*        const char **rownames)                                            */
00041 /*    dbl_QSdata *dbl_QScopy_prob (dbl_QSdata *p, const char *newname)                  */
00042 /*    int dbl_QSchange_objsense (dbl_QSdata *p, int newsense)                       */
00043 /*    int dbl_QSget_objsense (dbl_QSdata *p, int *objsense)                         */
00044 /*    int dbl_QSnew_col (dbl_QSdata *p, double obj, double lower, double upper,     */
00045 /*        const char *name)                                                 */
00046 /*    int dbl_QSadd_cols (dbl_QSdata *p, int num, int *cmatcnt, int *cmatbeg,       */
00047 /*        int *cmatind, double *cmatval, double *obj, double *lower,        */
00048 /*        double *upper, const char **names)                                */
00049 /*    int dbl_QSadd_col (dbl_QSdata *p, int cnt, int *cmatind, double *cmatval,     */
00050 /*        double obj, double lower, double upper, const char *name)         */
00051 /*    int dbl_QSnew_row (dbl_QSdata *p, double rhs, const char sense, char *name)   */
00052 /*    int dbl_QSadd_rows (dbl_QSdata *p, int num, int *rmatcnt, int *rmatbeg,       */
00053 /*        int *rmatind, double *rmatval, double *rhs, char *sense,          */
00054 /*        char **names)                                                     */
00055 /*    int dbl_QSadd_row (dbl_QSdata *p, int cnt, int *rmatind, double *rmatval,     */
00056 /*        double rhs, char sense, const char *name)                         */
00057 /*    int dbl_QSdelete_rows (dbl_QSdata *p, int num, int *dellist)                  */
00058 /*    int dbl_QSdelete_row (dbl_QSdata *p, int rowindex)                            */
00059 /*    int dbl_QSdelete_setrows (dbl_QSdata *p, int *flags)                          */
00060 /*    int dbl_QSdelete_cols (dbl_QSdata *p, int num, int *dellist)                  */
00061 /*    int dbl_QSdelete_col (dbl_QSdata *p, int colindex)                            */
00062 /*    int dbl_QSdelete_setcols (dbl_QSdata *p, int *flags)                          */
00063 /*    int dbl_QSdelete_named_column (dbl_QSdata *p, const char *colname)            */
00064 /*    int dbl_QSdelete_named_columns_list (dbl_QSdata *p, int num,                  */
00065 /*        const char **colnames)                                            */
00066 /*    int dbl_QSdelete_named_row (dbl_QSdata *p, const char *rowname)               */
00067 /*    int dbl_QSdelete_named_rows_list (dbl_QSdata *p, int num,                     */
00068 /*        const char **rownames)                                            */
00069 /*    int dbl_QSchange_senses (dbl_QSdata *p, int num, int *rowlist, char *sense)   */
00070 /*    int dbl_QSchange_sense (dbl_QSdata *p, int rowindex, char sense)              */
00071 /*    int dbl_QSchange_coef (dbl_QSdata *p, int rowindex, int colindex,             */
00072 /*        double coef)                                                      */
00073 /*    int dbl_QSchange_objcoef (dbl_QSdata *p, int indx, double coef)               */
00074 /*    int dbl_QSchange_rhscoef (dbl_QSdata *p, int indx, double coef)               */
00075 /*    int dbl_QSchange_bounds (dbl_QSdata *p, int num, int *collist, char *lu,      */
00076 /*        double *bounds)                                                   */
00077 /*    int dbl_QSchange_bound (dbl_QSdata *p, int indx, char lu, double bound)       */
00078 /*    int dbl_QSwrite_basis (dbl_QSdata *p, QSbasis *B, const char *filename)       */
00079 /*    QSbasis *dbl_QSget_basis (dbl_QSdata *p)                                      */
00080 /*    QSbasis *dbl_QSread_basis (dbl_QSdata *p, const char *filename)               */
00081 /*    int dbl_QSload_basis (dbl_QSdata *p, QSbasis *B)                              */
00082 /*    int dbl_QSread_and_load_basis (dbl_QSdata *p, const char *filename)           */
00083 /*    int dbl_QSload_basis_array (dbl_QSdata *p, char *cstat, char *rstat)          */
00084 /*    int dbl_QSload_basis_and_row_norms_array (dbl_QSdata *p, char *cstat,         */
00085 /*      char *rstat, double *rownorms)                                      */
00086 /*    int dbl_QSget_basis_array (dbl_QSdata *p, char *cstat, char *rstat)           */
00087 /*    int dbl_QSget_basis_and_row_norms_array (dbl_QSdata *p, char *cstat,          */
00088 /*      char *rstat, double *rownorms)                                      */
00089 /*    int dbl_QSget_binv_row (dbl_QSdata *p, int indx, double *binvrow)             */
00090 /*    int dbl_QSget_tableau_row (dbl_QSdata *p, int indx, double *tableaurow)       */
00091 /*    int dbl_QSget_basis_order (dbl_QSdata *p, int *basorder)                      */
00092 /*    int dbl_QSget_status (dbl_QSdata *p, int *status)                             */
00093 /*    int dbl_QSget_solution (dbl_QSdata *p, double *value, double *x,              */
00094 /*        double *pi, double *slack, double *rc),                           */
00095 /*    int dbl_QSget_objval (dbl_QSdata *p, double *value)                           */
00096 /*    int dbl_QSget_x_array (dbl_QSdata *p, double *x)                              */
00097 /*    int dbl_QSget_rc_array (dbl_QSdata *p, double *rc)                            */
00098 /*    int dbl_QSget_pi_array (dbl_QSdata *p, double *pi)                            */
00099 /*    int dbl_QSget_slack_array (dbl_QSdata *p, double *slack)                      */
00100 /*    int dbl_QSget_infeas_array (dbl_QSdata *p, double *pi)                        */
00101 /*    int dbl_QSget_named_x (dbl_QSdata *p, const char *colname, double *val)       */
00102 /*    int dbl_QSget_named_rc (dbl_QSdata *p, const char *colname, double *val)      */
00103 /*    int dbl_QSget_named_pi (dbl_QSdata *p, const char *rowname, double *val)      */
00104 /*    int dbl_QSget_named_slack (dbl_QSdata *p, const char *rowname, double *val)   */
00105 /*    int dbl_QSget_colcount (dbl_QSdata *p)                                        */
00106 /*    int dbl_QSget_rowcount (dbl_QSdata *p)                                        */
00107 /*    int dbl_QSget_nzcount (dbl_QSdata *p)                                         */
00108 /*    int dbl_QSget_obj (dbl_QSdata *p, double *obj),                               */
00109 /*    int dbl_QSget_rhs (dbl_QSdata *p, double *rhs)                                */
00110 /*    char* dbl_QSget_probname (dbl_QSdata *p)                                      */
00111 /*    char* dbl_QSget_objname (dbl_QSdata *p)                                       */
00112 /*    int dbl_QSget_columns (dbl_QSdata *p, int **colcnt, int **colbeg,             */
00113 /*        int **colind, double **colval, double **obj, double **lower,      */
00114 /*        double **upper, char ***names)                                    */
00115 /*    int dbl_QSget_columns_list (dbl_QSdata *p, int num, int *collist,             */
00116 /*        int **colcnt, int **colbeg, int **colind, double **colval,        */
00117 /*        double **obj, double **lower, double **upper, char ***names)      */
00118 /*    int dbl_QSget_rows (dbl_QSdata *p, int **rowcnt, int **rowbeg, int **rowind,  */
00119 /*        double **rowval, double **rhs, char **sense, char ***names)       */
00120 /*    int dbl_QSget_rows_list (dbl_QSdata *p, int num, int *rowlist, int **rowcnt,  */
00121 /*        int **rowbeg, int **rowind, double **rowval, double **rhs,        */
00122 /*        char **sense, char ***names)                                      */
00123 /*    int dbl_QSget_column_index (dbl_QSdata *p, const char *name, int *colindex)   */
00124 /*    int dbl_QSget_row_index (dbl_QSdata *p, const char *name, int *rowindex)      */
00125 /*    int dbl_QSget_rownames (dbl_QSdata *p, char **rownames)                       */
00126 /*    int dbl_QSget_colnames (dbl_QSdata *p, char **colnames)                       */
00127 /*    int dbl_QSget_bound (dbl_QSdata *p, int colindex, char lu, double *bound)     */
00128 /*    int dbl_QSget_bounds (dbl_QSdata *p, double *lower, double *upper)            */
00129 /*    int dbl_QSget_intcount (dbl_QSdata *p, int *count)                            */
00130 /*    int dbl_QSget_intflags (dbl_QSdata *p, int *intflags)                         */
00131 /*    int dbl_QScompute_row_norms (dbl_QSdata *p)                                   */
00132 /*    void dbl_QSfree_prob (dbl_QSdata *p)                                          */
00133 /*    void dbl_QSfree_basis (QSbasis *B)                                        */
00134 /*    int dbl_QSwrite_prob (dbl_QSdata *p, const char *filename,                    */
00135 /*        const char *filetype)                                             */
00136 /*    int dbl_QSwrite_prob_file (dbl_QSdata *p, FILE *file, const char *filetype)   */
00137 /*    int dbl_QSset_param (dbl_QSdata *p, int whichparam, int newvalue)             */
00138 /*    int QSset_param_double (dbl_QSdata *p, int whichparam, double newvalue)   */
00139 /*    int dbl_QSget_param (dbl_QSdata *p, int whichparam, int *value)               */
00140 /*    int QSget_param_double (dbl_QSdata *p, int whichparam, double *value)     */
00141 /*    int dbl_QStest_row_norms (dbl_QSdata *p)                                      */
00142 /*    int dbl_QSopt_strongbranch (dbl_QSdata *p, int ncand, int *candidatelist,     */
00143 /*        double *xlist, double *down_vals, double *up_vals,                */
00144 /*        int iterations, double objbound)                                  */
00145 /*    int dbl_QSopt_pivotin_row (dbl_QSdata *p, int rcnt, int *rlist)               */
00146 /*    int dbl_QSopt_pivotin_col (dbl_QSdata *p, int ccnt, int *clist)               */
00147 /*    void dbl_QSfree (void *ptr)                                               */
00148 /*    void dbl_QSstart (void)                                                   */
00149 /*    void dbl_QSend (void)                                                     */
00150 /*    char *dbl_QSversion (void))                                               */
00151 /*                                                                          */
00152 /*    dbl_NEW FUNCTIONS - Add to Docs                                           */
00153 /*                                                                          */
00154 /*    char *dbl_QSversion (void))                                               */
00155 /*    int dbl_QSget_objsense (dbl_QSdata *p, int *objsense)                         */
00156 /*                                                                          */
00157 /****************************************************************************/
00158 
00159 #include "qs_config.h"
00160 #include "dbl_iqsutil.h"
00161 #include "dbl_lpdata.h"
00162 #include "dbl_lpdefs.h"
00163 #include "dbl_simplex.h"
00164 #include "dbl_price.h"
00165 #include "dbl_qstruct.h"
00166 #include "dbl_qsopt.h"
00167 #include "dbl_lib.h"
00168 #include "dbl_mps.h"
00169 #include "dbl_lp.h"
00170 #ifdef USEDMALLOC
00171 #include "dmalloc.h"
00172 #endif
00173 void dbl_QSset_precision (
00174   const unsigned prec)
00175 {
00176   EGlpNumSetPrecision (prec);
00177   dbl_ILLchange_precision ();
00178   /* change the numbers */
00179 }
00180 
00181 static void dbl_init_basis (
00182   QSbasis * B),
00183   dbl_free_cache (
00184   dbl_QSdata * p);
00185 
00186 int dbl_grab_cache ( dbl_QSdata * p, int status);
00187 static int dbl_opt_work ( dbl_QSdata * p, int *status, int primal_or_dual),
00188   dbl_qsbasis_to_illbasis ( QSbasis * qB, dbl_ILLlp_basis * B),
00189   dbl_illbasis_to_qsbasis ( dbl_ILLlp_basis * B, QSbasis * qB),
00190   dbl_grab_basis ( dbl_QSdata * p),
00191   dbl_check_qsdata_pointer ( dbl_QSdata * p);
00192 
00193 
00194 dbl_QSLIB_INTERFACE int dbl_QSopt_primal (
00195   dbl_QSdata * p,
00196   int *status)
00197 {
00198   int rval = 0;
00199 
00200   if (status)
00201     *status = QS_LP_UNSOLVED;
00202 
00203   rval = dbl_check_qsdata_pointer (p);
00204   CHECKRVALG (rval, CLEANUP);
00205 
00206   /* If both the basis and the cache exist, then skip the optimization */
00207 
00208   if (!p->basis || !p->cache)
00209   {
00210     rval = dbl_opt_work (p, status, 0);
00211     CHECKRVALG (rval, CLEANUP);
00212   }
00213   else
00214   {
00215     if (status)
00216       *status = p->cache->status;
00217   }
00218 
00219 CLEANUP:
00220 
00221   EG_RETURN (rval);
00222 }
00223 
00224 dbl_QSLIB_INTERFACE int dbl_QSopt_dual (
00225   dbl_QSdata * p,
00226   int *status)
00227 {
00228   int rval = 0;
00229 
00230   if (status)
00231     *status = QS_LP_UNSOLVED;
00232 
00233   rval = dbl_check_qsdata_pointer (p);
00234   CHECKRVALG (rval, CLEANUP);
00235 
00236   if (!p->basis || !p->cache || !p->factorok)
00237   {
00238     rval = dbl_opt_work (p, status, 1);
00239     CHECKRVALG (rval, CLEANUP);
00240   }
00241   else
00242   {
00243     if (status)
00244       *status = p->cache->status;
00245   }
00246 
00247 CLEANUP:
00248 
00249   if (rval == QS_LP_CHANGE_PREC)
00250   {
00251     MESSAGE (__QS_SB_VERB, "Changing dbl_precision");
00252     return rval;
00253   }
00254   EG_RETURN (rval);
00255 }
00256 
00257 static int dbl_opt_work (
00258   dbl_QSdata * p,
00259   int *status,
00260   int primal_or_dual)
00261 {
00262   int rval = 0;
00263   int rstatus = QS_LP_UNSOLVED;
00264   dbl_QSdata *p2 = 0;
00265 
00266   if (p->basis)
00267   {
00268     if (p->basis->nstruct != p->qslp->nstruct ||
00269         p->basis->nrows != p->qslp->nrows)
00270     {
00271       fprintf (stderr, "Size of basis does not match LP\n");
00272       rval = 1;
00273       goto CLEANUP;
00274     }
00275   }
00276 
00277   if (!p->basis && p->lp->basisid == -1 && p->simplex_scaling == 1)
00278   {
00279     /* Try scaling by copying the LP and solving */
00280 
00281     dbl_ILLprice_free_pricing_info (p->pricing);  /* Just to be sure  */
00282     p->factorok = 0;            /* that p is clean. */
00283 
00284     p2 = dbl_QScopy_prob (p, "scaled_lp");
00285     if (p2 == 0)
00286       goto CLEANUP;
00287 
00288     rval = dbl_ILLlp_scale (p2->qslp);
00289     CHECKRVALG (rval, CLEANUP);
00290 
00291     if (primal_or_dual == 0)
00292     {
00293       rval = dbl_ILLlib_optimize (p2->lp, p2->basis, p2->pricing,
00294                               PRIMAL_SIMPLEX, 0, p2->simplex_display, 
00295                               &(p->itcnt));
00296     }
00297     else
00298     {
00299       rval = dbl_ILLlib_optimize (p2->lp, p2->basis, p2->pricing,
00300                               DUAL_SIMPLEX, 0, p2->simplex_display,
00301                               &(p->itcnt));
00302     }
00303     CHECKRVALG (rval, CLEANUP);
00304 
00305     rval = dbl_grab_basis (p2);
00306     CHECKRVALG (rval, CLEANUP);
00307 
00308     if (p->basis)
00309     {
00310       dbl_ILLlp_basis_free (p->basis);
00311       ILL_IFFREE (p->basis, dbl_ILLlp_basis);
00312     }
00313     p->basis = p2->basis;
00314     p2->basis = 0;
00315     dbl_QSfree_prob (p2);
00316     p2 = 0;
00317   }
00318 
00319   if (primal_or_dual == 0)
00320   {
00321     if (p->factorok == 0)
00322     {
00323       if (p->basis == 0)
00324         p->lp->basisid = -1;
00325       rval = dbl_ILLlib_optimize (p->lp, p->basis, p->pricing, PRIMAL_SIMPLEX,
00326                               &rstatus, p->simplex_display, &(p->itcnt));
00327     }
00328     else
00329     {
00330       dbl_ILLprice_free_pricing_info (p->pricing);
00331       if (p->lp->basisid != -1)
00332         p->lp->fbasisid = p->lp->basisid;
00333       rval = dbl_ILLlib_optimize (p->lp, 0, p->pricing,
00334                               PRIMAL_SIMPLEX, &rstatus, p->simplex_display, 
00335                               &(p->itcnt));
00336     }
00337   }
00338   else
00339   {
00340     if (p->factorok == 0)
00341     {
00342       if (p->basis == 0)
00343         p->lp->basisid = -1;
00344       rval = dbl_ILLlib_optimize (p->lp, p->basis, p->pricing, DUAL_SIMPLEX,
00345                               &rstatus, p->simplex_display, &(p->itcnt));
00346     }
00347     else
00348     {
00349       /* The factorization and rownorms should be up-to-date */
00350       if (p->lp->basisid != -1)
00351       {
00352         p->lp->fbasisid = p->lp->basisid;
00353       }
00354       else
00355       {
00356         dbl_ILLprice_free_pricing_info (p->pricing);
00357       }
00358       rval = dbl_ILLlib_optimize (p->lp, 0, p->pricing,
00359                               DUAL_SIMPLEX, &rstatus, p->simplex_display, 
00360                               &(p->itcnt));
00361     }
00362   }
00363   CHECKRVALG (rval, CLEANUP);
00364 
00365   rval = dbl_grab_basis (p);
00366   CHECKRVALG (rval, CLEANUP);
00367 
00368   if (rstatus == QS_LP_OPTIMAL)
00369   {
00370     rval = dbl_grab_cache (p, rstatus);
00371     CHECKRVALG (rval, CLEANUP);
00372   }
00373   else
00374   {
00375     dbl_free_cache (p);
00376   }
00377 
00378   p->factorok = 1;
00379 
00380 #if 0
00381   p->lp->basisid = -1;          /* This will cause the basis to be reloaded at the */
00382   /* next optimization - it could be moved into the  */
00383   /* add/del routines if we want to cache the        */
00384   /* factored basis.                                 */
00385   -switched to having qs_simplex load a basis whenever it is passed;
00386   the trouble with keeping basisid == -1 is that the QS - level routines
00387     will not know if the
00388     current lp has been optimized (so, for example,
00389                                    getbasis will not work)
00390     .
00391 #endif
00392   CLEANUP:p->qstatus = rstatus;
00393 
00394   if (status)
00395     *status = rstatus;
00396 
00397   if (p2)
00398     dbl_QSfree_prob (p2);
00399   if (rval == QS_LP_CHANGE_PREC)
00400   {
00401     MESSAGE (__QS_SB_VERB, "Changing dbl_precision");
00402     return rval;
00403   }
00404   MESSAGE (rval ? 0 : 1000, "Error code %d", rval);
00405   EG_RETURN (rval);
00406 }
00407 
00408 dbl_QSLIB_INTERFACE int dbl_QSopt_pivotin_row (
00409   dbl_QSdata * p,
00410   int rcnt,
00411   int *rlist)
00412 {
00413   int basismod = 0;
00414   int rval = 0;
00415 
00416   rval = dbl_check_qsdata_pointer (p);
00417   CHECKRVALG (rval, CLEANUP);
00418 
00419   if (p->pricing == 0)
00420   {
00421     ILL_ERROR (rval, "pricing info not available in dbl_QSopt_pivotin_row\n");
00422   }
00423 
00424   rval = dbl_ILLsimplex_pivotin (p->lp, p->pricing, rcnt, rlist,
00425                              SIMPLEX_PIVOTINROW, &basismod);
00426   CHECKRVALG (rval, CLEANUP);
00427 
00428   rval = dbl_grab_basis (p);
00429   CHECKRVALG (rval, CLEANUP);
00430 
00431 CLEANUP:
00432 
00433   EG_RETURN (rval);
00434 }
00435 
00436 dbl_QSLIB_INTERFACE int dbl_QSopt_pivotin_col (
00437   dbl_QSdata * p,
00438   int ccnt,
00439   int *clist)
00440 {
00441   int basismod = 0;
00442   int rval = 0;
00443 
00444   rval = dbl_check_qsdata_pointer (p);
00445   CHECKRVALG (rval, CLEANUP);
00446 
00447   if (p->pricing == 0)
00448   {
00449     ILL_ERROR (rval, "pricing info not available in QSopt_pivotin\n");
00450   }
00451 
00452   rval = dbl_ILLsimplex_pivotin (p->lp, p->pricing, ccnt, clist,
00453                              SIMPLEX_PIVOTINCOL, &basismod);
00454   CHECKRVALG (rval, CLEANUP);
00455 
00456   rval = dbl_grab_basis (p);
00457   CHECKRVALG (rval, CLEANUP);
00458 
00459 CLEANUP:
00460 
00461   EG_RETURN (rval);
00462 }
00463 
00464 
00465 dbl_QSLIB_INTERFACE int dbl_QSopt_strongbranch (
00466   dbl_QSdata * p,
00467   int ncand,
00468   int *candidatelist,
00469   double * xlist,
00470   double * down_vals,
00471   double * up_vals,
00472   int iterations,
00473   double objbound)
00474 {
00475   int rval = 0;
00476 
00477   rval = dbl_check_qsdata_pointer (p);
00478   CHECKRVALG (rval, CLEANUP);
00479 
00480   if (p->pricing == 0)
00481   {
00482     rval = 1;
00483     CHECKRVALG (rval, CLEANUP);
00484   }
00485 
00486   rval = dbl_ILLlib_strongbranch (p->lp, p->pricing, candidatelist, ncand,
00487                               xlist, down_vals, up_vals, iterations, objbound,
00488                               &(p->itcnt));
00489   CHECKRVALG (rval, CLEANUP);
00490 
00491   p->factorok = 0;
00492   dbl_free_cache (p);
00493   p->qstatus = QS_LP_UNSOLVED;  /* Was set to MODIFIED in dbl_free_cache () */
00494 
00495 CLEANUP:
00496 
00497   EG_RETURN (rval);
00498 }
00499 
00500 dbl_QSLIB_INTERFACE dbl_QSdata *dbl_QScreate_prob (
00501   const char *name,
00502   int objsense)
00503 {
00504   int rval = 0;
00505   dbl_QSdata *p = 0;
00506   int len;
00507 
00508   ILL_SAFE_MALLOC (p, 1, dbl_QSdata);
00509   if (!p)
00510   {
00511     fprintf (stderr, "out of memory in dbl_QScreate_prob\n");
00512     rval = 1;
00513     goto CLEANUP;
00514   }
00515 
00516   p->qslp = 0;
00517   p->lp = 0;
00518   p->pricing = 0;
00519   p->basis = 0;
00520   p->cache = 0;
00521   p->qstatus = QS_LP_UNSOLVED;
00522   p->factorok = 0;
00523 
00524   p->itcnt.pI_iter = 0;
00525   p->itcnt.pII_iter = 0;
00526   p->itcnt.dI_iter = 0;
00527   p->itcnt.dII_iter = 0;
00528   p->itcnt.tot_iter = 0;
00529   dbl_EGlpNumInitVar(p->uobjlim);
00530   dbl_EGlpNumInitVar(p->lobjlim);
00531   dbl_EGlpNumCopy(p->uobjlim, dbl_ILL_MAXDOUBLE);
00532   dbl_EGlpNumCopy(p->lobjlim, dbl_ILL_MINDOUBLE);
00533 
00534   p->simplex_display = 0;
00535   p->simplex_scaling = 1;
00536 
00537   ILL_SAFE_MALLOC (p->qslp, 1, dbl_ILLlpdata);
00538   if (!p->qslp)
00539   {
00540     fprintf (stderr, "out of memory in dbl_QScreate_prob\n");
00541     rval = 1;
00542     goto CLEANUP;
00543   }
00544   dbl_ILLlpdata_init (p->qslp);
00545 
00546   ILL_SAFE_MALLOC (p->lp, 1, dbl_lpinfo);
00547   if (!p->lp)
00548   {
00549     fprintf (stderr, "out of memory in dbl_QScreate_prob\n");
00550     rval = 1;
00551     goto CLEANUP;
00552   }
00553   dbl_EGlpNumInitVar (p->lp->objval);
00554   dbl_EGlpNumInitVar (p->lp->pobjval);
00555   dbl_EGlpNumInitVar (p->lp->dobjval);
00556   dbl_EGlpNumInitVar (p->lp->pinfeas);
00557   dbl_EGlpNumInitVar (p->lp->dinfeas);
00558   dbl_EGlpNumInitVar (p->lp->objbound);
00559   dbl_EGlpNumInitVar (p->lp->upd.piv);
00560   dbl_EGlpNumInitVar (p->lp->upd.dty);
00561   dbl_EGlpNumInitVar (p->lp->upd.c_obj);
00562   dbl_EGlpNumInitVar (p->lp->upd.tz);
00563   dbl_ILLsimplex_init_lpinfo (p->lp);
00564   dbl_ILLsimplex_load_lpinfo (p->qslp, p->lp);
00565 
00566   ILL_SAFE_MALLOC (p->pricing, 1, dbl_price_info);
00567   if (!p->pricing)
00568   {
00569     fprintf (stderr, "out of memory in dbl_QScreate_prob\n");
00570     rval = 1;
00571     goto CLEANUP;
00572   }
00573   dbl_EGlpNumInitVar (p->pricing->htrigger);
00574   dbl_ILLprice_init_pricing_info (p->pricing);
00575   p->pricing->pI_price = QS_DEFAULT_PRICE_PI;
00576   p->pricing->pII_price = QS_DEFAULT_PRICE_PII;
00577   p->pricing->dI_price = QS_DEFAULT_PRICE_DI;
00578   p->pricing->dII_price = QS_DEFAULT_PRICE_DII;
00579 
00580   if (name)
00581   {
00582     len = strlen (name) + 1;
00583     ILL_SAFE_MALLOC (p->name, len, char);
00584 
00585     strcpy (p->name, name);
00586   }
00587   else
00588   {
00589     ILL_SAFE_MALLOC (p->name, 7, char);
00590 
00591     sprintf (p->name, "noname");
00592   }
00593 
00594   len = strlen (p->name) + 1;
00595   ILL_SAFE_MALLOC (p->qslp->probname, len, char);
00596 
00597   strcpy (p->qslp->probname, p->name);
00598 
00599   if (objsense == QS_MAX)
00600   {
00601     p->qslp->objsense = QS_MAX;
00602   }
00603 
00604 CLEANUP:
00605 
00606   if (rval)
00607   {
00608     dbl_QSfree_prob (p);
00609     p = 0;
00610   }
00611 
00612   return p;
00613 }
00614 
00615 dbl_QSLIB_INTERFACE dbl_QSdata *dbl_QSread_prob (
00616   const char *filename,
00617   const char *filetype)
00618 {
00619   dbl_QSdata *p = 0;
00620   EGioFile_t *file = 0;
00621   dbl_QSline_reader reader;
00622 
00623   if ((file = EGioOpen (filename, "r")) == 0)
00624   {
00625     perror (filename);
00626     fprintf (stderr, "Unable to open \"%s\" for input.\n", filename);
00627   }
00628   if (file == NULL)
00629     goto CLEANUP;
00630 
00631   reader = dbl_ILLline_reader_new ((dbl_qsread_line_fct) EGioGets, file);
00632   p = dbl_QSget_prob (reader, filename, filetype);
00633   dbl_QSline_reader_free (reader);  /* Bico - 040723 */
00634 
00635 CLEANUP:
00636   if (file != NULL)
00637   {
00638     EGioClose (file);
00639   }
00640   return p;
00641 }
00642 
00643 dbl_QSLIB_INTERFACE dbl_QSdata *dbl_QSload_prob (
00644   const char *probname,
00645   int ncols,
00646   int nrows,
00647   int *cmatcnt,
00648   int *cmatbeg,
00649   int *cmatind,
00650   double * cmatval,
00651   int objsense,
00652   double * obj,
00653   double * rhs,
00654   char *sense,
00655   double * lower,
00656   double * upper,
00657   const char **colnames,
00658   const char **rownames)
00659 {
00660   int rval = 0;
00661   dbl_QSdata *p = 0;
00662 
00663   p = dbl_QScreate_prob (probname, objsense);
00664   if (p == 0)
00665     goto CLEANUP;
00666 
00667   rval = dbl_ILLlib_newrows (p->lp, 0, nrows, rhs, sense, 0, rownames);
00668   CHECKRVALG (rval, CLEANUP);
00669 
00670   rval = dbl_ILLlib_addcols (p->lp, 0, ncols, cmatcnt, cmatbeg, cmatind,
00671                          cmatval, obj, lower, upper, colnames, 0);
00672   CHECKRVALG (rval, CLEANUP);
00673 
00674   p->factorok = 0;
00675 
00676 CLEANUP:
00677 
00678   if (rval)
00679   {
00680     dbl_QSfree_prob (p);
00681     p = 0;
00682   }
00683 
00684   return p;
00685 }
00686 
00687 dbl_QSLIB_INTERFACE dbl_QSdata *dbl_QScopy_prob (
00688   dbl_QSdata * p,
00689   const char *newname)
00690 {
00691   int rval = 0;
00692   int j, col, beg, pindex, hit;
00693   dbl_QSdata *p2 = 0;
00694   char *coln;
00695   char buf[ILL_namebufsize];
00696 
00697   /* printf ("dbl_QScopy_prob ...\n"); fflush (stdout); */
00698 
00699   rval = dbl_check_qsdata_pointer (p);
00700   CHECKRVALG (rval, CLEANUP);
00701 
00702   p2 = dbl_QScreate_prob (newname, p->qslp->objsense);
00703   if (p2 == 0)
00704     goto CLEANUP;
00705 
00706   rval = dbl_ILLlib_newrows (p2->lp, 0, p->qslp->nrows,
00707                          p->qslp->rhs, p->qslp->sense, p->qslp->rangeval,
00708                          (const char **) p->qslp->rownames);
00709   CHECKRVALG (rval, CLEANUP);
00710 
00711   for (j = 0; j < p->qslp->nstruct; j++)
00712   {
00713     col = p->qslp->structmap[j];
00714     if (p->qslp->colnames)
00715       coln = p->qslp->colnames[j];
00716     else
00717       coln = 0;
00718     beg = p->qslp->A.matbeg[col];
00719 
00720     /* Monika: Note that Java will need to handle these arrays */
00721     /*         without using the beg offset.  The easiest way  */
00722     /*         may be to copy the arrays, as in the getcols()  */
00723     /*         code in dbl_lib.c.                                  */
00724 
00725     rval = dbl_ILLlib_addcol (p2->lp, 0,
00726                           p->qslp->A.matcnt[col],
00727                           p->qslp->A.matind + beg, p->qslp->A.matval + beg,
00728                           p->qslp->obj[col], p->qslp->lower[col],
00729                           p->qslp->upper[col], coln, 0);
00730     CHECKRVALG (rval, CLEANUP);
00731   }
00732 
00733   p2->qslp->objsense = p->qslp->objsense;
00734 
00735   p2->factorok = 0;
00736   p2->simplex_display = p->simplex_display;
00737   p2->simplex_scaling = p->simplex_scaling;
00738   dbl_EGlpNumClearVar (p2->pricing->htrigger);
00739   *(p2->pricing) = *(p->pricing);
00740   /* I added this line because copying the dbl_heap (as a pointer) doesn't make any
00741    * sense ! */
00742   dbl_ILLheap_init (&(p2->pricing->h));
00743   dbl_EGlpNumInitVar (p2->pricing->htrigger);
00744   dbl_EGlpNumCopy (p2->pricing->htrigger, p->pricing->htrigger);
00745 
00746   if (p->qslp->intmarker != 0)
00747   {
00748     ILL_SAFE_MALLOC (p2->qslp->intmarker, p->qslp->nstruct, char);
00749 
00750     for (j = 0; j < p->qslp->nstruct; j++)
00751     {
00752       p2->qslp->intmarker[j] = p->qslp->intmarker[j];
00753     }
00754   }
00755 
00756   if (p->qslp->objname != 0)
00757   {
00758     dbl_ILL_UTIL_STR (p2->qslp->objname, p->qslp->objname);
00759   }
00760   else
00761   {
00762     strcpy (buf, "obj");
00763     rval = ILLsymboltab_uname (&p2->qslp->rowtab, buf, "", NULL);
00764     CHECKRVALG (rval, CLEANUP);
00765     dbl_ILL_UTIL_STR (p2->qslp->objname, buf);
00766   }
00767   rval = ILLsymboltab_register (&p2->qslp->rowtab, p2->qslp->objname,
00768                                 -1, &pindex, &hit);
00769   rval = rval || hit;
00770   CHECKRVALG (rval, CLEANUP);
00771 
00772   ILLstring_reporter_copy (&p2->qslp->reporter, &p->qslp->reporter);
00773 
00774 CLEANUP:
00775 
00776   if (rval)
00777   {
00778     dbl_QSfree_prob (p2);
00779     p2 = 0;
00780   }
00781 
00782   return p2;
00783 }
00784 
00785 dbl_QSLIB_INTERFACE int dbl_QSchange_objsense (
00786   dbl_QSdata * p,
00787   int newsense)
00788 {
00789   int rval = 0;
00790 
00791   rval = dbl_check_qsdata_pointer (p);
00792   CHECKRVALG (rval, CLEANUP);
00793 
00794   if (newsense != QS_MIN && newsense != QS_MAX)
00795   {
00796     fprintf (stderr, "Illegal objective sense %d\n", newsense);
00797     rval = 1;
00798     goto CLEANUP;
00799   }
00800 
00801   if (p->qslp->objsense != newsense)
00802   {
00803     if(newsense == QS_MAX) dbl_ILLsimplex_set_bound(p->lp,(const double *)(&(p->lobjlim)), newsense);
00804     else dbl_ILLsimplex_set_bound(p->lp,(const double*)(&(p->uobjlim)), newsense);
00805     p->qslp->objsense = newsense;
00806     dbl_free_cache (p);
00807   }
00808 
00809 CLEANUP:
00810 
00811   EG_RETURN (rval);
00812 }
00813 
00814 dbl_QSLIB_INTERFACE int
00815 dbl_QSget_itcnt(
00816   dbl_QSdata* p,
00817   int *pI_iter,
00818   int *pII_iter,
00819   int *dI_iter, 
00820   int *dII_iter,
00821   int *tot_iter)
00822 {
00823   int rval = 0;
00824   rval = dbl_check_qsdata_pointer (p);
00825   CHECKRVALG (rval, CLEANUP);
00826   if(pI_iter) *pI_iter = p->itcnt.pI_iter;
00827   if(pII_iter) *pII_iter = p->itcnt.pII_iter;
00828   if(dI_iter) *dI_iter = p->itcnt.dI_iter;
00829   if(dII_iter) *dII_iter = p->itcnt.dII_iter;
00830   if(tot_iter) *tot_iter = p->itcnt.tot_iter;
00831 
00832 CLEANUP:
00833 
00834   EG_RETURN(rval);
00835 }
00836 
00837 dbl_QSLIB_INTERFACE int dbl_QSget_objsense (
00838   dbl_QSdata * p,
00839   int *objsense)
00840 {
00841   int rval = 0;
00842 
00843   rval = dbl_check_qsdata_pointer (p);
00844   CHECKRVALG (rval, CLEANUP);
00845 
00846   if (objsense)
00847     *objsense = p->qslp->objsense;
00848 
00849 CLEANUP:
00850 
00851   EG_RETURN (rval);
00852 }
00853 
00854 
00855 dbl_QSLIB_INTERFACE int dbl_QSnew_col (
00856   dbl_QSdata * p,
00857   const double obj,
00858   const double lower,
00859   const double upper,
00860   const char *name)
00861 {
00862   int rval = 0;
00863 
00864   rval = dbl_check_qsdata_pointer (p);
00865   CHECKRVALG (rval, CLEANUP);
00866 
00867   rval = dbl_ILLlib_newcol (p->lp, p->basis, obj, lower, upper, name, p->factorok);
00868   CHECKRVALG (rval, CLEANUP);
00869 
00870   dbl_free_cache (p);
00871 
00872 CLEANUP:
00873 
00874   EG_RETURN (rval);
00875 }
00876 
00877 dbl_QSLIB_INTERFACE int dbl_QSadd_cols (
00878   dbl_QSdata * p,
00879   int num,
00880   int *cmatcnt,
00881   int *cmatbeg,
00882   int *cmatind,
00883   double * cmatval,
00884   double * obj,
00885   double * lower,
00886   double * upper,
00887   const char **names)
00888 {
00889   int rval = 0;
00890 
00891   rval = dbl_check_qsdata_pointer (p);
00892   CHECKRVALG (rval, CLEANUP);
00893 
00894   rval = dbl_ILLlib_addcols (p->lp, p->basis, num, cmatcnt, cmatbeg,
00895                          cmatind, cmatval, obj, lower, upper, names,
00896                          p->factorok);
00897   CHECKRVALG (rval, CLEANUP);
00898 
00899   dbl_free_cache (p);
00900 
00901 CLEANUP:
00902 
00903   EG_RETURN (rval);
00904 }
00905 
00906 dbl_QSLIB_INTERFACE int dbl_QSadd_col (
00907   dbl_QSdata * p,
00908   int cnt,
00909   int *cmatind,
00910   double * cmatval,
00911   double obj,
00912   double lower,
00913   double upper,
00914   const char *name)
00915 {
00916   int rval = 0;
00917 
00918   rval = dbl_check_qsdata_pointer (p);
00919   CHECKRVALG (rval, CLEANUP);
00920 
00921   rval = dbl_ILLlib_addcol (p->lp, p->basis, cnt, cmatind, cmatval,
00922                         obj, lower, upper, name, p->factorok);
00923   CHECKRVALG (rval, CLEANUP);
00924 
00925   dbl_free_cache (p);
00926 
00927 CLEANUP:
00928 
00929   EG_RETURN (rval);
00930 }
00931 
00932 dbl_QSLIB_INTERFACE int dbl_QSnew_row (
00933   dbl_QSdata * p,
00934   const double rhs,
00935   int sense,
00936   const char *name)
00937 {
00938   int rval = 0;
00939 
00940   rval = dbl_check_qsdata_pointer (p);
00941   CHECKRVALG (rval, CLEANUP);
00942 
00943   rval = dbl_ILLlib_newrow (p->lp, p->basis, rhs, sense, dbl_zeroLpNum, name);
00944   CHECKRVALG (rval, CLEANUP);
00945 
00946   p->factorok = 0;
00947   dbl_free_cache (p);
00948 
00949 CLEANUP:
00950 
00951   EG_RETURN (rval);
00952 }
00953 
00954 dbl_QSLIB_INTERFACE int dbl_QSadd_ranged_rows (
00955   dbl_QSdata * p,
00956   int num,
00957   int *rmatcnt,
00958   int *rmatbeg,
00959   int *rmatind,
00960   const double * rmatval,
00961   const double * rhs,
00962   char *sense,
00963   const double * range,
00964   const char **names)
00965 {
00966   int rval = 0;
00967 
00968   rval = dbl_check_qsdata_pointer (p);
00969   CHECKRVALG (rval, CLEANUP);
00970 
00971   rval = dbl_ILLlib_addrows (p->lp, p->basis, num, rmatcnt, rmatbeg,
00972                          rmatind, rmatval, rhs, sense, range,
00973                          names, &(p->factorok));
00974   CHECKRVALG (rval, CLEANUP);
00975 
00976   if (p->factorok == 1 && p->basis->rownorms)
00977   {
00978     rval = dbl_ILLlib_loadrownorms (p->lp, p->pricing, p->basis->rownorms);
00979     CHECKRVALG (rval, CLEANUP);
00980     /* This really should go inside of dbl_ILLlib_addrows, once pinf is  */
00981     /* is moved into the lp struct.                                  */
00982   }
00983 
00984   dbl_free_cache (p);
00985 
00986 CLEANUP:
00987 
00988   EG_RETURN (rval);
00989 }
00990 
00991 dbl_QSLIB_INTERFACE int dbl_QSadd_ranged_row (
00992   dbl_QSdata * p,
00993   int cnt,
00994   int *rmatind,
00995   const double * rmatval,
00996   const double * rhs,
00997   int sense,
00998   const double * range,
00999   const char *name)
01000 {
01001   int rval = 0;
01002   int vmatcnt[1];
01003   int vmatbeg[1];
01004   char vsense[1];
01005   const char *vnames[1];
01006 
01007   rval = dbl_check_qsdata_pointer (p);
01008   CHECKRVALG (rval, CLEANUP);
01009 
01010   vmatcnt[0] = cnt;
01011   vmatbeg[0] = 0;
01012   vsense[0] = sense;
01013   vnames[0] = name;
01014 
01015   rval = dbl_QSadd_ranged_rows (p, 1, vmatcnt, vmatbeg, rmatind, rmatval, rhs,
01016                             vsense, range, vnames);
01017   CHECKRVALG (rval, CLEANUP);
01018 
01019 CLEANUP:
01020 
01021   EG_RETURN (rval);
01022 }
01023 
01024 dbl_QSLIB_INTERFACE int dbl_QSadd_rows (
01025   dbl_QSdata * p,
01026   int num,
01027   int *rmatcnt,
01028   int *rmatbeg,
01029   int *rmatind,
01030   const double * rmatval,
01031   const double * rhs,
01032   char *sense,
01033   const char **names)
01034 {
01035   int rval = 0;
01036 
01037   rval = dbl_check_qsdata_pointer (p);
01038   CHECKRVALG (rval, CLEANUP);
01039 
01040   rval = dbl_ILLlib_addrows (p->lp, p->basis, num, rmatcnt, rmatbeg,
01041                          rmatind, rmatval, rhs, sense, 0, names,
01042                          &(p->factorok));
01043   CHECKRVALG (rval, CLEANUP);
01044 
01045   if (p->factorok == 1 && p->basis->rownorms)
01046   {
01047     rval = dbl_ILLlib_loadrownorms (p->lp, p->pricing, p->basis->rownorms);
01048     CHECKRVALG (rval, CLEANUP);
01049     /* This really should go inside of dbl_ILLlib_addrows, once pinf is  */
01050     /* is moved into the lp struct.                                  */
01051   }
01052 
01053   dbl_free_cache (p);
01054 
01055 CLEANUP:
01056 
01057   EG_RETURN (rval);
01058 }
01059 
01060 dbl_QSLIB_INTERFACE int dbl_QSadd_row (
01061   dbl_QSdata * p,
01062   int cnt,
01063   int *rmatind,
01064   const double * rmatval,
01065   const double * rhs,
01066   int sense,
01067   const char *name)
01068 {
01069   int rval = 0;
01070   int vmatcnt[1];
01071   int vmatbeg[1];
01072   char vsense[1];
01073   const char *vnames[1];
01074 
01075   rval = dbl_check_qsdata_pointer (p);
01076   CHECKRVALG (rval, CLEANUP);
01077 
01078   vmatcnt[0] = cnt;
01079   vmatbeg[0] = 0;
01080   vsense[0] = sense;
01081   vnames[0] = name;
01082 
01083   rval = dbl_QSadd_rows (p, 1, vmatcnt, vmatbeg, rmatind, rmatval, rhs, vsense,
01084                      vnames);
01085   CHECKRVALG (rval, CLEANUP);
01086 
01087 CLEANUP:
01088 
01089   EG_RETURN (rval);
01090 }
01091 
01092 dbl_QSLIB_INTERFACE int dbl_QSdelete_rows (
01093   dbl_QSdata * p,
01094   int num,
01095   int *dellist)
01096 {
01097   int rval = 0;
01098   int basis_ok = 0;
01099   int cache_ok = 0;
01100 
01101   rval = dbl_check_qsdata_pointer (p);
01102   CHECKRVALG (rval, CLEANUP);
01103 
01104   rval = dbl_ILLlib_delrows (p->lp, p->basis, p->cache, num, dellist, &basis_ok,
01105                          &cache_ok);
01106   CHECKRVALG (rval, CLEANUP);
01107 
01108   /* For now, just remove the basis - wait for pivotin */
01109 
01110   if (p->basis && !basis_ok)
01111   {
01112     dbl_ILLlp_basis_free (p->basis);
01113     ILL_IFFREE (p->basis, dbl_ILLlp_basis);
01114   }
01115 
01116   p->factorok = 0;
01117 
01118   if (!p->basis || !basis_ok || !cache_ok)
01119   {
01120     /* Note: If we only delete basic rows then cached soln is valid */
01121     dbl_free_cache (p);
01122   }
01123 
01124 CLEANUP:
01125 
01126   EG_RETURN (rval);
01127 }
01128 
01129 dbl_QSLIB_INTERFACE int dbl_QSdelete_row (
01130   dbl_QSdata * p,
01131   int rowindex)
01132 {
01133   int rval = 0;
01134   int vdellist[1];
01135 
01136   rval = dbl_check_qsdata_pointer (p);
01137   CHECKRVALG (rval, CLEANUP);
01138 
01139   vdellist[0] = rowindex;
01140 
01141   rval = dbl_QSdelete_rows (p, 1, vdellist);
01142   CHECKRVALG (rval, CLEANUP);
01143 
01144 CLEANUP:
01145 
01146   EG_RETURN (rval);
01147 }
01148 
01149 dbl_QSLIB_INTERFACE int dbl_QSdelete_setrows (
01150   dbl_QSdata * p,
01151   int *flags)
01152 {
01153   int rval = 0;
01154   int j, num = 0;
01155   int *dellist = 0;
01156   int nrows;
01157 
01158   rval = dbl_check_qsdata_pointer (p);
01159   CHECKRVALG (rval, CLEANUP);
01160 
01161   nrows = p->qslp->nrows;
01162 
01163   for (j = 0; j < nrows; j++)
01164   {
01165     if (flags[j] == 1)
01166       num++;
01167   }
01168 
01169   if (num > 0)
01170   {
01171     ILL_SAFE_MALLOC (dellist, num, int);
01172 
01173     for (j = 0, num = 0; j < nrows; j++)
01174     {
01175       if (flags[j] == 1)
01176       {
01177         dellist[num++] = j;
01178       }
01179     }
01180 
01181     rval = dbl_QSdelete_rows (p, num, dellist);
01182     CHECKRVALG (rval, CLEANUP);
01183   }
01184 
01185 CLEANUP:
01186 
01187   ILL_IFFREE (dellist, int);
01188 
01189   EG_RETURN (rval);
01190 }
01191 
01192 dbl_QSLIB_INTERFACE int dbl_QSdelete_named_row (
01193   dbl_QSdata * p,
01194   const char *rowname)
01195 {
01196   int rval = 0;
01197   int i, vdellist[1];
01198 
01199   rval = dbl_check_qsdata_pointer (p);
01200   CHECKRVALG (rval, CLEANUP);
01201 
01202   rval = dbl_QSget_row_index (p, rowname, &i);
01203   CHECKRVALG (rval, CLEANUP);
01204 
01205   vdellist[0] = i;
01206 
01207   rval = dbl_QSdelete_rows (p, 1, vdellist);
01208   CHECKRVALG (rval, CLEANUP);
01209 
01210 CLEANUP:
01211 
01212   EG_RETURN (rval);
01213 }
01214 
01215 dbl_QSLIB_INTERFACE int dbl_QSdelete_named_rows_list (
01216   dbl_QSdata * p,
01217   int num,
01218   const char **rownames)
01219 {
01220   int rval = 0;
01221   int i, k;
01222   int *vdellist = 0;
01223 
01224   rval = dbl_check_qsdata_pointer (p);
01225   CHECKRVALG (rval, CLEANUP);
01226 
01227   if (num > 0)
01228   {
01229     ILL_SAFE_MALLOC (vdellist, num, int);
01230 
01231     for (k = 0; k < num; k++)
01232     {
01233       rval = dbl_QSget_row_index (p, rownames[k], &i);
01234       CHECKRVALG (rval, CLEANUP);
01235       vdellist[k] = i;
01236     }
01237 
01238     rval = dbl_QSdelete_rows (p, num, vdellist);
01239     CHECKRVALG (rval, CLEANUP);
01240   }
01241 
01242 CLEANUP:
01243 
01244   ILL_IFFREE (vdellist, int);
01245 
01246   EG_RETURN (rval);
01247 }
01248 
01249 dbl_QSLIB_INTERFACE int dbl_QSdelete_cols (
01250   dbl_QSdata * p,
01251   int num,
01252   int *dellist)
01253 {
01254   int rval = 0;
01255   int basis_ok;
01256 
01257   rval = dbl_check_qsdata_pointer (p);
01258   CHECKRVALG (rval, CLEANUP);
01259 
01260   rval = dbl_ILLlib_delcols (p->lp, p->basis, num, dellist, &basis_ok);
01261   CHECKRVALG (rval, CLEANUP);
01262 
01263   /* For now, just remove the basis - wait for pivotout */
01264 
01265   if (p->basis && !basis_ok)
01266   {
01267     dbl_ILLlp_basis_free (p->basis);
01268     ILL_IFFREE (p->basis, dbl_ILLlp_basis);
01269   }
01270 
01271   p->factorok = 0;
01272   dbl_free_cache (p);
01273 
01274 CLEANUP:
01275 
01276   EG_RETURN (rval);
01277 }
01278 
01279 dbl_QSLIB_INTERFACE int dbl_QSdelete_col (
01280   dbl_QSdata * p,
01281   int colindex)
01282 {
01283   int rval = 0;
01284   int vdellist[1];
01285 
01286   rval = dbl_check_qsdata_pointer (p);
01287   CHECKRVALG (rval, CLEANUP);
01288 
01289   vdellist[0] = colindex;
01290 
01291   rval = dbl_QSdelete_cols (p, 1, vdellist);
01292   CHECKRVALG (rval, CLEANUP);
01293 
01294 CLEANUP:
01295 
01296   EG_RETURN (rval);
01297 }
01298 
01299 dbl_QSLIB_INTERFACE int dbl_QSdelete_setcols (
01300   dbl_QSdata * p,
01301   int *flags)
01302 {
01303   int rval = 0;
01304   int j, num = 0;
01305   int *dellist = 0;
01306   int ncols;
01307 
01308   rval = dbl_check_qsdata_pointer (p);
01309   CHECKRVALG (rval, CLEANUP);
01310 
01311   ncols = p->qslp->nstruct;
01312 
01313   for (j = 0; j < ncols; j++)
01314   {
01315     if (flags[j] == 1)
01316       num++;
01317   }
01318 
01319   if (num > 0)
01320   {
01321     ILL_SAFE_MALLOC (dellist, num, int);
01322 
01323     for (j = 0, num = 0; j < ncols; j++)
01324     {
01325       if (flags[j] == 1)
01326       {
01327         dellist[num++] = j;
01328       }
01329     }
01330 
01331     rval = dbl_QSdelete_cols (p, num, dellist);
01332     CHECKRVALG (rval, CLEANUP);
01333   }
01334 
01335 CLEANUP:
01336 
01337   ILL_IFFREE (dellist, int);
01338 
01339   EG_RETURN (rval);
01340 }
01341 
01342 dbl_QSLIB_INTERFACE int dbl_QSdelete_named_column (
01343   dbl_QSdata * p,
01344   const char *colname)
01345 {
01346   int rval = 0;
01347   int j, vdellist[1];
01348 
01349   rval = dbl_check_qsdata_pointer (p);
01350   CHECKRVALG (rval, CLEANUP);
01351 
01352   rval = dbl_QSget_column_index (p, colname, &j);
01353   CHECKRVALG (rval, CLEANUP);
01354 
01355   vdellist[0] = j;
01356 
01357   rval = dbl_QSdelete_cols (p, 1, vdellist);
01358   CHECKRVALG (rval, CLEANUP);
01359 
01360 CLEANUP:
01361 
01362   EG_RETURN (rval);
01363 }
01364 
01365 dbl_QSLIB_INTERFACE int dbl_QSdelete_named_columns_list (
01366   dbl_QSdata * p,
01367   int num,
01368   const char **colnames)
01369 {
01370   int rval = 0;
01371   int i, j;
01372   int *vdellist = 0;
01373 
01374   rval = dbl_check_qsdata_pointer (p);
01375   CHECKRVALG (rval, CLEANUP);
01376 
01377   if (num > 0)
01378   {
01379     ILL_SAFE_MALLOC (vdellist, num, int);
01380 
01381     for (i = 0; i < num; i++)
01382     {
01383       rval = dbl_QSget_column_index (p, colnames[i], &j);
01384       CHECKRVALG (rval, CLEANUP);
01385       vdellist[i] = j;
01386     }
01387 
01388     rval = dbl_QSdelete_cols (p, num, vdellist);
01389     CHECKRVALG (rval, CLEANUP);
01390   }
01391 
01392 CLEANUP:
01393 
01394   ILL_IFFREE (vdellist, int);
01395 
01396   EG_RETURN (rval);
01397 }
01398 
01399 dbl_QSLIB_INTERFACE int dbl_QSchange_senses (
01400   dbl_QSdata * p,
01401   int num,
01402   int *rowlist,
01403   char *sense)
01404 {
01405   int rval = 0;
01406 
01407   rval = dbl_check_qsdata_pointer (p);
01408   CHECKRVALG (rval, CLEANUP);
01409 
01410   rval = dbl_ILLlib_chgsense (p->lp, num, rowlist, sense);
01411   CHECKRVALG (rval, CLEANUP);
01412 
01413   dbl_free_cache (p);
01414 
01415 CLEANUP:
01416 
01417   EG_RETURN (rval);
01418 }
01419 
01420 dbl_QSLIB_INTERFACE int dbl_QSchange_range (
01421   dbl_QSdata*p,
01422   int rowindex,
01423   double range)
01424 {
01425   int rval = 0; 
01426   rval = dbl_check_qsdata_pointer (p);
01427   CHECKRVALG(rval, CLEANUP);
01428   
01429   rval = dbl_ILLlib_chgrange (p->lp, rowindex, range);
01430   CHECKRVALG(rval, CLEANUP);
01431   
01432   p->factorok = 0; /* Sanjeeb -- 050911  */
01433   dbl_free_cache (p);
01434  
01435 CLEANUP:
01436 
01437   EG_RETURN(rval);
01438 
01439 }
01440 
01441 dbl_QSLIB_INTERFACE int dbl_QSchange_sense (
01442   dbl_QSdata * p,
01443   int rowindex,
01444   int sense)
01445 {
01446   int rval = 0;
01447   int vrowlist[1];
01448   char vsenselist[1];
01449 
01450   rval = dbl_check_qsdata_pointer (p);
01451   CHECKRVALG (rval, CLEANUP);
01452 
01453   vrowlist[0] = rowindex;
01454   vsenselist[0] = sense;
01455 
01456   rval = dbl_QSchange_senses (p, 1, vrowlist, vsenselist);
01457   CHECKRVALG (rval, CLEANUP);
01458 
01459 CLEANUP:
01460 
01461   EG_RETURN (rval);
01462 }
01463 
01464 dbl_QSLIB_INTERFACE  int dbl_QSget_coef (
01465   dbl_QSdata *p,
01466   int rowindex,
01467   int colindex,
01468   double* coef)
01469 {
01470   int rval = 0;
01471   rval = dbl_check_qsdata_pointer (p);
01472   CHECKRVALG (rval, CLEANUP);
01473   rval = dbl_ILLlib_getcoef (p->lp, rowindex, colindex, coef);
01474   CHECKRVALG (rval, CLEANUP);
01475   
01476 CLEANUP:
01477   EG_RETURN (rval);
01478 }
01479 
01480 dbl_QSLIB_INTERFACE int dbl_QSchange_coef (
01481   dbl_QSdata * p,
01482   int rowindex,
01483   int colindex,
01484   double coef)
01485 {
01486   int rval = 0;
01487 
01488   rval = dbl_check_qsdata_pointer (p);
01489   CHECKRVALG (rval, CLEANUP);
01490 
01491   rval = dbl_ILLlib_chgcoef (p->lp, rowindex, colindex, coef);
01492   CHECKRVALG (rval, CLEANUP);
01493 
01494   dbl_free_cache (p);
01495 
01496 CLEANUP:
01497 
01498   EG_RETURN (rval);
01499 }
01500 
01501 dbl_QSLIB_INTERFACE int dbl_QSchange_objcoef (
01502   dbl_QSdata * p,
01503   int indx,
01504   double coef)
01505 {
01506   int rval = 0;
01507 
01508   rval = dbl_check_qsdata_pointer (p);
01509   CHECKRVALG (rval, CLEANUP);
01510 
01511   rval = dbl_ILLlib_chgobj (p->lp, indx, coef);
01512   CHECKRVALG (rval, CLEANUP);
01513 
01514   dbl_free_cache (p);
01515 
01516 CLEANUP:
01517 
01518   EG_RETURN (rval);
01519 }
01520 
01521 dbl_QSLIB_INTERFACE int dbl_QSchange_rhscoef (
01522   dbl_QSdata * p,
01523   int indx,
01524   double coef)
01525 {
01526   int rval = 0;
01527 
01528   rval = dbl_check_qsdata_pointer (p);
01529   CHECKRVALG (rval, CLEANUP);
01530 
01531   rval = dbl_ILLlib_chgrhs (p->lp, indx, coef);
01532   CHECKRVALG (rval, CLEANUP);
01533 
01534   dbl_free_cache (p);
01535 
01536 CLEANUP:
01537 
01538   EG_RETURN (rval);
01539 }
01540 
01541 dbl_QSLIB_INTERFACE int dbl_QSchange_bounds (
01542   dbl_QSdata * p,
01543   int num,
01544   int *collist,
01545   char *lu,
01546   const double * bounds)
01547 {
01548   int rval = 0;
01549 
01550   rval = dbl_check_qsdata_pointer (p);
01551   CHECKRVALG (rval, CLEANUP);
01552 
01553   rval = dbl_ILLlib_chgbnds (p->lp, num, collist, lu, bounds);
01554   CHECKRVALG (rval, CLEANUP);
01555 
01556   dbl_free_cache (p);
01557 
01558 CLEANUP:
01559 
01560   EG_RETURN (rval);
01561 }
01562 
01563 dbl_QSLIB_INTERFACE int dbl_QSchange_bound (
01564   dbl_QSdata * p,
01565   int indx,
01566   int lu,
01567   const double bound)
01568 {
01569   int rval = 0;
01570 
01571   rval = dbl_check_qsdata_pointer (p);
01572   CHECKRVALG (rval, CLEANUP);
01573 
01574   rval = dbl_ILLlib_chgbnd (p->lp, indx, lu, bound);
01575   CHECKRVALG (rval, CLEANUP);
01576 
01577   dbl_free_cache (p);
01578 
01579 CLEANUP:
01580 
01581   EG_RETURN (rval);
01582 }
01583 
01584 #if 0
01585     /*
01586      * Bico - I removed this on 02.04.22.  I don't think we need to support
01587      * this type of interface (the loading via arrays can do the job)
01588      */
01589 dbl_QSLIB_INTERFACE QSbasis *QScreate_basis (
01590   int nstruct,
01591   int nrows)
01592 {
01593   int rval = 0;
01594   int i;
01595   QSbasis *B = 0;
01596 
01597   ILL_SAFE_MALLOC (B, 1, QSbasis);
01598 
01599   B->nstruct = nstruct;
01600   B->nrows = nrows;
01601   B->cstat = 0;
01602   B->rstat = 0;
01603 
01604   if (nstruct)
01605   {
01606     ILL_SAFE_MALLOC (B->cstat, nstruct, char);
01607   }
01608 
01609   if (nrows)
01610   {
01611     ILL_SAFE_MALLOC (B->rstat, nrows, char);
01612   }
01613 
01614   for (i = 0; i < nstruct; i++)
01615     B->cstat[i] = 0;
01616   for (i = 0; i < nrows; i++)
01617     B->rstat[i] = 0;
01618 
01619 CLEANUP:
01620 
01621   if (rval)
01622   {
01623     dbl_QSfree_basis (B);
01624     B = 0;
01625   }
01626 
01627   return B;
01628 }
01629 #endif
01630 
01631 dbl_QSLIB_INTERFACE QSbasis *dbl_QSread_basis (
01632   dbl_QSdata * p,
01633   const char *filename)
01634 {
01635   int rval = 0;
01636   QSbasis *qB = 0;
01637   dbl_ILLlp_basis B;
01638 
01639   dbl_ILLlp_basis_init (&B);
01640 
01641   rval = dbl_check_qsdata_pointer (p);
01642   CHECKRVALG (rval, CLEANUP);
01643 
01644   ILL_NEW (qB, QSbasis);
01645   dbl_init_basis (qB);
01646 
01647   rval = dbl_ILLlib_readbasis (p->lp, &B, filename);
01648   CHECKRVALG (rval, CLEANUP);
01649 
01650   rval = dbl_illbasis_to_qsbasis (&B, qB);
01651   CHECKRVALG (rval, CLEANUP);
01652 
01653 CLEANUP:
01654 
01655   if (rval && qB)
01656   {
01657     dbl_QSfree_basis (qB);
01658     qB = 0;
01659   }
01660   dbl_ILLlp_basis_free (&B);
01661 
01662   return qB;
01663 }
01664 
01665 dbl_QSLIB_INTERFACE int dbl_QSload_basis (
01666   dbl_QSdata * p,
01667   QSbasis * B)
01668 {
01669   int rval = 0;
01670 
01671   rval = dbl_check_qsdata_pointer (p);
01672   CHECKRVALG (rval, CLEANUP);
01673 
01674   if (B->nstruct != p->qslp->nstruct || B->nrows != p->qslp->nrows)
01675   {
01676     fprintf (stderr, "size of basis does not match lp\n");
01677     rval = 1;
01678     goto CLEANUP;
01679   }
01680 
01681   if (p->basis == 0)
01682   {
01683     ILL_SAFE_MALLOC (p->basis, 1, dbl_ILLlp_basis);
01684     dbl_ILLlp_basis_init (p->basis);
01685   }
01686   else
01687   {
01688     dbl_ILLlp_basis_free (p->basis);
01689   }
01690 
01691   rval = dbl_qsbasis_to_illbasis (B, p->basis);
01692   CHECKRVALG (rval, CLEANUP);
01693 
01694   p->factorok = 0;
01695 
01696 CLEANUP:
01697 
01698   EG_RETURN (rval);
01699 }
01700 
01701 dbl_QSLIB_INTERFACE int dbl_QSread_and_load_basis (
01702   dbl_QSdata * p,
01703   const char *filename)
01704 {
01705   int rval = 0;
01706 
01707   rval = dbl_check_qsdata_pointer (p);
01708   CHECKRVALG (rval, CLEANUP);
01709 
01710   if (p->basis == 0)
01711   {
01712     ILL_SAFE_MALLOC (p->basis, 1, dbl_ILLlp_basis);
01713     dbl_ILLlp_basis_init (p->basis);
01714   }
01715   else
01716   {
01717     dbl_ILLlp_basis_free (p->basis);
01718   }
01719 
01720   rval = dbl_ILLlib_readbasis (p->lp, p->basis, filename);
01721   CHECKRVALG (rval, CLEANUP);
01722 
01723 CLEANUP:
01724 
01725   return rval;
01726 }
01727 
01728 dbl_QSLIB_INTERFACE int dbl_QSload_basis_array (
01729   dbl_QSdata * p,
01730   char *cstat,
01731   char *rstat)
01732 {
01733   int rval = 0;
01734   int i;
01735   dbl_ILLlp_basis *B;
01736   dbl_ILLlpdata *qslp;
01737 
01738   rval = dbl_check_qsdata_pointer (p);
01739   CHECKRVALG (rval, CLEANUP);
01740 
01741   qslp = p->qslp;
01742 
01743   if (qslp->nstruct > 0 && cstat == 0)
01744   {
01745     fprintf (stderr, "dbl_QSload_basis_array called without cstat\n");
01746     rval = 1;
01747     goto CLEANUP;
01748   }
01749 
01750   if (qslp->nrows > 0 && rstat == 0)
01751   {
01752     fprintf (stderr, "dbl_QSload_basis_array called without rstat\n");
01753     rval = 1;
01754     goto CLEANUP;
01755   }
01756 
01757   if (p->basis == 0)
01758   {
01759     ILL_SAFE_MALLOC (p->basis, 1, dbl_ILLlp_basis);
01760     dbl_ILLlp_basis_init (p->basis);
01761   }
01762   else
01763   {
01764     dbl_ILLlp_basis_free (p->basis);
01765   }
01766 
01767   B = p->basis;
01768 
01769   B->nstruct = qslp->nstruct;
01770   B->nrows = qslp->nrows;
01771   ILL_SAFE_MALLOC (B->cstat, qslp->nstruct, char);
01772   ILL_SAFE_MALLOC (B->rstat, qslp->nrows, char);
01773 
01774   for (i = 0; i < qslp->nstruct; i++)
01775   {
01776     B->cstat[i] = cstat[i];
01777   }
01778 
01779   for (i = 0; i < qslp->nrows; i++)
01780   {
01781     B->rstat[i] = rstat[i];
01782   }
01783 
01784   p->factorok = 0;
01785 
01786 CLEANUP:
01787 
01788   EG_RETURN (rval);
01789 }
01790 
01791 dbl_QSLIB_INTERFACE int dbl_QSload_basis_and_row_norms_array (
01792   dbl_QSdata * p,
01793   char *cstat,
01794   char *rstat,
01795   double * rownorms)
01796 {
01797   int rval = 0;
01798   int i, nrows;
01799 
01800   rval = dbl_check_qsdata_pointer (p);
01801   CHECKRVALG (rval, CLEANUP);
01802 
01803   nrows = p->qslp->nrows;
01804 
01805   rval = dbl_QSload_basis_array (p, cstat, rstat);
01806   CHECKRVALG (rval, CLEANUP);
01807   p->basis->rownorms = dbl_EGlpNumAllocArray (nrows);
01808 
01809   for (i = 0; i < nrows; i++)
01810   {
01811     dbl_EGlpNumCopy (p->basis->rownorms[i], rownorms[i]);
01812   }
01813 
01814   p->factorok = 0;
01815 
01816 CLEANUP:
01817 
01818   EG_RETURN (rval);
01819 }
01820 
01821 dbl_QSLIB_INTERFACE int dbl_QSwrite_basis (
01822   dbl_QSdata * p,
01823   QSbasis * B,
01824   const char *filename)
01825 {
01826   int rval = 0;
01827   dbl_ILLlp_basis iB, *basis = 0;
01828 
01829   dbl_ILLlp_basis_init (&iB);
01830 
01831   rval = dbl_check_qsdata_pointer (p);
01832   CHECKRVALG (rval, CLEANUP);
01833 
01834   if (B)
01835   {
01836     rval = dbl_qsbasis_to_illbasis (B, &iB);
01837     CHECKRVALG (rval, CLEANUP);
01838     basis = &iB;
01839   }
01840   else
01841   {
01842     if (p->basis == 0)
01843     {
01844       fprintf (stderr, "no basis available in dbl_QSwrite_basis\n");
01845       rval = 1;
01846       goto CLEANUP;
01847     }
01848     basis = p->basis;
01849   }
01850 
01851   rval = dbl_ILLlib_writebasis (p->lp, basis, filename);
01852   CHECKRVALG (rval, CLEANUP);
01853 
01854 
01855 CLEANUP:
01856 
01857   dbl_ILLlp_basis_free (basis);
01858   EG_RETURN (rval);
01859 }
01860 
01861 dbl_QSLIB_INTERFACE QSbasis *dbl_QSget_basis (
01862   dbl_QSdata * p)
01863 {
01864   int rval = 0;
01865   QSbasis *B = 0;
01866 
01867   if (p->basis == 0)
01868   {
01869     fprintf (stderr, "no basis available in dbl_QSget_basis\n");
01870     rval = 1;
01871     goto CLEANUP;
01872   }
01873 
01874   ILL_SAFE_MALLOC (B, 1, QSbasis);
01875   dbl_init_basis (B);
01876   rval = dbl_illbasis_to_qsbasis (p->basis, B);
01877   CHECKRVALG (rval, CLEANUP);
01878 
01879 CLEANUP:
01880 
01881   if (rval)
01882   {
01883     dbl_QSfree_basis (B);
01884     B = 0;
01885   }
01886 
01887   return B;
01888 }
01889 
01890 dbl_QSLIB_INTERFACE int dbl_QSget_basis_array (
01891   dbl_QSdata * p,
01892   char *cstat,
01893   char *rstat)
01894 {
01895   int rval = 0;
01896   int i;
01897 
01898   rval = dbl_check_qsdata_pointer (p);
01899   CHECKRVALG (rval, CLEANUP);
01900 
01901   if (p->basis == 0)
01902   {
01903     fprintf (stderr, "no basis available in dbl_QSget_basis_array\n");
01904     rval = 1;
01905     goto CLEANUP;
01906   }
01907 
01908   for (i = 0; i < p->basis->nstruct; i++)
01909     cstat[i] = p->basis->cstat[i];
01910   for (i = 0; i < p->basis->nrows; i++)
01911     rstat[i] = p->basis->rstat[i];
01912 
01913 CLEANUP:
01914 
01915   EG_RETURN (rval);
01916 }
01917 
01918 dbl_QSLIB_INTERFACE int dbl_QSget_basis_and_row_norms_array (
01919   dbl_QSdata * p,
01920   char *cstat,
01921   char *rstat,
01922   double * rownorms)
01923 {
01924   int rval = 0;
01925   int i;
01926 
01927   rval = dbl_check_qsdata_pointer (p);
01928   CHECKRVALG (rval, CLEANUP);
01929 
01930   if (p->basis == 0)
01931   {
01932     fprintf (stderr, "no basis available\n");
01933     rval = 1;
01934     goto CLEANUP;
01935   }
01936 
01937   for (i = 0; i < p->basis->nstruct; i++)
01938     cstat[i] = p->basis->cstat[i];
01939   for (i = 0; i < p->basis->nrows; i++)
01940     rstat[i] = p->basis->rstat[i];
01941 
01942   if (p->basis->rownorms == 0)
01943   {
01944     fprintf (stderr, "no row norms available\n");
01945     rval = 1;
01946     goto CLEANUP;
01947   }
01948   else
01949   {
01950     for (i = 0; i < p->basis->nrows; i++)
01951     {
01952       dbl_EGlpNumCopy (rownorms[i], p->basis->rownorms[i]);
01953     }
01954   }
01955 
01956 CLEANUP:
01957 
01958   EG_RETURN (rval);
01959 }
01960 
01961 static int dbl_illbasis_to_qsbasis (
01962   dbl_ILLlp_basis * B,
01963   QSbasis * qB)
01964 {
01965   int rval = 0;
01966   int i;
01967 
01968   qB->nstruct = B->nstruct;
01969   qB->nrows = B->nrows;
01970   ILL_SAFE_MALLOC (qB->cstat, B->nstruct, char);
01971   ILL_SAFE_MALLOC (qB->rstat, B->nrows, char);
01972 
01973   for (i = 0; i < B->nstruct; i++)
01974   {
01975     qB->cstat[i] = B->cstat[i];
01976   }
01977 
01978   for (i = 0; i < B->nrows; i++)
01979   {
01980     qB->rstat[i] = B->rstat[i];
01981   }
01982 
01983 CLEANUP:
01984 
01985   EG_RETURN (rval);
01986 }
01987 
01988 static int dbl_qsbasis_to_illbasis (
01989   QSbasis * qB,
01990   dbl_ILLlp_basis * B)
01991 {
01992   int rval = 0;
01993   int i;
01994   int nbas = 0;
01995 
01996   B->nstruct = qB->nstruct;
01997   B->nrows = qB->nrows;
01998   ILL_SAFE_MALLOC (B->cstat, qB->nstruct, char);
01999   ILL_SAFE_MALLOC (B->rstat, qB->nrows, char);
02000 
02001   for (i = 0; i < qB->nstruct; i++)
02002   {
02003     if(qB->cstat[i] == QS_COL_BSTAT_BASIC) nbas++;
02004     B->cstat[i] = qB->cstat[i];
02005   }
02006 
02007   for (i = 0; i < qB->nrows; i++)
02008   {
02009     if(qB->rstat[i] == QS_ROW_BSTAT_BASIC) nbas++;
02010     B->rstat[i] = qB->rstat[i];
02011   }
02012 
02013   if(nbas != qB->nrows)
02014   {
02015     fprintf(stderr,"Received basis is not valid, in dbl_qsbasis_to_illbasis\n");
02016     rval = 1;
02017     ILL_CLEANUP;
02018   }
02019 
02020 CLEANUP:
02021 
02022   EG_RETURN (rval);
02023 }
02024 
02025 int dbl_grab_basis (
02026   dbl_QSdata * p)
02027 {
02028   int rval = 0;
02029   dbl_ILLlp_basis *B = p->basis;
02030   int nstruct = p->qslp->nstruct;
02031   int nrows = p->qslp->nrows;
02032 
02033   if (!B)
02034   {
02035     ILL_SAFE_MALLOC (p->basis, 1, dbl_ILLlp_basis);
02036     dbl_ILLlp_basis_init (p->basis);
02037     B = p->basis;
02038   }
02039 
02040   if (nstruct != B->nstruct)
02041   {
02042     ILL_IFFREE (B->cstat, char);
02043     ILL_SAFE_MALLOC (B->cstat, nstruct, char);
02044 
02045     B->nstruct = nstruct;
02046   }
02047 
02048   if (nrows != B->nrows)
02049   {
02050     ILL_IFFREE (B->rstat, char);
02051     ILL_SAFE_MALLOC (B->rstat, nrows, char);
02052 
02053     B->nrows = nrows;
02054   }
02055 
02056   rval = dbl_ILLlib_getbasis (p->lp, B->cstat, B->rstat);
02057   CHECKRVALG (rval, CLEANUP);
02058 
02059   dbl_EGlpNumFreeArray (B->rownorms);
02060   dbl_EGlpNumFreeArray (B->colnorms);
02061 
02062   if (p->pricing->dII_price == QS_PRICE_DSTEEP)
02063   {
02064     B->rownorms = dbl_EGlpNumAllocArray (nrows);
02065     rval = dbl_ILLlib_getrownorms (p->lp, p->pricing, B->rownorms);
02066     if (rval)
02067     {
02068 /*
02069             fprintf (stderr, "no dbl_edge norms, continue anyway\n");
02070 */
02071       dbl_EGlpNumFreeArray (B->rownorms);
02072       rval = 0;
02073     }
02074   }
02075 
02076 CLEANUP:
02077 
02078   if (rval)
02079   {
02080     if (B)
02081     {
02082       dbl_ILLlp_basis_free (B);
02083       ILL_IFFREE (p->basis, dbl_ILLlp_basis);
02084     }
02085   }
02086 
02087   EG_RETURN (rval);
02088 }
02089 
02090 int dbl_grab_cache (
02091   dbl_QSdata * p,
02092   int status)
02093 {
02094   int rval = 0;
02095   dbl_ILLlp_cache *C = p->cache;
02096   int nstruct = p->qslp->nstruct;
02097   int nrows = p->qslp->nrows;
02098   #if 0
02099   /* we may need to fix basic status for fixed variables */
02100   register int i;
02101   char *const cstat = p->basis->cstat;
02102   const int *const structmap = p->lp->O->structmap;
02103   const int sense = p->lp->O->objsense;
02104   const int *const vtype = p->lp->vtype;
02105   int *const vstat = p->lp->vstat;
02106   /* end extra variables needed */
02107   #endif
02108 
02109   if (C == 0)
02110   {
02111     ILL_SAFE_MALLOC (p->cache, 1, dbl_ILLlp_cache);
02112     dbl_EGlpNumInitVar (p->cache->val);
02113     dbl_ILLlp_cache_init (p->cache);
02114     C = p->cache;
02115   }
02116 
02117   if (nstruct != C->nstruct || nrows != C->nrows)
02118   {
02119     dbl_ILLlp_cache_free (C);
02120     rval = dbl_ILLlp_cache_alloc (C, nstruct, nrows);
02121     CHECKRVALG (rval, CLEANUP);
02122   }
02123 
02124   rval = dbl_ILLlib_cache_solution (p->lp, C);
02125   CHECKRVALG (rval, CLEANUP);
02126 
02127   #if 0
02128   /* we fix basis status and vstat */
02129   for( i = nstruct ; i-- ; )
02130   {
02131     if(vtype[structmap[i]] != VFIXED) continue;
02132     if(cstat[i] == QS_COL_BSTAT_BASIC) continue;
02133     if(( sense > 0 && dbl_EGlpNumIsLess(dbl_SZERO_TOLER,C->rc[i])) ||
02134        ( sense < 0 && !dbl_EGlpNumIsLess(dbl_SZERO_TOLER,C->rc[i])))
02135     {
02136       vstat[structmap[i]] = STAT_LOWER;
02137       cstat[i] = QS_COL_BSTAT_LOWER;
02138     }
02139     else
02140     {
02141       vstat[structmap[i]] = STAT_UPPER;
02142       cstat[i] = QS_COL_BSTAT_UPPER;
02143     }
02144   }/* end fix */
02145   #endif
02146   C->status = status;
02147 
02148 CLEANUP:
02149 
02150   if (rval)
02151   {
02152     if (C)
02153     {
02154       dbl_ILLlp_cache_free (C);
02155       dbl_EGlpNumClearVar (p->cache->val);
02156       ILL_IFFREE (p->cache, dbl_ILLlp_cache);
02157     }
02158   }
02159 
02160   EG_RETURN (rval);
02161 }
02162 
02163 void dbl_free_cache (
02164   dbl_QSdata * p)
02165 {
02166   if (p->cache)
02167   {
02168     dbl_ILLlp_cache_free (p->cache);
02169     dbl_EGlpNumClearVar (p->cache->val);
02170     ILL_IFFREE (p->cache, dbl_ILLlp_cache);
02171   }
02172   p->qstatus = QS_LP_MODIFIED;
02173 }
02174 
02175 dbl_QSLIB_INTERFACE int dbl_QSget_binv_row (
02176   dbl_QSdata * p,
02177   int indx,
02178   double * binvrow)
02179 {
02180   int rval = 0;
02181 
02182   rval = dbl_check_qsdata_pointer (p);
02183   CHECKRVALG (rval, CLEANUP);
02184 
02185   if(!p->basis)
02186   {
02187     fprintf(stderr, "no active basis in store\n");
02188     rval = 1;
02189     goto CLEANUP;
02190   }
02191   if(0>indx || indx >= dbl_QSget_rowcount(p))
02192   {
02193     fprintf(stderr, "row index %d outside valid bounds [%d:%d]\n",
02194             indx, 0, dbl_QSget_rowcount(p)-1);
02195     rval = 1;
02196     goto CLEANUP;
02197   }
02198   if (p->cache == 0)
02199   {
02200     fprintf (stderr, "LP has not been optimized in dbl_QSget_binv_row\n");
02201     rval = 1;
02202     goto CLEANUP;
02203   }
02204 
02205   rval = dbl_ILLlib_tableau (p->lp, indx, binvrow, 0);
02206   CHECKRVALG (rval, CLEANUP);
02207 
02208 CLEANUP:
02209 
02210   EG_RETURN (rval);
02211 }
02212 
02213 dbl_QSLIB_INTERFACE int dbl_QSget_tableau_row (
02214   dbl_QSdata * p,
02215   int indx,
02216   double * tableaurow)
02217 {
02218   int rval = 0;
02219 
02220   rval = dbl_check_qsdata_pointer (p);
02221   CHECKRVALG (rval, CLEANUP);
02222 
02223   if (p->cache == 0)
02224   {
02225     fprintf (stderr, "LP has not been optimized in dbl_QSget_tableau_row\n");
02226     rval = 1;
02227     goto CLEANUP;
02228   }
02229 
02230   rval = dbl_ILLlib_tableau (p->lp, indx, 0, tableaurow);
02231   CHECKRVALG (rval, CLEANUP);
02232 
02233 CLEANUP:
02234 
02235   EG_RETURN (rval);
02236 }
02237 
02238 dbl_QSLIB_INTERFACE int dbl_QSget_basis_order (
02239   dbl_QSdata * p,
02240   int *basorder)
02241 {
02242   int rval = 0;
02243 
02244   rval = dbl_check_qsdata_pointer (p);
02245   CHECKRVALG (rval, CLEANUP);
02246 
02247   if (p->cache == 0)
02248   {
02249     fprintf (stderr, "LP has not been optimized in dbl_QSget_basis_order\n");
02250     rval = 1;
02251     goto CLEANUP;
02252   }
02253 
02254   rval = dbl_ILLlib_basis_order (p->lp, basorder);
02255   CHECKRVALG (rval, CLEANUP);
02256 
02257 CLEANUP:
02258 
02259   EG_RETURN (rval);
02260 }
02261 
02262 dbl_QSLIB_INTERFACE int dbl_QScompute_row_norms (
02263   dbl_QSdata * p)
02264 {
02265   int rval = 0;
02266 
02267   rval = dbl_check_qsdata_pointer (p);
02268   CHECKRVALG (rval, CLEANUP);
02269 
02270   if (p->pricing->dII_price != QS_PRICE_DSTEEP)
02271   {
02272     fprintf (stderr, "not using dual steepest dbl_edge\n");
02273     rval = 1;
02274     goto CLEANUP;
02275   }
02276 
02277   rval = dbl_ILLlib_recompute_rownorms (p->lp, p->pricing);
02278   CHECKRVALG (rval, CLEANUP);
02279 
02280   rval = dbl_grab_basis (p);
02281   CHECKRVALG (rval, CLEANUP);
02282 
02283 CLEANUP:
02284 
02285   EG_RETURN (rval);
02286 }
02287 
02288 dbl_QSLIB_INTERFACE void dbl_QSfree_prob (
02289   dbl_QSdata * p)
02290 {
02291   if (p)
02292   {
02293     dbl_EGlpNumClearVar(p->uobjlim);
02294     dbl_EGlpNumClearVar(p->lobjlim);
02295     if (p->qslp)
02296     {
02297       dbl_ILLlpdata_free (p->qslp);
02298       ILL_IFFREE (p->qslp, dbl_ILLlpdata);
02299     }
02300     if (p->lp)
02301     {
02302       dbl_ILLsimplex_free_lpinfo (p->lp);
02303       dbl_EGlpNumClearVar (p->lp->objval);
02304       dbl_EGlpNumClearVar (p->lp->pobjval);
02305       dbl_EGlpNumClearVar (p->lp->dobjval);
02306       dbl_EGlpNumClearVar (p->lp->pinfeas);
02307       dbl_EGlpNumClearVar (p->lp->dinfeas);
02308       dbl_EGlpNumClearVar (p->lp->objbound);
02309       dbl_EGlpNumClearVar (p->lp->upd.piv);
02310       dbl_EGlpNumClearVar (p->lp->upd.dty);
02311       dbl_EGlpNumClearVar (p->lp->upd.c_obj);
02312       dbl_EGlpNumClearVar (p->lp->upd.tz);
02313       ILL_IFFREE (p->lp, dbl_lpinfo);
02314     }
02315     if (p->basis)
02316     {
02317       dbl_ILLlp_basis_free (p->basis);
02318       ILL_IFFREE (p->basis, dbl_ILLlp_basis);
02319     }
02320     if (p->cache)
02321     {
02322       dbl_ILLlp_cache_free (p->cache);
02323       dbl_EGlpNumClearVar (p->cache->val);
02324       ILL_IFFREE (p->cache, dbl_ILLlp_cache);
02325     }
02326     if (p->pricing)
02327     {
02328       dbl_EGlpNumClearVar (p->pricing->htrigger);
02329       dbl_ILLprice_free_pricing_info (p->pricing);
02330       ILL_IFFREE (p->pricing, dbl_price_info);
02331     }
02332     ILL_IFFREE (p->name, char);
02333 
02334     ILL_IFFREE (p, dbl_QSdata);
02335   }
02336 }
02337 
02338 dbl_QSLIB_INTERFACE void dbl_QSfree_basis (
02339   QSbasis * B)
02340 {
02341   if (B)
02342   {
02343     ILL_IFFREE (B->rstat, char);
02344     ILL_IFFREE (B->cstat, char);
02345 
02346     ILL_IFFREE (B, QSbasis);
02347   }
02348 }
02349 
02350 static void dbl_init_basis (
02351   QSbasis * B)
02352 {
02353   if (B)
02354   {
02355     B->nstruct = 0;
02356     B->nrows = 0;
02357     B->cstat = 0;
02358     B->rstat = 0;
02359   }
02360 }
02361 
02362 dbl_QSLIB_INTERFACE int dbl_QSget_status (
02363   dbl_QSdata * p,
02364   int *status)
02365 {
02366   int rval = 0;
02367 
02368   rval = dbl_check_qsdata_pointer (p);
02369   CHECKRVALG (rval, CLEANUP);
02370 
02371   if (status)
02372     *status = p->qstatus;
02373 
02374 CLEANUP:
02375 
02376   EG_RETURN (rval);
02377 }
02378 
02379 dbl_QSLIB_INTERFACE int dbl_QSget_solution (
02380   dbl_QSdata * p,
02381   double * value,
02382   double * x,
02383   double * pi,
02384   double * slack,
02385   double * rc)
02386 {
02387   int rval = 0;
02388 
02389   rval = dbl_check_qsdata_pointer (p);
02390   CHECKRVALG (rval, CLEANUP);
02391 
02392   if (p->cache == 0)
02393   {
02394     fprintf (stderr, "no solution available in dbl_QSget_solution\n");
02395     rval = 1;
02396     goto CLEANUP;
02397   }
02398 
02399   rval = dbl_ILLlib_solution (p->lp, p->cache, value, x, pi, slack, rc);
02400   CHECKRVALG (rval, CLEANUP);
02401 
02402 CLEANUP:
02403 
02404   EG_RETURN (rval);
02405 }
02406 
02407 dbl_QSLIB_INTERFACE int dbl_QSget_objval (
02408   dbl_QSdata * p,
02409   double * value)
02410 {
02411   int rval = 0;
02412 
02413   rval = dbl_check_qsdata_pointer (p);
02414   CHECKRVALG (rval, CLEANUP);
02415 
02416 /* Want to get objval after limited number of pivots. */
02417 
02418   if (p->qstatus == QS_LP_MODIFIED)
02419   {
02420     fprintf (stderr, "QSmsg: LP has been modified since last solve.\n");
02421     rval = 1;
02422     ILL_CLEANUP;
02423   }
02424 
02425   rval = dbl_ILLlib_objval (p->lp, p->cache, value);
02426   CHECKRVALG (rval, CLEANUP);
02427 
02428 CLEANUP:
02429 
02430   EG_RETURN (rval);
02431 }
02432 
02433 dbl_QSLIB_INTERFACE int dbl_QSget_x_array (
02434   dbl_QSdata * p,
02435   double * x)
02436 {
02437   int rval = 0;
02438 
02439   rval = dbl_check_qsdata_pointer (p);
02440   CHECKRVALG (rval, CLEANUP);
02441 
02442   if (p->cache == 0)
02443   {
02444     fprintf (stderr, "no solution available in dbl_QSget_x_array\n");
02445     rval = 1;
02446     goto CLEANUP;
02447   }
02448 
02449   rval = dbl_ILLlib_get_x (p->lp, p->cache, x);
02450   CHECKRVALG (rval, CLEANUP);
02451 
02452 CLEANUP:
02453 
02454   EG_RETURN (rval);
02455 }
02456 
02457 dbl_QSLIB_INTERFACE int dbl_QSget_slack_array (
02458   dbl_QSdata * p,
02459   double * slack)
02460 {
02461   int rval = 0;
02462 
02463   rval = dbl_check_qsdata_pointer (p);
02464   CHECKRVALG (rval, CLEANUP);
02465 
02466   if (p->cache == 0)
02467   {
02468     fprintf (stderr, "no solution available in dbl_QSget_slack_array\n");
02469     rval = 1;
02470     goto CLEANUP;
02471   }
02472 
02473   rval = dbl_ILLlib_get_slack (p->lp, p->cache, slack);
02474   CHECKRVALG (rval, CLEANUP);
02475 
02476 CLEANUP:
02477 
02478   EG_RETURN (rval);
02479 }
02480 
02481 dbl_QSLIB_INTERFACE int dbl_QSget_rc_array (
02482   dbl_QSdata * p,
02483   double * rc)
02484 {
02485   int rval = 0;
02486 
02487   rval = dbl_check_qsdata_pointer (p);
02488   CHECKRVALG (rval, CLEANUP);
02489 
02490   if (p->cache == 0)
02491   {
02492     fprintf (stderr, "no solution available in dbl_QSget_rc_array\n");
02493     rval = 1;
02494     goto CLEANUP;
02495   }
02496 
02497   rval = dbl_ILLlib_solution (p->lp, p->cache, 0, 0, 0, 0, rc);
02498   CHECKRVALG (rval, CLEANUP);
02499 
02500 CLEANUP:
02501 
02502   EG_RETURN (rval);
02503 }
02504 
02505 dbl_QSLIB_INTERFACE int dbl_QSget_pi_array (
02506   dbl_QSdata * p,
02507   double * pi)
02508 {
02509   int rval = 0;
02510 
02511   rval = dbl_check_qsdata_pointer (p);
02512   CHECKRVALG (rval, CLEANUP);
02513 
02514   if (p->cache == 0)
02515   {
02516     fprintf (stderr, "no solution available in dbl_QSget_pi_array\n");
02517     rval = 1;
02518     goto CLEANUP;
02519   }
02520 
02521   rval = dbl_ILLlib_solution (p->lp, p->cache, 0, 0, pi, 0, 0);
02522   CHECKRVALG (rval, CLEANUP);
02523 
02524 CLEANUP:
02525 
02526   EG_RETURN (rval);
02527 }
02528 
02529 dbl_QSLIB_INTERFACE int dbl_QSget_infeas_array (
02530   dbl_QSdata * p,
02531   double * pi)
02532 {
02533   int rval = 0;
02534 
02535   rval = dbl_check_qsdata_pointer (p);
02536   CHECKRVALG (rval, CLEANUP);
02537 
02538   if (pi == 0)
02539   {
02540     ILL_ERROR (rval, "QS_get_infeas_array called with NULL pi vector\n");
02541   }
02542 
02543   rval = dbl_ILLsimplex_infcertificate (p->lp, pi);
02544   CHECKRVALG (rval, CLEANUP);
02545 
02546 CLEANUP:
02547 
02548   EG_RETURN (rval);
02549 }
02550 
02551 dbl_QSLIB_INTERFACE int dbl_QSget_named_x (
02552   dbl_QSdata * p,
02553   const char *colname,
02554   double * val)
02555 {
02556   int rval = 0;
02557   int j;
02558 
02559   rval = dbl_check_qsdata_pointer (p);
02560   CHECKRVALG (rval, CLEANUP);
02561 
02562   if (p->cache == 0)
02563   {
02564     fprintf (stderr, "no solution available in dbl_QSget_named_x\n");
02565     rval = 1;
02566     goto CLEANUP;
02567   }
02568 
02569   rval = dbl_QSget_column_index (p, colname, &j);
02570   CHECKRVALG (rval, CLEANUP);
02571 
02572   if (j != -1)
02573   {
02574     dbl_EGlpNumCopy (*val, p->cache->x[j]);
02575   }
02576   else
02577   {
02578     rval = 1;
02579   }
02580 
02581 CLEANUP:
02582 
02583   EG_RETURN (rval);
02584 }
02585 
02586 dbl_QSLIB_INTERFACE int dbl_QSget_named_rc (
02587   dbl_QSdata * p,
02588   const char *colname,
02589   double * val)
02590 {
02591   int rval = 0;
02592   int j;
02593 
02594   rval = dbl_check_qsdata_pointer (p);
02595   CHECKRVALG (rval, CLEANUP);
02596 
02597   if (p->cache == 0)
02598   {
02599     fprintf (stderr, "no solution available in dbl_QSget_named_rc\n");
02600     rval = 1;
02601     goto CLEANUP;
02602   }
02603 
02604   rval = dbl_QSget_column_index (p, colname, &j);
02605   CHECKRVALG (rval, CLEANUP);
02606 
02607   if (j != -1)
02608   {
02609     dbl_EGlpNumCopy (*val, p->cache->rc[j]);
02610   }
02611   else
02612   {
02613     rval = 1;
02614   }
02615 
02616 CLEANUP:
02617 
02618   EG_RETURN (rval);
02619 }
02620 
02621 dbl_QSLIB_INTERFACE int dbl_QSget_named_pi (
02622   dbl_QSdata * p,
02623   const char *rowname,
02624   double * val)
02625 {
02626   int rval = 0;
02627   int i;
02628 
02629   rval = dbl_check_qsdata_pointer (p);
02630   CHECKRVALG (rval, CLEANUP);
02631 
02632   if (p->cache == 0)
02633   {
02634     fprintf (stderr, "no solution available in dbl_QSget_named_pi\n");
02635     rval = 1;
02636     goto CLEANUP;
02637   }
02638 
02639   rval = dbl_QSget_row_index (p, rowname, &i);
02640   CHECKRVALG (rval, CLEANUP);
02641 
02642   if (i != -1)
02643   {
02644     dbl_EGlpNumCopy (*val, p->cache->pi[i]);
02645   }
02646   else
02647   {
02648     rval = 1;
02649   }
02650 
02651 CLEANUP:
02652 
02653   EG_RETURN (rval);
02654 }
02655 
02656 dbl_QSLIB_INTERFACE int dbl_QSget_named_slack (
02657   dbl_QSdata * p,
02658   const char *rowname,
02659   double * val)
02660 {
02661   int rval = 0;
02662   int i;
02663 
02664   rval = dbl_check_qsdata_pointer (p);
02665   CHECKRVALG (rval, CLEANUP);
02666 
02667   if (p->cache == 0)
02668   {
02669     fprintf (stderr, "no solution available in dbl_QSget_named_slack\n");
02670     rval = 1;
02671     goto CLEANUP;
02672   }
02673 
02674   rval = dbl_QSget_row_index (p, rowname, &i);
02675   CHECKRVALG (rval, CLEANUP);
02676 
02677   if (i != -1)
02678   {
02679     dbl_EGlpNumCopy (*val, p->cache->slack[i]);
02680   }
02681   else
02682   {
02683     rval = 1;
02684   }
02685 
02686 CLEANUP:
02687 
02688   EG_RETURN (rval);
02689 }
02690 
02691 dbl_QSLIB_INTERFACE int dbl_QSget_colcount (
02692   dbl_QSdata * p)
02693 {
02694   int cnt;
02695 
02696   if (dbl_check_qsdata_pointer (p))
02697     cnt = 0;
02698   else
02699     cnt = p->qslp->nstruct;
02700 
02701   return cnt;
02702 }
02703 
02704 dbl_QSLIB_INTERFACE int dbl_QSget_rowcount (
02705   dbl_QSdata * p)
02706 {
02707   int cnt;
02708 
02709   if (dbl_check_qsdata_pointer (p))
02710     cnt = 0;
02711   else
02712     cnt = p->qslp->nrows;
02713 
02714   return cnt;
02715 }
02716 
02717 dbl_QSLIB_INTERFACE int dbl_QSget_nzcount (
02718   dbl_QSdata * p)
02719 {
02720   int cnt;
02721 
02722   if (dbl_check_qsdata_pointer (p))
02723     cnt = 0;
02724   else
02725     cnt = p->qslp->nzcount - p->qslp->nrows;
02726 
02727   return cnt;
02728 }
02729 
02730 dbl_QSLIB_INTERFACE int dbl_QStest_row_norms (
02731   dbl_QSdata * p)
02732 {
02733   int yesno;
02734 
02735   if (dbl_check_qsdata_pointer (p))
02736   {
02737     yesno = 0;
02738   }
02739   else
02740   {
02741     if (p->basis && p->basis->rownorms)
02742     {
02743       yesno = 1;
02744     }
02745     else
02746     {
02747       yesno = 0;
02748     }
02749   }
02750 
02751   return yesno;
02752 }
02753 
02754 dbl_QSLIB_INTERFACE int dbl_QSget_obj_list(dbl_QSprob p,
02755   int num,
02756   int*collist,
02757   double*obj)
02758 {
02759   int rval = 0;
02760   rval = dbl_check_qsdata_pointer (p);
02761   CHECKRVALG (rval, CLEANUP);
02762   rval = dbl_ILLlib_getobj_list (p->lp, num, collist, obj);
02763   CHECKRVALG (rval, CLEANUP);
02764 
02765 CLEANUP:
02766   EG_RETURN (rval);
02767 }
02768 
02769 dbl_QSLIB_INTERFACE int dbl_QSget_obj (
02770   dbl_QSdata * p,
02771   double * obj)
02772 {
02773   int rval = 0;
02774 
02775   rval = dbl_check_qsdata_pointer (p);
02776   CHECKRVALG (rval, CLEANUP);
02777 
02778   rval = dbl_ILLlib_getobj (p->lp, obj);
02779   CHECKRVALG (rval, CLEANUP);
02780 
02781 CLEANUP:
02782 
02783   EG_RETURN (rval);
02784 }
02785 
02786 dbl_QSLIB_INTERFACE int dbl_QSget_rhs (
02787   dbl_QSdata * p,
02788   double * rhs)
02789 {
02790   int rval = 0;
02791 
02792   rval = dbl_check_qsdata_pointer (p);
02793   CHECKRVALG (rval, CLEANUP);
02794 
02795   rval = dbl_ILLlib_getrhs (p->lp, rhs);
02796   CHECKRVALG (rval, CLEANUP);
02797 
02798 CLEANUP:
02799 
02800   EG_RETURN (rval);
02801 }
02802 
02803 dbl_QSLIB_INTERFACE int dbl_QSget_ranged_rows_list (
02804   dbl_QSdata * p,
02805   int num,
02806   int *rowlist,
02807   int **rowcnt,
02808   int **rowbeg,
02809   int **rowind,
02810   double ** rowval,
02811   double ** rhs,
02812   char **sense,
02813   double ** range,
02814   char ***names)
02815 {
02816   int rval = 0;
02817   int i, nrows;
02818 
02819   rval = dbl_check_qsdata_pointer (p);
02820   CHECKRVALG (rval, CLEANUP);
02821 
02822   nrows = dbl_QSget_rowcount (p);
02823   for (i = 0; i < num; i++)
02824   {
02825     if (rowlist[i] < 0 || rowlist[i] >= nrows)
02826     {
02827       fprintf (stderr, "entry %d in rowlist out of range\n", i);
02828       rval = 1;
02829       goto CLEANUP;
02830     }
02831   }
02832 
02833   rval = dbl_ILLlib_getrows (p->lp, num, rowlist, rowcnt, rowbeg, rowind,
02834                          rowval, rhs, sense, range, names);
02835   CHECKRVALG (rval, CLEANUP);
02836 
02837 
02838 CLEANUP:
02839 
02840   EG_RETURN (rval);
02841 }
02842 
02843 dbl_QSLIB_INTERFACE int dbl_QSget_ranged_rows (
02844   dbl_QSdata * p,
02845   int **rowcnt,
02846   int **rowbeg,
02847   int **rowind,
02848   double ** rowval,
02849   double ** rhs,
02850   char **sense,
02851   double ** range,
02852   char ***names)
02853 {
02854   int rval = 0;
02855   int i, nrows;
02856   int *rowlist = 0;
02857 
02858   rval = dbl_check_qsdata_pointer (p);
02859   CHECKRVALG (rval, CLEANUP);
02860 
02861   nrows = dbl_QSget_rowcount (p);
02862   if (nrows > 0)
02863   {
02864     ILL_SAFE_MALLOC (rowlist, nrows, int);
02865 
02866     for (i = 0; i < nrows; i++)
02867     {
02868       rowlist[i] = i;
02869     }
02870     rval = dbl_ILLlib_getrows (p->lp, nrows, rowlist, rowcnt, rowbeg, rowind,
02871                            rowval, rhs, sense, range, names);
02872     CHECKRVALG (rval, CLEANUP);
02873   }
02874 
02875 CLEANUP:
02876 
02877   ILL_IFFREE (rowlist, int);
02878 
02879   EG_RETURN (rval);
02880 }
02881 
02882 dbl_QSLIB_INTERFACE int dbl_QSget_senses (
02883   dbl_QSdata *p,
02884   char *senses)
02885 {
02886   int rval = 0;
02887 
02888   rval = dbl_check_qsdata_pointer (p);
02889   CHECKRVALG (rval, CLEANUP);
02890 
02891   rval = dbl_ILLlib_getsenses (p->lp, senses);
02892   CHECKRVALG (rval, CLEANUP);
02893 
02894 CLEANUP:
02895 
02896   EG_RETURN (rval);
02897 }
02898 
02899 
02900 
02901 dbl_QSLIB_INTERFACE int dbl_QSget_rows_list (
02902   dbl_QSdata * p,
02903   int num,
02904   int *rowlist,
02905   int **rowcnt,
02906   int **rowbeg,
02907   int **rowind,
02908   double ** rowval,
02909   double ** rhs,
02910   char **sense,
02911   char ***names)
02912 {
02913   int rval = 0;
02914   int i, nrows;
02915 
02916   rval = dbl_check_qsdata_pointer (p);
02917   CHECKRVALG (rval, CLEANUP);
02918 
02919   nrows = dbl_QSget_rowcount (p);
02920   for (i = 0; i < num; i++)
02921   {
02922     if (rowlist[i] < 0 || rowlist[i] >= nrows)
02923     {
02924       fprintf (stderr, "entry %d in rowlist out of range\n", i);
02925       rval = 1;
02926       goto CLEANUP;
02927     }
02928   }
02929 
02930   rval = dbl_ILLlib_getrows (p->lp, num, rowlist, rowcnt, rowbeg, rowind,
02931                          rowval, rhs, sense, 0, names);
02932   CHECKRVALG (rval, CLEANUP);
02933 
02934 
02935 CLEANUP:
02936 
02937   EG_RETURN (rval);
02938 }
02939 
02940 dbl_QSLIB_INTERFACE int dbl_QSget_rows (
02941   dbl_QSdata * p,
02942   int **rowcnt,
02943   int **rowbeg,
02944   int **rowind,
02945   double ** rowval,
02946   double ** rhs,
02947   char **sense,
02948   char ***names)
02949 {
02950   int rval = 0;
02951   int i, nrows;
02952   int *rowlist = 0;
02953 
02954   rval = dbl_check_qsdata_pointer (p);
02955   CHECKRVALG (rval, CLEANUP);
02956 
02957   nrows = dbl_QSget_rowcount (p);
02958   if (nrows > 0)
02959   {
02960     ILL_SAFE_MALLOC (rowlist, nrows, int);
02961 
02962     for (i = 0; i < nrows; i++)
02963     {
02964       rowlist[i] = i;
02965     }
02966     rval = dbl_ILLlib_getrows (p->lp, nrows, rowlist, rowcnt, rowbeg, rowind,
02967                            rowval, rhs, sense, 0, names);
02968     CHECKRVALG (rval, CLEANUP);
02969   }
02970 
02971 CLEANUP:
02972 
02973   ILL_IFFREE (rowlist, int);
02974 
02975   EG_RETURN (rval);
02976 }
02977 
02978 dbl_QSLIB_INTERFACE int dbl_QSget_columns_list (
02979   dbl_QSdata * p,
02980   int num,
02981   int *collist,
02982   int **colcnt,
02983   int **colbeg,
02984   int **colind,
02985   double ** colval,
02986   double ** obj,
02987   double ** lower,
02988   double ** upper,
02989   char ***names)
02990 {
02991   int rval = 0;
02992   int j, ncols;
02993 
02994   rval = dbl_check_qsdata_pointer (p);
02995   CHECKRVALG (rval, CLEANUP);
02996 
02997   ncols = dbl_QSget_colcount (p);
02998   for (j = 0; j < num; j++)
02999   {
03000     if (collist[j] < 0 || collist[j] >= ncols)
03001     {
03002       fprintf (stderr, "entry %d in collist out of range\n", j);
03003       rval = 1;
03004       goto CLEANUP;
03005     }
03006   }
03007 
03008   rval = dbl_ILLlib_getcols (p->lp, num, collist, colcnt, colbeg, colind,
03009                          colval, obj, lower, upper, names);
03010   CHECKRVALG (rval, CLEANUP);
03011 
03012 CLEANUP:
03013 
03014   EG_RETURN (rval);
03015 }
03016 
03017 dbl_QSLIB_INTERFACE int dbl_QSget_columns (
03018   dbl_QSdata * p,
03019   int **colcnt,
03020   int **colbeg,
03021   int **colind,
03022   double ** colval,
03023   double ** obj,
03024   double ** lower,
03025   double ** upper,
03026   char ***names)
03027 {
03028   int rval = 0;
03029   int j, ncols;
03030   int *collist = 0;
03031 
03032   rval = dbl_check_qsdata_pointer (p);
03033   CHECKRVALG (rval, CLEANUP);
03034 
03035   ncols = dbl_QSget_colcount (p);
03036   if (ncols > 0)
03037   {
03038     ILL_SAFE_MALLOC (collist, ncols, int);
03039 
03040     for (j = 0; j < ncols; j++)
03041     {
03042       collist[j] = j;
03043     }
03044     rval = dbl_ILLlib_getcols (p->lp, ncols, collist, colcnt, colbeg, colind,
03045                            colval, obj, lower, upper, names);
03046     CHECKRVALG (rval, CLEANUP);
03047   }
03048 
03049 CLEANUP:
03050 
03051   ILL_IFFREE (collist, int);
03052 
03053   EG_RETURN (rval);
03054 }
03055 
03056 dbl_QSLIB_INTERFACE char *dbl_QSget_probname (
03057   dbl_QSdata * p)
03058 {
03059   int rval = 0;
03060   char *name = 0;
03061 
03062   rval = dbl_check_qsdata_pointer (p);
03063   CHECKRVALG (rval, CLEANUP);
03064 
03065   dbl_ILL_UTIL_STR (name, p->name);
03066 
03067 CLEANUP:
03068   ILL_RETURN_PTR (name, "dbl_QSget_probname");
03069 }
03070 
03071 dbl_QSLIB_INTERFACE char *dbl_QSget_objname (
03072   dbl_QSdata * p)
03073 {
03074   int rval = 0;
03075   char *name = 0;
03076 
03077   rval = dbl_check_qsdata_pointer (p);
03078   CHECKRVALG (rval, CLEANUP);
03079 
03080   if (p->qslp->objname != 0)
03081   {
03082     dbl_ILL_UTIL_STR (name, p->qslp->objname);
03083   }
03084 
03085 CLEANUP:
03086   ILL_RETURN_PTR (name, "dbl_QSget_objname");
03087 }
03088 
03089 dbl_QSLIB_INTERFACE int dbl_QSget_rownames (
03090   dbl_QSdata * p,
03091   char **rownames)
03092 {
03093   int rval = 0;
03094 
03095   rval = dbl_check_qsdata_pointer (p);
03096   CHECKRVALG (rval, CLEANUP);
03097 
03098   rval = dbl_ILLlib_rownames (p->lp, rownames);
03099   CHECKRVALG (rval, CLEANUP);
03100 
03101 CLEANUP:
03102 
03103   EG_RETURN (rval);
03104 }
03105 
03106 dbl_QSLIB_INTERFACE int dbl_QSget_colnames (
03107   dbl_QSdata * p,
03108   char **colnames)
03109 {
03110   int rval = 0;
03111 
03112   rval = dbl_check_qsdata_pointer (p);
03113   CHECKRVALG (rval, CLEANUP);
03114 
03115   rval = dbl_ILLlib_colnames (p->lp, colnames);
03116   CHECKRVALG (rval, CLEANUP);
03117 
03118 CLEANUP:
03119 
03120   EG_RETURN (rval);
03121 }
03122 
03123 dbl_QSLIB_INTERFACE int dbl_QSget_bound (
03124   dbl_QSdata * p,
03125   int colindex,
03126   int lu,
03127   double * bound)
03128 {
03129   int rval = 0;
03130 
03131   rval = dbl_check_qsdata_pointer (p);
03132   CHECKRVALG (rval, CLEANUP);
03133 
03134   rval = dbl_ILLlib_getbnd (p->lp, colindex, lu, bound);
03135   CHECKRVALG (rval, CLEANUP);
03136 
03137 CLEANUP:
03138 
03139   EG_RETURN (rval);
03140 }
03141 
03142 dbl_QSLIB_INTERFACE int dbl_QSget_bounds_list(
03143   dbl_QSdata* p,
03144   int num,
03145   int*collist,
03146   double*lb,
03147   double*ub)
03148 {
03149   int rval = 0;
03150 
03151   rval = dbl_check_qsdata_pointer (p);
03152   CHECKRVALG (rval, CLEANUP);
03153 
03154   rval = dbl_ILLlib_getbnds_list (p->lp, num, collist, lb, ub);
03155   CHECKRVALG (rval, CLEANUP);
03156   
03157 CLEANUP:
03158 
03159   EG_RETURN (rval);
03160 }
03161 
03162 dbl_QSLIB_INTERFACE int dbl_QSget_bounds (
03163   dbl_QSdata * p,
03164   double * lower,
03165   double * upper)
03166 {
03167   int rval = 0;
03168 
03169   rval = dbl_check_qsdata_pointer (p);
03170   CHECKRVALG (rval, CLEANUP);
03171 
03172   rval = dbl_ILLlib_getbnds (p->lp, lower, upper);
03173   CHECKRVALG (rval, CLEANUP);
03174 
03175 CLEANUP:
03176 
03177   EG_RETURN (rval);
03178 }
03179 
03180 dbl_QSLIB_INTERFACE int dbl_QSget_intflags (
03181   dbl_QSdata * p,
03182   int *intflags)
03183 {
03184   int rval = 0;
03185 
03186   rval = dbl_check_qsdata_pointer (p);
03187   CHECKRVALG (rval, CLEANUP);
03188 
03189   if (intflags == 0)
03190   {
03191     rval = 1;
03192     ILL_CLEANUP;
03193   }
03194 
03195   rval = dbl_ILLlib_getintflags (p->lp, intflags);
03196   CHECKRVALG (rval, CLEANUP);
03197 
03198 CLEANUP:
03199 
03200   EG_RETURN (rval);
03201 }
03202 
03203 dbl_QSLIB_INTERFACE int dbl_QSget_intcount (
03204   dbl_QSdata * p,
03205   int *count)
03206 {
03207   int j, ncols, cnt = 0, rval = 0;
03208   int *intflags = 0;
03209 
03210   *count = 0;
03211 
03212   rval = dbl_check_qsdata_pointer (p);
03213   CHECKRVALG (rval, CLEANUP);
03214 
03215   ncols = dbl_QSget_colcount (p);
03216 
03217   if (ncols > 0)
03218   {
03219     ILL_SAFE_MALLOC (intflags, ncols, int);
03220 
03221     rval = dbl_ILLlib_getintflags (p->lp, intflags);
03222     CHECKRVALG (rval, CLEANUP);
03223 
03224     for (j = 0; j < ncols; j++)
03225     {
03226       if (intflags[j] > 0)
03227         cnt++;
03228     }
03229   }
03230 
03231 CLEANUP:
03232 
03233   *count = cnt;
03234   ILL_IFFREE (intflags, int);
03235 
03236   EG_RETURN (rval);
03237 }
03238 
03239 dbl_QSLIB_INTERFACE int dbl_QSget_column_index (
03240   dbl_QSdata * p,
03241   const char *name,
03242   int *colindex)
03243 {
03244   int rval = 0;
03245 
03246   *colindex = -1;
03247 
03248   rval = dbl_check_qsdata_pointer (p);
03249   CHECKRVALG (rval, CLEANUP);
03250 
03251   rval = dbl_ILLlib_colindex (p->lp, name, colindex);
03252   CHECKRVALG (rval, CLEANUP);
03253 
03254 CLEANUP:
03255 
03256   EG_RETURN (rval);
03257 }
03258 
03259 dbl_QSLIB_INTERFACE int dbl_QSget_row_index (
03260   dbl_QSdata * p,
03261   const char *name,
03262   int *rowindex)
03263 {
03264   int rval = 0;
03265 
03266   *rowindex = -1;
03267 
03268   rval = dbl_check_qsdata_pointer (p);
03269   CHECKRVALG (rval, CLEANUP);
03270 
03271   rval = dbl_ILLlib_rowindex (p->lp, name, rowindex);
03272   CHECKRVALG (rval, CLEANUP);
03273 
03274 CLEANUP:
03275 
03276   EG_RETURN (rval);
03277 }
03278 
03279 static int dbl_QSwrite_prob_EGioFile(
03280     dbl_QSdata*p,
03281     EGioFile_t*out,
03282     const char*filetype)
03283 {
03284     int rval = 0; 
03285     qsstring_reporter rep; 
03286 
03287     ILLstring_reporter_copy(&rep, &p->qslp->reporter); 
03288     ILLstring_reporter_init(&p->qslp->reporter, 
03289                             (qsreport_string_fct) EGioWrite, out); 
03290     rval = dbl_QSreport_prob(p, filetype, NULL);
03291     ILLstring_reporter_copy(&p->qslp->reporter, &rep); 
03292     ILL_RESULT(rval, "dbl_QSwrite_prob_EGioFile");
03293 }
03294 
03295 dbl_QSLIB_INTERFACE int dbl_QSwrite_prob (
03296   dbl_QSdata * p,
03297   const char *filename,
03298   const char *filetype)
03299 {
03300   EGioFile_t *file = NULL;
03301   int rval = 0;
03302 
03303   if (filename == NULL)
03304   {
03305     file = EGioOpenFILE(stdout);
03306   }
03307   else
03308   {
03309     if ((file = EGioOpen (filename, "w")) == 0)
03310     {
03311       perror (filename);
03312       fprintf (stderr, "Unable to open \"%s\" for output.\n", filename);
03313     }
03314   }
03315   ILL_CHECKnull (file, NULL);
03316   rval = dbl_QSwrite_prob_EGioFile (p, file, filetype);
03317   if (file)
03318   {
03319     EGioClose (file);
03320   }
03321 CLEANUP:
03322   EG_RETURN (rval);
03323 }
03324 
03325 dbl_QSLIB_INTERFACE int dbl_QSwrite_prob_file (
03326   dbl_QSdata * p,
03327   FILE * out,
03328   const char *filetype)
03329 {
03330   int rval = 0;
03331   EGioFile_t*lout = EGioOpenFILE(out);
03332   rval = dbl_QSwrite_prob_EGioFile(p,lout,filetype);
03333   CHECKRVALG(rval,CLEANUP);
03334   CLEANUP:
03335   free(lout);
03336   EG_RETURN (rval);
03337 }
03338 
03339 dbl_QSLIB_INTERFACE void dbl_QSfree (
03340   void *ptr)
03341 {
03342   ILL_IFFREE (ptr, void);
03343 }
03344 
03345 dbl_QSLIB_INTERFACE int dbl_QSset_param (
03346   dbl_QSdata * p,
03347   int whichparam,
03348   int newvalue)
03349 {
03350   int rval = 0;
03351 
03352   rval = dbl_check_qsdata_pointer (p);
03353   CHECKRVALG (rval, CLEANUP);
03354 
03355   switch (whichparam)
03356   {
03357   case QS_PARAM_PRIMAL_PRICING:
03358     if (newvalue == QS_PRICE_PDANTZIG ||
03359         newvalue == QS_PRICE_PDEVEX ||
03360         newvalue == QS_PRICE_PSTEEP || newvalue == QS_PRICE_PMULTPARTIAL)
03361     {
03362       p->pricing->pI_price = newvalue;
03363       p->pricing->pII_price = newvalue;
03364     }
03365     else
03366     {
03367       fprintf (stderr, "illegal value for QS_PARAM_PRIMAL_PRICING\n");
03368       rval = 1;
03369       goto CLEANUP;
03370     }
03371     break;
03372   case QS_PARAM_DUAL_PRICING:
03373     if (newvalue == QS_PRICE_DDANTZIG ||
03374         newvalue == QS_PRICE_DSTEEP ||
03375         newvalue == QS_PRICE_DMULTPARTIAL || newvalue == QS_PRICE_DDEVEX)
03376     {
03377       p->pricing->dI_price = newvalue;
03378       p->pricing->dII_price = newvalue;
03379     }
03380     else
03381     {
03382       fprintf (stderr, "illegal value for QS_PARAM_DUAL_PRICING\n");
03383       rval = 1;
03384       goto CLEANUP;
03385     }
03386     break;
03387   case QS_PARAM_SIMPLEX_DISPLAY:
03388     if (newvalue == 0 || (newvalue > 0 && newvalue < 4))
03389     {
03390       p->simplex_display = newvalue;
03391     }
03392     else
03393     {
03394       fprintf (stderr, "illegal value for QS_PARAM_SIMPLEX_DISPLAY\n");
03395       rval = 1;
03396       goto CLEANUP;
03397     }
03398     break;
03399   case QS_PARAM_SIMPLEX_MAX_ITERATIONS:
03400     if (newvalue > 0)
03401     {
03402       p->lp->maxiter = newvalue;
03403     }
03404     else
03405     {
03406       fprintf (stderr, "illegal value for QS_PARAM_SIMPLEX_MAX_ITERATIONS\n");
03407       rval = 1;
03408       goto CLEANUP;
03409     }
03410     break;
03411   case QS_PARAM_SIMPLEX_SCALING:
03412     if (newvalue == 0 || newvalue == 1)
03413     {
03414       p->simplex_scaling = newvalue;
03415     }
03416     else
03417     {
03418       fprintf (stderr, "illegal value for QS_PARAM_SIMPLEX_SCALING\n");
03419       rval = 1;
03420       goto CLEANUP;
03421     }
03422     break;
03423   default:
03424     fprintf (stderr, "unknown parameter: %d\n", whichparam);
03425     rval = 1;
03426     goto CLEANUP;
03427   }
03428 
03429 CLEANUP:
03430 
03431   EG_RETURN (rval);
03432 }
03433 
03434 dbl_QSLIB_INTERFACE int dbl_QSset_param_EGlpNum (
03435   dbl_QSdata * p,
03436   int whichparam,
03437   double newvalue)
03438 {
03439   int rval = 0;
03440   int sense;
03441   double lvar;
03442 
03443   dbl_EGlpNumInitVar(lvar);
03444   dbl_EGlpNumCopy(lvar,newvalue);
03445   rval = dbl_check_qsdata_pointer (p);
03446   CHECKRVALG (rval, CLEANUP);
03447 
03448   switch (whichparam)
03449   {
03450   case QS_PARAM_SIMPLEX_MAX_TIME:
03451     if (dbl_EGlpNumIsGreatZero (lvar))
03452     {
03453       p->lp->maxtime = dbl_EGlpNumToLf (lvar);
03454     }
03455     else
03456     {
03457       fprintf (stderr, "illegal value for QS_PARAM_SIMPLEX_MAX_TIME\n");
03458       rval = 1;
03459       goto CLEANUP;
03460     }
03461     break;
03462   case QS_PARAM_OBJULIM:
03463     dbl_QSget_objsense(p,&sense);
03464     if(dbl_EGlpNumIsLeq(dbl_ILL_MAXDOUBLE,lvar)) dbl_EGlpNumCopy(lvar,dbl_ILL_MAXDOUBLE);
03465     dbl_EGlpNumCopy(p->uobjlim,lvar);
03466     if(sense == QS_MIN) dbl_ILLsimplex_set_bound(p->lp,(const double*)(&lvar), sense);
03467     break;
03468   case QS_PARAM_OBJLLIM:
03469     dbl_QSget_objsense(p,&sense);
03470     if(dbl_EGlpNumIsLeq(newvalue,dbl_ILL_MINDOUBLE)) dbl_EGlpNumCopy(lvar,dbl_ILL_MINDOUBLE);
03471     dbl_EGlpNumCopy(p->lobjlim,lvar);
03472     if(sense == QS_MAX) dbl_ILLsimplex_set_bound(p->lp,(const double*)(&lvar), sense);
03473     break;
03474   default:
03475     fprintf (stderr, "unknown parameter: %d\n", whichparam);
03476     rval = 1;
03477     goto CLEANUP;
03478   }
03479 
03480 CLEANUP:
03481 
03482   dbl_EGlpNumClearVar(lvar);
03483   EG_RETURN (rval);
03484 }
03485 
03486 dbl_QSLIB_INTERFACE int dbl_QSget_param (
03487   dbl_QSdata * p,
03488   int whichparam,
03489   int *value)
03490 {
03491   int rval = 0;
03492 
03493   rval = dbl_check_qsdata_pointer (p);
03494   CHECKRVALG (rval, CLEANUP);
03495 
03496   if (!value)
03497   {
03498     fprintf (stderr, "dbl_QSget_param call without a value pointer\n");
03499     rval = 1;
03500     goto CLEANUP;
03501   }
03502 
03503   switch (whichparam)
03504   {
03505   case QS_PARAM_PRIMAL_PRICING:
03506     *value = p->pricing->pII_price;
03507     break;
03508   case QS_PARAM_DUAL_PRICING:
03509     *value = p->pricing->dII_price;
03510     break;
03511   case QS_PARAM_SIMPLEX_DISPLAY:
03512     *value = p->simplex_display;
03513     break;
03514   case QS_PARAM_SIMPLEX_MAX_ITERATIONS:
03515     *value = p->lp->maxiter;
03516     break;
03517   case QS_PARAM_SIMPLEX_SCALING:
03518     *value = p->simplex_scaling;
03519     break;
03520   default:
03521     fprintf (stderr, "unknown parameter: %d\n", whichparam);
03522     rval = 1;
03523     goto CLEANUP;
03524   }
03525 
03526 CLEANUP:
03527 
03528   EG_RETURN (rval);
03529 }
03530 
03531 dbl_QSLIB_INTERFACE int dbl_QSget_param_EGlpNum (
03532   dbl_QSdata * p,
03533   int whichparam,
03534   double * value)
03535 {
03536   int rval = 0;
03537 
03538   rval = dbl_check_qsdata_pointer (p);
03539   CHECKRVALG (rval, CLEANUP);
03540 
03541   if (!value)
03542   {
03543     fprintf (stderr, "QSget_param_double call without a value pointer\n");
03544     rval = 1;
03545     goto CLEANUP;
03546   }
03547 
03548   switch (whichparam)
03549   {
03550   case QS_PARAM_SIMPLEX_MAX_TIME:
03551     dbl_EGlpNumSet (*value, p->lp->maxtime);
03552     break;
03553   case QS_PARAM_OBJULIM:
03554     dbl_EGlpNumCopy(*value,p->uobjlim);
03555     break;
03556   case QS_PARAM_OBJLLIM:
03557     dbl_EGlpNumCopy(*value,p->lobjlim);
03558     break;
03559   default:
03560     fprintf (stderr, "unknown parameter: %d\n", whichparam);
03561     rval = 1;
03562     goto CLEANUP;
03563   }
03564 
03565 CLEANUP:
03566 
03567   EG_RETURN (rval);
03568 }
03569 
03570 static int dbl_check_qsdata_pointer (
03571   dbl_QSdata * p)
03572 {
03573   if (p == NULL)
03574   {
03575     fprintf (stderr, "NULL dbl_QSprob pointer\n");
03576     return 1;
03577   }
03578   else
03579   {
03580     return 0;
03581   }
03582 }
03583 
03584 static int dbl_formatIsMps (
03585   const char *filetype,
03586   int *isMps)
03587 {
03588   int rval = 0;
03589 
03590   if (!strcasecmp (filetype, "MPS"))
03591   {
03592     *isMps = 1;
03593   }
03594   else if (!strcasecmp (filetype, "LP"))
03595   {
03596     *isMps = 0;
03597   }
03598   else
03599   {
03600     fprintf (stderr, "Unknown prob-file type: %s\n", filetype);
03601     rval = 1;
03602     ILL_CLEANUP;
03603   }
03604 CLEANUP:
03605   return rval;
03606 }
03607 
03608 
03609 /****************************************************************************/
03610 /* 
03611  * undocumentyed functions 
03612  */
03613 
03614 static void dbl_check_pointer (
03615   void *p,
03616   const char *fct,
03617   const char *param)
03618 {
03619   if (p == NULL)
03620     fprintf (stderr, "NULL %s argument to %s\n", param, fct);
03621 }
03622 
03623 /* dbl_QSline_reader: 
03624  *    used by mps/lp reader to get input lines 
03625  *    by default input is read froma FILE* via fgets 
03626  */
03627 dbl_QSLIB_INTERFACE dbl_QSline_reader dbl_QSline_reader_new (
03628   void *fct,
03629   void *data_src)
03630 {
03631   dbl_check_pointer (fct, "dbl_QSline_reader_new", "fct");
03632   dbl_check_pointer (data_src, "dbl_QSline_reader_new", "data_src");
03633   return dbl_ILLline_reader_new ((dbl_qsread_line_fct) fct, data_src);
03634 }
03635 
03636 dbl_QSLIB_INTERFACE void dbl_QSline_reader_set_error_collector (
03637   dbl_QSline_reader reader,
03638   dbl_QSerror_collector collector)
03639 {
03640   dbl_check_pointer (reader, "dbl_QSline_reader_set_error_collector", "reader");
03641   dbl_check_pointer (collector, "dbl_QSline_reader_set_error_collector", "collector");
03642   reader->error_collector = collector;
03643 }
03644 
03645 dbl_QSLIB_INTERFACE void dbl_QSline_reader_free (
03646   dbl_QSline_reader reader)
03647 {
03648   dbl_ILLline_reader_free (reader);
03649 }
03650 
03651 dbl_QSLIB_INTERFACE char *dbl_QSline_reader_get (
03652   dbl_QSline_reader reader,
03653   char *s,
03654   int size)
03655 {
03656   dbl_check_pointer (reader, "dbl_QSline_reader_get", "reader");
03657   dbl_check_pointer (s, "dbl_QSline_reader_get", "s");
03658   return dbl_ILLline_reader_get (s, size, reader);
03659 }
03660 
03661 
03662 dbl_QSLIB_INTERFACE dbl_QSerror_collector dbl_QSerror_collector_new (
03663   void *fct,
03664   void *dest)
03665 {
03666   dbl_check_pointer (fct, "dbl_QSerror_collector_new", "fct");
03667   return dbl_ILLerror_collector_new ((dbl_qsadd_error_fct) fct, dest);
03668 }
03669 
03670 dbl_QSLIB_INTERFACE
03671   dbl_QSerror_collector dbl_QSerror_memory_collector_new (dbl_QSerror_memory mem)
03672 {
03673   dbl_check_pointer (mem, "dbl_QSerror_memory_collector_new", "mem");
03674   return dbl_ILLerror_memory_collector_new (mem);
03675 }
03676 
03677 dbl_QSLIB_INTERFACE void dbl_QSerror_collector_free (
03678   dbl_QSerror_collector c)
03679 {
03680   dbl_ILLerror_collector_free (c);
03681 }
03682 
03683 dbl_QSLIB_INTERFACE dbl_QSdata *dbl_QSget_prob (
03684   dbl_QSline_reader reader,
03685   const char *probname,
03686   const char *filetype)
03687 {
03688   int isMps, rval = 0;
03689   dbl_QSdata *p = 0;
03690 
03691   if ((filetype != NULL) && !strcasecmp (filetype, "MPS"))
03692   {
03693     isMps = 1;
03694   }
03695   else if ((filetype != NULL) && !strcasecmp (filetype, "LP"))
03696   {
03697     isMps = 0;
03698   }
03699   else
03700   {
03701     fprintf (stderr, "Unknown prob-file type: %s\n",
03702              (filetype != NULL) ? filetype : "NULL");
03703     rval = 1;
03704     ILL_CLEANUP;
03705   }
03706 
03707   p = dbl_ILLread (reader, probname, isMps);
03708   ILL_CHECKnull (p, NULL);
03709 
03710   ILL_FAILfalse (p->qslp != NULL, "If there's a p there must be a p-qslp");
03711   ILL_IFFREE (p->name, char);
03712 
03713   dbl_ILL_UTIL_STR (p->name, p->qslp->probname);
03714   dbl_ILLsimplex_load_lpinfo (p->qslp, p->lp);
03715 
03716 CLEANUP:
03717 
03718   if (rval != 0)
03719   {
03720     dbl_QSfree_prob (p);
03721     p = 0;
03722   }
03723   return p;
03724 }
03725 
03726 dbl_QSLIB_INTERFACE int dbl_QSreport_prob (
03727   dbl_QSdata * p,
03728   const char *filetype,
03729   dbl_qserror_collector * c)
03730 {
03731   int isMps, rval = 0;
03732 
03733   rval = dbl_formatIsMps (filetype, &isMps);
03734   CHECKRVALG (rval, CLEANUP);
03735   if (isMps)
03736   {
03737     rval = dbl_ILLwrite_mps (p->qslp, c);
03738   }
03739   else
03740   {
03741     rval = dbl_ILLwrite_lp (p->qslp, c);
03742   }
03743 CLEANUP:
03744   EG_RETURN (rval);
03745 }
03746 
03747 dbl_QSLIB_INTERFACE char *dbl_QSversion (
03748   void)
03749 {
03750   char *name = 0;
03751   name = EGsMalloc (char, 256);
03752 
03753   snprintf (name, (size_t) 255, "%s (build %s-%s)",PACKAGE_STRING, __DATE__,
03754             __TIME__);
03755   return name;
03756 }
03757 
03758 /* QSstring_reporter: 
03759  *    used by solver code to report dbl_feedback 
03760  *    by default dbl_feedback is sent to stdout via fprintf
03761  */
03762 dbl_QSLIB_INTERFACE void dbl_QSset_reporter (
03763   dbl_QSprob prob,
03764   int skip,
03765   void *fct,
03766   void *dest)
03767 {
03768   int rval = 0;
03769 
03770   rval = dbl_check_qsdata_pointer (prob);
03771   if (rval != 0)
03772     return;
03773 
03774   dbl_check_pointer (fct, "dbl_QSset_reporter", "fct");
03775 
03776   ILL_FAILtrue (prob->lp == NULL, "dbl_QSprob internal error: prob->lp == NULL");
03777   ILLstring_reporter_init (&prob->qslp->reporter,
03778                            (qsreport_string_fct) fct, dest);
03779 
03780   prob->lp->iterskip = skip;
03781 CLEANUP:
03782   return;
03783 }
03784 
03785 dbl_QSLIB_INTERFACE const char *dbl_QSformat_error_type_string (
03786   int tp)
03787 {
03788   const char *type = "Error";
03789 
03790   if (tp == QS_DATA_ERROR)
03791   {
03792     type = "Data Error";
03793   }
03794   if (tp == QS_DATA_WARN)
03795   {
03796     type = "Data Warning";
03797   }
03798   if (tp == QS_MPS_FORMAT_ERROR)
03799   {
03800     type = "MPS Error";
03801   }
03802   if (tp == QS_MPS_FORMAT_WARN)
03803   {
03804     type = "MPS Warning";
03805   }
03806   if (tp == QS_LP_FORMAT_ERROR)
03807   {
03808     type = "LP Error";
03809   }
03810   if (tp == QS_LP_FORMAT_WARN)
03811   {
03812     type = "LP Warning";
03813   }
03814   return type;
03815 }
03816 
03817 dbl_QSLIB_INTERFACE int dbl_QSerror_get_type (
03818   dbl_QSformat_error error)
03819 {
03820   dbl_check_pointer (error, "dbl_QSerror_get_type", "error");
03821   return error->type;
03822 }
03823 
03824 dbl_QSLIB_INTERFACE const char *dbl_QSerror_get_desc (
03825   dbl_QSformat_error error)
03826 {
03827   dbl_check_pointer (error, "dbl_QSerror_get_desc", "error");
03828   return error->desc;
03829 }
03830 
03831 dbl_QSLIB_INTERFACE int dbl_QSerror_get_line_number (
03832   dbl_QSformat_error error)
03833 {
03834   dbl_check_pointer (error, "dbl_QSerror_get_line_number", "error");
03835   return error->lineNumber;
03836 }
03837 
03838 dbl_QSLIB_INTERFACE int dbl_QSerror_get_pos (
03839   dbl_QSformat_error error)
03840 {
03841   dbl_check_pointer (error, "dbl_QSerror_get_pos", "error");
03842   return error->at;
03843 }
03844 
03845 dbl_QSLIB_INTERFACE const char *dbl_QSerror_get_line (
03846   dbl_QSformat_error error)
03847 {
03848   dbl_check_pointer (error, "dbl_QSerror_get_line", "error");
03849   return error->theLine;
03850 }
03851 
03852 dbl_QSLIB_INTERFACE void dbl_QSerror_print (
03853   FILE * f,
03854   dbl_QSformat_error error)
03855 {
03856   dbl_check_pointer (f, "dbl_QSerror_print", "f");
03857   if (error == NULL)
03858   {
03859     fprintf (stderr, "0\n");
03860   }
03861   else
03862   {
03863     EGioFile_t*out = EGioOpenFILE(f);
03864     dbl_ILLformat_error_print (out, error);
03865     EGioClose(out);
03866   }
03867 }
03868 
03869 dbl_QSLIB_INTERFACE dbl_QSerror_memory dbl_QSerror_memory_create (
03870   int takeErrorLines)
03871 {
03872   return dbl_ILLerror_memory_create (takeErrorLines);
03873 }
03874 
03875 dbl_QSLIB_INTERFACE void dbl_QSerror_memory_free (
03876   dbl_QSerror_memory mem)
03877 {
03878   if (mem != NULL)
03879   {
03880     dbl_ILLerror_memory_free (mem);
03881   }
03882 }
03883 
03884 dbl_QSLIB_INTERFACE int dbl_QSerror_memory_get_nerrors (
03885   dbl_QSerror_memory mem)
03886 {
03887   dbl_check_pointer (mem, "dbl_QSerror_memory_get_nerrors", "mem");
03888   return mem->nerror;
03889 }
03890 
03891 dbl_QSLIB_INTERFACE int dbl_QSerror_memory_get_nof (
03892   dbl_QSerror_memory mem,
03893   int type)
03894 {
03895   dbl_check_pointer (mem, "dbl_QSerror_memory_get_nerrors", "mem");
03896   if (0 <= type && type < QS_INPUT_NERROR)
03897   {
03898     return mem->has_error[type];
03899   }
03900   else
03901   {
03902     ILL_REPRT ("bad error type");
03903     return 0;
03904   }
03905 }
03906 
03907 dbl_QSLIB_INTERFACE dbl_QSformat_error dbl_QSerror_memory_get_last_error (
03908   dbl_QSerror_memory mem)
03909 {
03910   dbl_check_pointer (mem, "QSerror_memory_get_last_errors", "mem");
03911   return mem->error_list;
03912 }
03913 
03914 dbl_QSLIB_INTERFACE dbl_QSformat_error dbl_QSerror_memory_get_prev_error (
03915   dbl_QSformat_error e)
03916 {
03917   dbl_check_pointer (e, "QSerror_memory_get_prev_errors", "e");
03918   if (e != NULL)
03919     e = e->next;
03920   return e;
03921 }

Generated on Thu Mar 29 09:32:29 2012 for QSopt_ex by  doxygen 1.4.7