dbl_lpdata.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_lpdata.c,v $ $Revision: 1.2 $ $Date: 2003/11/05 16:49:52 $"; */
00024 /****************************************************************************/
00025 /*                                                                          */
00026 /*               Routines for Manipulating and Writing LPdata               */
00027 /*                                                                          */
00028 /*  EXPORTED FUNCTIONS                                                      */
00029 /*                                                                          */
00030 /*    int ILLlpdata_buildrows (dbl_ILLlpdata *lp, int **rowbeg, int **rowcnt,     */
00031 /*            int **rowind, double **rowval, int include_logicals)          */
00032 /*      - include_logicals:  if nonzero, then logical variables will be     */
00033 /*          included in the row data                                        */
00034 /*                                                                          */
00035 /*                                                                          */
00036 /*    All _init routines initialize fields of allocated structure to        */
00037 /*    appropiate default values                                             */
00038 /*    The _free routines free structures contained in pareameter structure  */
00039 /*    but not the parameter itself.                                         */
00040 /*    The _alloc routines check whether given parameter is NULL; they either*/
00041 /*    print an error message or fill structure with default values or the   */
00042 /*    given paremeter values.                                               */
00043 /*                                                                          */
00044 /*    void dbl_ILLlpdata_init (dbl_ILLlpdata *lp)                                   */
00045 /*    void dbl_ILLlpdata_free (dbl_ILLlpdata *lp)                                   */
00046 /*                                                                          */
00047 /*    void dbl_ILLlp_basis_init (dbl_ILLlp_basis *B)                                */
00048 /*    void dbl_ILLlp_basis_free (dbl_ILLlp_basis *B)                                */
00049 /*    int dbl_ILLlp_basis_alloc (dbl_ILLlp_basis *B, int nstruct, int nrows)        */
00050 /*                                                                          */
00051 /*    void dbl_ILLlp_cache_init (dbl_ILLlp_cache *C)                                */
00052 /*    void dbl_ILLlp_cache_free (dbl_ILLlp_cache *C)                                */
00053 /*    int dbl_ILLlp_cache_alloc (dbl_ILLlp_cache *C, int nstruct, int nrows)        */
00054 /*                                                                          */
00055 /*    void dbl_ILLlp_sinfo_init (dbl_ILLlp_sinfo *sinfo)                            */
00056 /*    void dbl_ILLlp_sinfo_free (dbl_ILLlp_sinfo *sinfo)                            */
00057 /*                                                                          */
00058 /*    int dbl_ILLlp_rows_init(dbl_ILLlp_rows *lprows, dbl_ILLlpdata *lp,                */
00059 /*                                           int include_logicals)          */
00060 /*                                                                          */
00061 /****************************************************************************/
00062 
00063 #include "qs_config.h"
00064 #include "dbl_iqsutil.h"
00065 #include "dbl_lpdata.h"
00066 #include "dbl_qstruct.h"
00067 #include "dbl_qsopt.h"
00068 #include "dbl_lp.h"
00069 #include "dbl_mps.h"
00070 #include "dbl_rawlp.h"
00071 #ifdef USEDMALLOC
00072 #include "dmalloc.h"
00073 #endif
00074 
00075 //static int TRACE = 0;
00076 
00077 double dbl_PARAM_IBASIS_RPIVOT;
00078 double dbl_PARAM_IBASIS_RTRIANG;
00079 double dbl_PARAM_MIN_DNORM;
00080 double dbl_PFEAS_TOLER;
00081 double dbl_BD_TOLER;
00082 double dbl_DFEAS_TOLER;
00083 double dbl_PIVOT_TOLER;
00084 double dbl_SZERO_TOLER;
00085 double dbl_PIVZ_TOLER;
00086 double dbl_OBJBND_TOLER;
00087 double dbl_DBNDPIV_TOLER;
00088 double dbl_DBNDPIV_RATIO;
00089 double dbl_ALTPIV_TOLER;
00090 //double DJZERO_TOLER;
00091 double dbl_PROGRESS_ZERO;       /*   1e-7 */
00092 double dbl_PROGRESS_THRESH;     /*   1e-5 */
00093 double dbl_CB_EPS;
00094 double dbl_CB_INF_RATIO;
00095 double dbl_CB_PRI_RLIMIT;
00096 double dbl_ILL_MAXDOUBLE;
00097 double dbl_ILL_MINDOUBLE;
00098 
00099 /* ========================================================================= */
00100 int dbl___QSEX_SETUP = 0;
00101 /* ========================================================================= */
00102 void dbl_ILLstart ( void)
00103 {
00104   if (dbl___QSEX_SETUP)
00105     return;
00106   dbl_EGlpNumInitVar (dbl_PARAM_IBASIS_RPIVOT);
00107   dbl_EGlpNumInitVar (dbl_PARAM_IBASIS_RTRIANG);
00108   dbl_EGlpNumInitVar (dbl_PARAM_MIN_DNORM);
00109   dbl_EGlpNumInitVar (dbl_PFEAS_TOLER);
00110   dbl_EGlpNumInitVar (dbl_BD_TOLER);
00111   dbl_EGlpNumInitVar (dbl_DFEAS_TOLER);
00112   dbl_EGlpNumInitVar (dbl_PIVOT_TOLER);
00113   dbl_EGlpNumInitVar (dbl_SZERO_TOLER);
00114   dbl_EGlpNumInitVar (dbl_PIVZ_TOLER);
00115   dbl_EGlpNumInitVar (dbl_OBJBND_TOLER);
00116   dbl_EGlpNumInitVar (dbl_DBNDPIV_TOLER);
00117   dbl_EGlpNumInitVar (dbl_DBNDPIV_RATIO);
00118   dbl_EGlpNumInitVar (dbl_ALTPIV_TOLER);
00119   //dbl_EGlpNumInitVar (DJZERO_TOLER);
00120   dbl_EGlpNumInitVar (dbl_PROGRESS_ZERO); /*            1e-7 */
00121   dbl_EGlpNumInitVar (dbl_PROGRESS_THRESH); /*          1e-5 */
00122   dbl_EGlpNumInitVar (dbl_CB_PRI_RLIMIT);
00123   dbl_EGlpNumInitVar (dbl_CB_INF_RATIO);
00124   dbl_EGlpNumInitVar (dbl_CB_EPS);
00125   dbl_EGlpNumInitVar (dbl_ILL_MAXDOUBLE);
00126   dbl_EGlpNumInitVar (dbl_ILL_MINDOUBLE);
00127   /* parameters that do depend on the tolerance to zero */
00128   dbl_EGlpNumSet (dbl_PARAM_MIN_DNORM, 4.5036e-9);
00129   dbl_EGlpNumMultTo (dbl_PARAM_MIN_DNORM, dbl_epsLpNum);
00130   dbl_EGlpNumSet (dbl_PFEAS_TOLER, 4.5036e9);
00131   dbl_EGlpNumMultTo (dbl_PFEAS_TOLER, dbl_epsLpNum);
00132   dbl_EGlpNumSet (dbl_BD_TOLER, 4.5036e8);
00133   dbl_EGlpNumMultTo (dbl_BD_TOLER, dbl_epsLpNum);
00134   dbl_EGlpNumSet (dbl_DFEAS_TOLER, 4.5036e9);
00135   dbl_EGlpNumMultTo (dbl_DFEAS_TOLER, dbl_epsLpNum);
00136   dbl_EGlpNumSet (dbl_PIVOT_TOLER, 4.5036e5);
00137   dbl_EGlpNumMultTo (dbl_PIVOT_TOLER, dbl_epsLpNum);
00138   dbl_EGlpNumSet (dbl_SZERO_TOLER, 4.5036);
00139   dbl_EGlpNumMultTo (dbl_SZERO_TOLER, dbl_epsLpNum);
00140   dbl_EGlpNumSet (dbl_PIVZ_TOLER, 4.5036e3);
00141   dbl_EGlpNumMultTo (dbl_PIVZ_TOLER, dbl_epsLpNum);
00142   dbl_EGlpNumSet (dbl_OBJBND_TOLER, 4.5036e13);
00143   dbl_EGlpNumMultTo (dbl_OBJBND_TOLER, dbl_epsLpNum);
00144   dbl_EGlpNumSet (dbl_ALTPIV_TOLER, 4.5036e7);
00145   dbl_EGlpNumMultTo (dbl_ALTPIV_TOLER, dbl_epsLpNum);
00146   dbl_EGlpNumSet (dbl_PROGRESS_ZERO, 4.5036e8);
00147   dbl_EGlpNumMultTo (dbl_PROGRESS_ZERO, dbl_epsLpNum);
00148   dbl_EGlpNumSet (dbl_PROGRESS_THRESH, 4.5036e10);
00149   dbl_EGlpNumMultTo (dbl_PROGRESS_THRESH, dbl_epsLpNum);
00150 #if VERBOSE_LEVEL <= DEBUG
00151   MESSAGE (VERBOSE_LEVEL, "Setting dbl_PARAM_MIN_DNORM to %lg", dbl_EGlpNumToLf (dbl_PARAM_MIN_DNORM));
00152   MESSAGE (VERBOSE_LEVEL, "Setting dbl_PFEAS_TOLER to %lg", dbl_EGlpNumToLf (dbl_PFEAS_TOLER));
00153   MESSAGE (VERBOSE_LEVEL, "Setting dbl_BD_TOLER to %lg", dbl_EGlpNumToLf (dbl_BD_TOLER));
00154   MESSAGE (VERBOSE_LEVEL, "Setting dbl_DFEAS_TOLER to %lg", dbl_EGlpNumToLf (dbl_DFEAS_TOLER));
00155   MESSAGE (VERBOSE_LEVEL, "Setting dbl_PIVOT_TOLER to %lg", dbl_EGlpNumToLf (dbl_PIVOT_TOLER));
00156   MESSAGE (VERBOSE_LEVEL, "Setting dbl_SZERO_TOLER to %lg", dbl_EGlpNumToLf (dbl_SZERO_TOLER));
00157   MESSAGE (VERBOSE_LEVEL, "Setting dbl_PIVZ_TOLER to %lg", dbl_EGlpNumToLf (dbl_PIVZ_TOLER));
00158   MESSAGE (VERBOSE_LEVEL, "Setting dbl_OBJBND_TOLER to %lg", dbl_EGlpNumToLf (dbl_OBJBND_TOLER));
00159   MESSAGE (VERBOSE_LEVEL, "Setting dbl_ALTPIV_TOLER to %lg", dbl_EGlpNumToLf (dbl_ALTPIV_TOLER));
00160   MESSAGE (VERBOSE_LEVEL, "Setting dbl_PROGRESS_ZERO to %lg", dbl_EGlpNumToLf (dbl_PROGRESS_ZERO));
00161   MESSAGE (VERBOSE_LEVEL, "Setting dbl_PROGRESS_THRESH to %lg", dbl_EGlpNumToLf (dbl_PROGRESS_THRESH));
00162 #endif
00163   /* parameters that do not depend on the tolerance to zero */
00164   dbl_EGlpNumSet (dbl_ILL_MAXDOUBLE, 1e150);
00165   dbl_EGlpNumSet (dbl_ILL_MINDOUBLE, -1e150);
00166   dbl_EGlpNumSet (dbl_PARAM_IBASIS_RPIVOT, 0.98);
00167   dbl_EGlpNumSet (dbl_PARAM_IBASIS_RTRIANG, 0.01);
00168   dbl_EGlpNumSet (dbl_DBNDPIV_TOLER, 1e-3);
00169   dbl_EGlpNumSet (dbl_DBNDPIV_RATIO, 1e-2);
00170   //dbl_EGlpNumSet (DJZERO_TOLER, 1e-8);
00171   dbl_EGlpNumSet (dbl_CB_EPS, 0.001);
00172   dbl_EGlpNumSet (dbl_CB_INF_RATIO, 10.0);
00173   dbl_EGlpNumSet (dbl_CB_PRI_RLIMIT, 0.25);
00174   dbl___QSEX_SETUP = 1;
00175 }
00176 
00177 /* ========================================================================= */
00178 void dbl_ILLchange_precision (
00179   void)
00180 {
00181   dbl_EGlpNumClearVar (dbl_PFEAS_TOLER);
00182   dbl_EGlpNumClearVar (dbl_BD_TOLER);
00183   dbl_EGlpNumClearVar (dbl_DFEAS_TOLER);
00184   dbl_EGlpNumClearVar (dbl_PIVOT_TOLER);
00185   dbl_EGlpNumClearVar (dbl_SZERO_TOLER);
00186   dbl_EGlpNumClearVar (dbl_PIVZ_TOLER);
00187   dbl_EGlpNumClearVar (dbl_OBJBND_TOLER);
00188   dbl_EGlpNumClearVar (dbl_ALTPIV_TOLER);
00189   dbl_EGlpNumClearVar (dbl_PARAM_MIN_DNORM);
00190   dbl_EGlpNumClearVar (dbl_PROGRESS_ZERO);
00191   dbl_EGlpNumClearVar (dbl_PROGRESS_THRESH);
00192   dbl_EGlpNumInitVar (dbl_PROGRESS_ZERO);
00193   dbl_EGlpNumInitVar (dbl_PROGRESS_THRESH);
00194   dbl_EGlpNumInitVar (dbl_PFEAS_TOLER);
00195   dbl_EGlpNumInitVar (dbl_BD_TOLER);
00196   dbl_EGlpNumInitVar (dbl_DFEAS_TOLER);
00197   dbl_EGlpNumInitVar (dbl_PIVOT_TOLER);
00198   dbl_EGlpNumInitVar (dbl_SZERO_TOLER);
00199   dbl_EGlpNumInitVar (dbl_PIVZ_TOLER);
00200   dbl_EGlpNumInitVar (dbl_OBJBND_TOLER);
00201   dbl_EGlpNumInitVar (dbl_ALTPIV_TOLER);
00202   dbl_EGlpNumInitVar (dbl_PARAM_MIN_DNORM);
00203   /* parameters that do depend on the tolerance to zero */
00204   dbl_EGlpNumSet (dbl_PARAM_MIN_DNORM, 4.5036e-9);
00205   dbl_EGlpNumMultTo (dbl_PARAM_MIN_DNORM, dbl_epsLpNum);
00206   dbl_EGlpNumSet (dbl_PFEAS_TOLER, 4.5036e9);
00207   dbl_EGlpNumMultTo (dbl_PFEAS_TOLER, dbl_epsLpNum);
00208   dbl_EGlpNumSet (dbl_BD_TOLER, 4.5036e8);
00209   dbl_EGlpNumMultTo (dbl_BD_TOLER, dbl_epsLpNum);
00210   dbl_EGlpNumSet (dbl_DFEAS_TOLER, 4.5036e9);
00211   dbl_EGlpNumMultTo (dbl_DFEAS_TOLER, dbl_epsLpNum);
00212   dbl_EGlpNumSet (dbl_PIVOT_TOLER, 4.5036e5);
00213   dbl_EGlpNumMultTo (dbl_PIVOT_TOLER, dbl_epsLpNum);
00214   dbl_EGlpNumSet (dbl_SZERO_TOLER, 4.5036);
00215   dbl_EGlpNumMultTo (dbl_SZERO_TOLER, dbl_epsLpNum);
00216   dbl_EGlpNumSet (dbl_PIVZ_TOLER, 4.5036e3);
00217   dbl_EGlpNumMultTo (dbl_PIVZ_TOLER, dbl_epsLpNum);
00218   dbl_EGlpNumSet (dbl_OBJBND_TOLER, 4.5036e13);
00219   dbl_EGlpNumMultTo (dbl_OBJBND_TOLER, dbl_epsLpNum);
00220   dbl_EGlpNumSet (dbl_ALTPIV_TOLER, 4.5036e7);
00221   dbl_EGlpNumMultTo (dbl_ALTPIV_TOLER, dbl_epsLpNum);
00222   dbl_EGlpNumSet (dbl_PROGRESS_ZERO, 4.5036e8);
00223   dbl_EGlpNumMultTo (dbl_PROGRESS_ZERO, dbl_epsLpNum);
00224   dbl_EGlpNumSet (dbl_PROGRESS_THRESH, 4.5036e10);
00225   dbl_EGlpNumMultTo (dbl_PROGRESS_THRESH, dbl_epsLpNum);
00226 }
00227 
00228 /* ========================================================================= */
00229 void dbl_ILLend ( void)
00230 {
00231   if (!dbl___QSEX_SETUP)
00232     return;
00233   dbl_EGlpNumClearVar (dbl_PARAM_IBASIS_RPIVOT);
00234   dbl_EGlpNumClearVar (dbl_PARAM_IBASIS_RTRIANG);
00235   dbl_EGlpNumClearVar (dbl_PARAM_MIN_DNORM);
00236   dbl_EGlpNumClearVar (dbl_PFEAS_TOLER);
00237   dbl_EGlpNumClearVar (dbl_BD_TOLER);
00238   dbl_EGlpNumClearVar (dbl_DFEAS_TOLER);
00239   dbl_EGlpNumClearVar (dbl_PIVOT_TOLER);
00240   dbl_EGlpNumClearVar (dbl_SZERO_TOLER);
00241   dbl_EGlpNumClearVar (dbl_PIVZ_TOLER);
00242   dbl_EGlpNumClearVar (dbl_OBJBND_TOLER);
00243   dbl_EGlpNumClearVar (dbl_DBNDPIV_TOLER);
00244   dbl_EGlpNumClearVar (dbl_DBNDPIV_RATIO);
00245   dbl_EGlpNumClearVar (dbl_ALTPIV_TOLER);
00246   //dbl_EGlpNumClearVar (DJZERO_TOLER);
00247   dbl_EGlpNumClearVar (dbl_PROGRESS_ZERO);  /*            1e-7 */
00248   dbl_EGlpNumClearVar (dbl_PROGRESS_THRESH);  /*          1e-5 */
00249   dbl_EGlpNumClearVar (dbl_CB_EPS);
00250   dbl_EGlpNumClearVar (dbl_CB_INF_RATIO);
00251   dbl_EGlpNumClearVar (dbl_CB_PRI_RLIMIT);
00252   dbl_EGlpNumClearVar (dbl_ILL_MAXDOUBLE);
00253   dbl_EGlpNumClearVar (dbl_ILL_MINDOUBLE);
00254   dbl___QSEX_SETUP = 0;
00255 }
00256 
00257 dbl_QSdata *dbl_ILLread (
00258   dbl_qsline_reader * file,
00259   const char *dbl_fname,
00260   int isMps)
00261 {
00262   int rval = 0;
00263   dbl_QSdata *p = 0;
00264   dbl_ILLlpdata *lp;
00265   dbl_rawlpdata rawlp;
00266 
00267   ILL_FAILfalse (file != NULL, NULL);
00268   ILL_FAILfalse (dbl_fname != NULL, NULL);
00269 
00270   p = dbl_QScreate_prob (dbl_fname, QS_MIN);
00271   ILL_CHECKnull (p, NULL);
00272   ILL_IFFREE (p->qslp->probname, char);
00273 
00274   lp = p->qslp;
00275 
00276   dbl_ILLinit_rawlpdata (&rawlp, file->error_collector);
00277   dbl_ILLlpdata_init (lp);
00278 
00279   if (isMps != 0)
00280   {
00281     rval = dbl_ILLread_mps (file, dbl_fname, &rawlp);
00282   }
00283   else
00284   {
00285     rval = dbl_ILLread_lp (file, dbl_fname, &rawlp);
00286   }
00287   CHECKRVALG (rval, CLEANUP);
00288 
00289   rval = dbl_ILLrawlpdata_to_lpdata (&rawlp, lp);
00290   CHECKRVALG (rval, CLEANUP);
00291 
00292 CLEANUP:
00293   dbl_ILLfree_rawlpdata (&rawlp);
00294   if (rval != 0)
00295   {
00296     dbl_QSfree_prob (p);
00297     p = 0;
00298   }
00299   return p;
00300 }
00301 
00302 void dbl_ILLlpdata_init (
00303   dbl_ILLlpdata * lp)
00304 {
00305   if (lp)
00306   {
00307     lp->nrows = 0;
00308     lp->ncols = 0;
00309     lp->nstruct = 0;
00310     lp->nzcount = 0;
00311     lp->rowsize = 0;
00312     lp->colsize = 0;
00313     lp->structsize = 0;
00314     lp->objsense = dbl_ILL_MIN;
00315     lp->sense = 0;
00316     lp->obj = 0;
00317     lp->rhs = 0;
00318     lp->rangeval = 0;
00319     lp->lower = 0;
00320     lp->upper = 0;
00321 
00322     dbl_ILLmatrix_init (&lp->A);
00323     dbl_ILLmatrix_init (&lp->sos);
00324     lp->rA = 0;
00325     lp->is_sos_mem = NULL;
00326     lp->refrowname = NULL;
00327     lp->refind = -1;
00328 
00329     lp->colnames = 0;
00330     ILLsymboltab_init (&lp->coltab);
00331     lp->rownames = 0;
00332     ILLsymboltab_init (&lp->rowtab);
00333     lp->objname = 0;
00334 
00335     lp->probname = 0;
00336     lp->intmarker = 0;
00337     lp->structmap = 0;
00338     lp->rowmap = 0;
00339     lp->basis = 0;
00340     /*lp->presolve   = 0; */
00341     lp->sinfo = 0;
00342 
00343     ILLstring_reporter_init (&lp->reporter, ILL_fprintf, stdout);
00344   }
00345 }
00346 
00347 void dbl_ILLlpdata_free (
00348   dbl_ILLlpdata * lp)
00349 {
00350   int i;
00351 
00352   if (lp)
00353   {
00354     ILL_IFFREE (lp->sense, char);
00355 
00356     dbl_EGlpNumFreeArray (lp->obj);
00357     dbl_EGlpNumFreeArray (lp->rhs);
00358     dbl_EGlpNumFreeArray (lp->rangeval);
00359     dbl_EGlpNumFreeArray (lp->lower);
00360     dbl_EGlpNumFreeArray (lp->upper);
00361     dbl_ILLmatrix_free (&lp->A);
00362     if (lp->rA)
00363     {
00364       dbl_ILLlp_rows_clear (lp->rA);
00365       ILL_IFFREE (lp->rA, dbl_ILLlp_rows);
00366     }
00367     ILL_IFFREE (lp->is_sos_mem, int);
00368     ILL_IFFREE (lp->refrowname, char);
00369 
00370     dbl_ILLmatrix_free (&lp->sos);
00371     if (lp->colnames)
00372     {
00373       for (i = 0; i < lp->nstruct; i++)
00374       {
00375         ILL_IFFREE (lp->colnames[i], char);
00376       }
00377       ILL_IFFREE (lp->colnames, char *);
00378     }
00379     ILLsymboltab_free (&lp->coltab);
00380     if (lp->rownames)
00381     {
00382       for (i = 0; i < lp->nrows; i++)
00383       {
00384         ILL_IFFREE (lp->rownames[i], char);
00385       }
00386       ILL_IFFREE (lp->rownames, char *);
00387     }
00388     ILLsymboltab_free (&lp->rowtab);
00389     ILL_IFFREE (lp->objname, char);
00390     ILL_IFFREE (lp->probname, char);
00391     ILL_IFFREE (lp->intmarker, char);
00392     ILL_IFFREE (lp->structmap, int);
00393     ILL_IFFREE (lp->rowmap, int);
00394 
00395     if (lp->sinfo)
00396     {
00397       dbl_ILLlp_sinfo_free (lp->sinfo);
00398       ILL_IFFREE (lp->sinfo, dbl_ILLlp_sinfo);
00399     }
00400     dbl_ILLlpdata_init (lp);
00401   }
00402 }
00403 
00404 void dbl_ILLlp_basis_init (
00405   dbl_ILLlp_basis * B)
00406 {
00407   if (B)
00408   {
00409     B->cstat = 0;
00410     B->rstat = 0;
00411     B->rownorms = 0;
00412     B->colnorms = 0;
00413     B->nstruct = 0;
00414     B->nrows = 0;
00415   }
00416 }
00417 
00418 void dbl_ILLlp_basis_free (
00419   dbl_ILLlp_basis * B)
00420 {
00421   if (B)
00422   {
00423     ILL_IFFREE (B->cstat, char);
00424     ILL_IFFREE (B->rstat, char);
00425 
00426     dbl_EGlpNumFreeArray (B->rownorms);
00427     dbl_EGlpNumFreeArray (B->colnorms);
00428     B->nstruct = 0;
00429     B->nrows = 0;
00430   }
00431 }
00432 
00433 int dbl_ILLlp_basis_alloc (
00434   dbl_ILLlp_basis * B,
00435   int nstruct,
00436   int nrows)
00437 {
00438   int rval = 0;
00439 
00440   ILL_FAILtrue (B == NULL, "dbl_ILLlp_basis_alloc called without a basis");
00441 
00442   B->nstruct = nstruct;
00443   B->nrows = nrows;
00444 
00445   if (nstruct > 0)
00446   {
00447     ILL_SAFE_MALLOC (B->cstat, nstruct, char);
00448   }
00449 
00450   if (nrows > 0)
00451   {
00452     ILL_SAFE_MALLOC (B->rstat, nrows, char);
00453   }
00454 
00455 CLEANUP:
00456 
00457   if (rval)
00458   {
00459     dbl_ILLlp_basis_free (B);
00460   }
00461 
00462   EG_RETURN (rval);
00463 }
00464 
00465 void dbl_ILLlp_cache_init (
00466   dbl_ILLlp_cache * C)
00467 {
00468   if (C)
00469   {
00470     C->x = 0;
00471     C->rc = 0;
00472     C->pi = 0;
00473     C->slack = 0;
00474     C->nstruct = 0;
00475     C->nrows = 0;
00476     C->status = 0;
00477     dbl_EGlpNumZero (C->val);
00478   }
00479 }
00480 
00481 void dbl_ILLlp_cache_free (
00482   dbl_ILLlp_cache * C)
00483 {
00484   if (C)
00485   {
00486     dbl_EGlpNumFreeArray (C->x);
00487     dbl_EGlpNumFreeArray (C->rc);
00488     dbl_EGlpNumFreeArray (C->pi);
00489     dbl_EGlpNumFreeArray (C->slack);
00490     C->nstruct = 0;
00491     C->nrows = 0;
00492     C->status = 0;
00493   }
00494 }
00495 
00496 int dbl_ILLlp_cache_alloc (
00497   dbl_ILLlp_cache * C,
00498   int nstruct,
00499   int nrows)
00500 {
00501   int rval = 0;
00502 
00503   ILL_FAILtrue (C == NULL, "dbl_ILLlp_cache_alloc called without a cache");
00504 
00505   C->nstruct = nstruct;
00506   C->nrows = nrows;
00507 
00508   if (nstruct > 0)
00509   {
00510     C->x = dbl_EGlpNumAllocArray (nstruct);
00511     C->rc = dbl_EGlpNumAllocArray (nstruct);
00512   }
00513 
00514   if (nrows > 0)
00515   {
00516     C->pi = dbl_EGlpNumAllocArray (nrows);
00517     C->slack = dbl_EGlpNumAllocArray (nrows);
00518   }
00519 
00520 CLEANUP:
00521 
00522   if (rval)
00523   {
00524     dbl_ILLlp_cache_free (C);
00525   }
00526 
00527   EG_RETURN (rval);
00528 }
00529 
00530 
00531 int dbl_ILLlp_rows_init (
00532   dbl_ILLlp_rows * lprows,
00533   dbl_ILLlpdata * lp,
00534   int include_logicals)
00535 {
00536   int rval = 0;
00537   int i, k, st;
00538   int *beg, *cnt, *ind;
00539   double *val;
00540   dbl_ILLmatrix *A;
00541   char *hit = 0;
00542   int *inv_structmap = 0;
00543 
00544   /* If logicals are not included, then the columns are ordered as in */
00545   /* lp->structmap.  Otherwise, the columns are ordered as in the     */
00546   /* matrix structure.                                                */
00547 
00548   if (lprows != NULL)
00549   {
00550     lprows->rowbeg = 0;
00551     lprows->rowcnt = 0;
00552     lprows->rowind = 0;
00553     lprows->rowval = 0;
00554   }
00555 
00556   ILL_FAILfalse ((lp != NULL) && (lprows != NULL),
00557                  "called with a NULL pointer");
00558 
00559   A = &lp->A;
00560 
00561   if (lp->nrows > 0)
00562   {
00563     if (include_logicals == 0)
00564     {
00565       ILL_FAILtrue (lp->rowmap == NULL, "Programming error.");
00566       ILL_SAFE_MALLOC (hit, lp->ncols, char);
00567 
00568       for (i = 0; i < lp->ncols; i++)
00569       {
00570         hit[i] = 0;
00571       }
00572       for (i = 0; i < lp->nrows; i++)
00573       {
00574         hit[lp->rowmap[i]] = 1;
00575       }
00576 
00577       ILL_SAFE_MALLOC (inv_structmap, lp->ncols, int);
00578 
00579       for (i = 0; i < lp->nstruct; i++)
00580       {
00581         inv_structmap[lp->structmap[i]] = i;
00582       }
00583     }
00584 
00585     ILL_SAFE_MALLOC (lprows->rowbeg, lp->nrows, int);
00586     ILL_SAFE_MALLOC (lprows->rowcnt, lp->nrows, int);
00587 
00588     if (((include_logicals != 0) && lp->nzcount > 0) ||
00589         ((include_logicals == 0) && lp->nzcount > lp->nrows))
00590     {
00591       if (include_logicals != 0)
00592       {
00593         ILL_SAFE_MALLOC (lprows->rowind, lp->nzcount, int);
00594 
00595         lprows->rowval = dbl_EGlpNumAllocArray (lp->nzcount);
00596       }
00597       else
00598       {
00599         ILL_SAFE_MALLOC (lprows->rowind, lp->nzcount - lp->nrows, int);
00600 
00601         lprows->rowval = dbl_EGlpNumAllocArray (lp->nzcount - lp->nrows);
00602       }
00603     }
00604 
00605     beg = lprows->rowbeg;
00606     cnt = lprows->rowcnt;
00607     ind = lprows->rowind;
00608     val = lprows->rowval;
00609 
00610     for (i = 0; i < lp->nrows; i++)
00611     {
00612       cnt[i] = 0;
00613     }
00614 
00615     for (i = 0; i < lp->ncols; i++)
00616     {
00617       if ((include_logicals != 0) || hit[i] == 0)
00618       {
00619         k = A->matbeg[i];
00620         st = k + A->matcnt[i];
00621         for (; k < st; k++)
00622         {
00623           cnt[A->matind[k]]++;
00624         }
00625       }
00626     }
00627 
00628     for (i = 0, k = 0; i < lp->nrows; i++)
00629     {
00630       beg[i] = k;
00631       k += cnt[i];
00632     }
00633 
00634     for (i = 0; i < lp->ncols; i++)
00635     {
00636       if ((include_logicals != 0) || hit[i] == 0)
00637       {
00638         k = A->matbeg[i];
00639         st = k + A->matcnt[i];
00640         for (; k < st; k++)
00641         {
00642           if (include_logicals != 0)
00643           {
00644             ind[beg[A->matind[k]]] = i;
00645           }
00646           else
00647           {
00648             ind[beg[A->matind[k]]] = inv_structmap[i];
00649           }
00650           dbl_EGlpNumCopy (val[beg[A->matind[k]]], A->matval[k]);
00651           beg[A->matind[k]]++;
00652         }
00653       }
00654     }
00655 
00656     for (i = 0, k = 0; i < lp->nrows; i++)
00657     {
00658       beg[i] = k;
00659       k += cnt[i];
00660     }
00661   }
00662 CLEANUP:
00663 
00664   if (rval)
00665   {
00666     dbl_ILLlp_rows_clear (lprows);
00667   }
00668   ILL_IFFREE (hit, char);
00669   ILL_IFFREE (inv_structmap, int);
00670 
00671   EG_RETURN (rval);
00672 }
00673 
00674 void dbl_ILLlp_rows_clear (
00675   dbl_ILLlp_rows * lprows)
00676 {
00677   if (lprows != NULL)
00678   {
00679     ILL_IFFREE (lprows->rowbeg, int);
00680     ILL_IFFREE (lprows->rowcnt, int);
00681     ILL_IFFREE (lprows->rowind, int);
00682 
00683     dbl_EGlpNumFreeArray (lprows->rowval);
00684   }
00685 }
00686 
00687 static int dbl_wr_line (
00688   dbl_ILLlpdata * lp,
00689   const char *format,
00690   va_list argptr)
00691 {
00692   char buffer[ILL_namebufsize];
00693   int rval = 0;
00694 
00695   rval = vsprintf (buffer, format, argptr);
00696   if (rval > 0)
00697   {
00698                 /* Bico -- OPTERON DEBUGGING 051005  */
00699                 /* Replaced ILLstring_report by the explicit call to */
00700                 /* fprintf.                                          */
00701                 /*rval = fprintf (lp->reporter.dest, buffer);
00702                 if (rval < 0) rval = 1;
00703                 else          rval = 0;
00704                 */
00705     /* daespino -- BACK to ILLstring_report to support compresed files 090909
00706      * */
00707     rval = ILLstring_report(buffer, &lp->reporter);
00708   }
00709   return rval;
00710 }
00711 
00712 int dbl_ILLprint_report (
00713   dbl_ILLlpdata * lp,
00714   const char *format,
00715   ...)
00716 {
00717   va_list marker;
00718   int rval = 0;
00719 
00720   va_start (marker, format);    /* ANSI style */
00721   rval = dbl_wr_line (lp, format, marker);
00722   va_end (marker);              /* Reset variable arguments.      */
00723   return rval;
00724 }

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