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: 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 (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 ILLlpdata_init (ILLlpdata *lp)                                   */
00045 /*    void ILLlpdata_free (ILLlpdata *lp)                                   */
00046 /*                                                                          */
00047 /*    void ILLlp_basis_init (ILLlp_basis *B)                                */
00048 /*    void ILLlp_basis_free (ILLlp_basis *B)                                */
00049 /*    int ILLlp_basis_alloc (ILLlp_basis *B, int nstruct, int nrows)        */
00050 /*                                                                          */
00051 /*    void ILLlp_cache_init (ILLlp_cache *C)                                */
00052 /*    void ILLlp_cache_free (ILLlp_cache *C)                                */
00053 /*    int ILLlp_cache_alloc (ILLlp_cache *C, int nstruct, int nrows)        */
00054 /*                                                                          */
00055 /*    void ILLlp_sinfo_init (ILLlp_sinfo *sinfo)                            */
00056 /*    void ILLlp_sinfo_free (ILLlp_sinfo *sinfo)                            */
00057 /*                                                                          */
00058 /*    int ILLlp_rows_init(ILLlp_rows *lprows, ILLlpdata *lp,                */
00059 /*                                           int include_logicals)          */
00060 /*                                                                          */
00061 /****************************************************************************/
00062 
00063 #include "qs_config.h"
00064 #include "iqsutil.h"
00065 #include "lpdata.h"
00066 #include "qstruct.h"
00067 #include "qsopt.h"
00068 #include "lp.h"
00069 #include "mps.h"
00070 #include "rawlp.h"
00071 #ifdef USEDMALLOC
00072 #include "dmalloc.h"
00073 #endif
00074 
00075 //static int TRACE = 0;
00076 
00077 EGlpNum_t PARAM_IBASIS_RPIVOT;
00078 EGlpNum_t PARAM_IBASIS_RTRIANG;
00079 EGlpNum_t PARAM_MIN_DNORM;
00080 EGlpNum_t PFEAS_TOLER;
00081 EGlpNum_t BD_TOLER;
00082 EGlpNum_t DFEAS_TOLER;
00083 EGlpNum_t PIVOT_TOLER;
00084 EGlpNum_t SZERO_TOLER;
00085 EGlpNum_t PIVZ_TOLER;
00086 EGlpNum_t OBJBND_TOLER;
00087 EGlpNum_t DBNDPIV_TOLER;
00088 EGlpNum_t DBNDPIV_RATIO;
00089 EGlpNum_t ALTPIV_TOLER;
00090 //EGlpNum_t DJZERO_TOLER;
00091 EGlpNum_t PROGRESS_ZERO;        /*   1e-7 */
00092 EGlpNum_t PROGRESS_THRESH;      /*   1e-5 */
00093 EGlpNum_t CB_EPS;
00094 EGlpNum_t CB_INF_RATIO;
00095 EGlpNum_t CB_PRI_RLIMIT;
00096 EGlpNum_t ILL_MAXDOUBLE;
00097 EGlpNum_t ILL_MINDOUBLE;
00098 
00099 /* ========================================================================= */
00100 int __QSEX_SETUP = 0;
00101 /* ========================================================================= */
00102 void ILLstart ( void)
00103 {
00104   if (__QSEX_SETUP)
00105     return;
00106   EGlpNumInitVar (PARAM_IBASIS_RPIVOT);
00107   EGlpNumInitVar (PARAM_IBASIS_RTRIANG);
00108   EGlpNumInitVar (PARAM_MIN_DNORM);
00109   EGlpNumInitVar (PFEAS_TOLER);
00110   EGlpNumInitVar (BD_TOLER);
00111   EGlpNumInitVar (DFEAS_TOLER);
00112   EGlpNumInitVar (PIVOT_TOLER);
00113   EGlpNumInitVar (SZERO_TOLER);
00114   EGlpNumInitVar (PIVZ_TOLER);
00115   EGlpNumInitVar (OBJBND_TOLER);
00116   EGlpNumInitVar (DBNDPIV_TOLER);
00117   EGlpNumInitVar (DBNDPIV_RATIO);
00118   EGlpNumInitVar (ALTPIV_TOLER);
00119   //EGlpNumInitVar (DJZERO_TOLER);
00120   EGlpNumInitVar (PROGRESS_ZERO); /*            1e-7 */
00121   EGlpNumInitVar (PROGRESS_THRESH); /*          1e-5 */
00122   EGlpNumInitVar (CB_PRI_RLIMIT);
00123   EGlpNumInitVar (CB_INF_RATIO);
00124   EGlpNumInitVar (CB_EPS);
00125   EGlpNumInitVar (ILL_MAXDOUBLE);
00126   EGlpNumInitVar (ILL_MINDOUBLE);
00127   /* parameters that do depend on the tolerance to zero */
00128   EGlpNumSet (PARAM_MIN_DNORM, 4.5036e-9);
00129   EGlpNumMultTo (PARAM_MIN_DNORM, epsLpNum);
00130   EGlpNumSet (PFEAS_TOLER, 4.5036e9);
00131   EGlpNumMultTo (PFEAS_TOLER, epsLpNum);
00132   EGlpNumSet (BD_TOLER, 4.5036e8);
00133   EGlpNumMultTo (BD_TOLER, epsLpNum);
00134   EGlpNumSet (DFEAS_TOLER, 4.5036e9);
00135   EGlpNumMultTo (DFEAS_TOLER, epsLpNum);
00136   EGlpNumSet (PIVOT_TOLER, 4.5036e5);
00137   EGlpNumMultTo (PIVOT_TOLER, epsLpNum);
00138   EGlpNumSet (SZERO_TOLER, 4.5036);
00139   EGlpNumMultTo (SZERO_TOLER, epsLpNum);
00140   EGlpNumSet (PIVZ_TOLER, 4.5036e3);
00141   EGlpNumMultTo (PIVZ_TOLER, epsLpNum);
00142   EGlpNumSet (OBJBND_TOLER, 4.5036e13);
00143   EGlpNumMultTo (OBJBND_TOLER, epsLpNum);
00144   EGlpNumSet (ALTPIV_TOLER, 4.5036e7);
00145   EGlpNumMultTo (ALTPIV_TOLER, epsLpNum);
00146   EGlpNumSet (PROGRESS_ZERO, 4.5036e8);
00147   EGlpNumMultTo (PROGRESS_ZERO, epsLpNum);
00148   EGlpNumSet (PROGRESS_THRESH, 4.5036e10);
00149   EGlpNumMultTo (PROGRESS_THRESH, epsLpNum);
00150 #if VERBOSE_LEVEL <= DEBUG
00151   MESSAGE (VERBOSE_LEVEL, "Setting PARAM_MIN_DNORM to %lg", EGlpNumToLf (PARAM_MIN_DNORM));
00152   MESSAGE (VERBOSE_LEVEL, "Setting PFEAS_TOLER to %lg", EGlpNumToLf (PFEAS_TOLER));
00153   MESSAGE (VERBOSE_LEVEL, "Setting BD_TOLER to %lg", EGlpNumToLf (BD_TOLER));
00154   MESSAGE (VERBOSE_LEVEL, "Setting DFEAS_TOLER to %lg", EGlpNumToLf (DFEAS_TOLER));
00155   MESSAGE (VERBOSE_LEVEL, "Setting PIVOT_TOLER to %lg", EGlpNumToLf (PIVOT_TOLER));
00156   MESSAGE (VERBOSE_LEVEL, "Setting SZERO_TOLER to %lg", EGlpNumToLf (SZERO_TOLER));
00157   MESSAGE (VERBOSE_LEVEL, "Setting PIVZ_TOLER to %lg", EGlpNumToLf (PIVZ_TOLER));
00158   MESSAGE (VERBOSE_LEVEL, "Setting OBJBND_TOLER to %lg", EGlpNumToLf (OBJBND_TOLER));
00159   MESSAGE (VERBOSE_LEVEL, "Setting ALTPIV_TOLER to %lg", EGlpNumToLf (ALTPIV_TOLER));
00160   MESSAGE (VERBOSE_LEVEL, "Setting PROGRESS_ZERO to %lg", EGlpNumToLf (PROGRESS_ZERO));
00161   MESSAGE (VERBOSE_LEVEL, "Setting PROGRESS_THRESH to %lg", EGlpNumToLf (PROGRESS_THRESH));
00162 #endif
00163   /* parameters that do not depend on the tolerance to zero */
00164   EGlpNumSet (ILL_MAXDOUBLE, 1e150);
00165   EGlpNumSet (ILL_MINDOUBLE, -1e150);
00166   EGlpNumSet (PARAM_IBASIS_RPIVOT, 0.98);
00167   EGlpNumSet (PARAM_IBASIS_RTRIANG, 0.01);
00168   EGlpNumSet (DBNDPIV_TOLER, 1e-3);
00169   EGlpNumSet (DBNDPIV_RATIO, 1e-2);
00170   //EGlpNumSet (DJZERO_TOLER, 1e-8);
00171   EGlpNumSet (CB_EPS, 0.001);
00172   EGlpNumSet (CB_INF_RATIO, 10.0);
00173   EGlpNumSet (CB_PRI_RLIMIT, 0.25);
00174   __QSEX_SETUP = 1;
00175 }
00176 
00177 /* ========================================================================= */
00178 void ILLchange_precision (
00179   void)
00180 {
00181   EGlpNumClearVar (PFEAS_TOLER);
00182   EGlpNumClearVar (BD_TOLER);
00183   EGlpNumClearVar (DFEAS_TOLER);
00184   EGlpNumClearVar (PIVOT_TOLER);
00185   EGlpNumClearVar (SZERO_TOLER);
00186   EGlpNumClearVar (PIVZ_TOLER);
00187   EGlpNumClearVar (OBJBND_TOLER);
00188   EGlpNumClearVar (ALTPIV_TOLER);
00189   EGlpNumClearVar (PARAM_MIN_DNORM);
00190   EGlpNumClearVar (PROGRESS_ZERO);
00191   EGlpNumClearVar (PROGRESS_THRESH);
00192   EGlpNumInitVar (PROGRESS_ZERO);
00193   EGlpNumInitVar (PROGRESS_THRESH);
00194   EGlpNumInitVar (PFEAS_TOLER);
00195   EGlpNumInitVar (BD_TOLER);
00196   EGlpNumInitVar (DFEAS_TOLER);
00197   EGlpNumInitVar (PIVOT_TOLER);
00198   EGlpNumInitVar (SZERO_TOLER);
00199   EGlpNumInitVar (PIVZ_TOLER);
00200   EGlpNumInitVar (OBJBND_TOLER);
00201   EGlpNumInitVar (ALTPIV_TOLER);
00202   EGlpNumInitVar (PARAM_MIN_DNORM);
00203   /* parameters that do depend on the tolerance to zero */
00204   EGlpNumSet (PARAM_MIN_DNORM, 4.5036e-9);
00205   EGlpNumMultTo (PARAM_MIN_DNORM, epsLpNum);
00206   EGlpNumSet (PFEAS_TOLER, 4.5036e9);
00207   EGlpNumMultTo (PFEAS_TOLER, epsLpNum);
00208   EGlpNumSet (BD_TOLER, 4.5036e8);
00209   EGlpNumMultTo (BD_TOLER, epsLpNum);
00210   EGlpNumSet (DFEAS_TOLER, 4.5036e9);
00211   EGlpNumMultTo (DFEAS_TOLER, epsLpNum);
00212   EGlpNumSet (PIVOT_TOLER, 4.5036e5);
00213   EGlpNumMultTo (PIVOT_TOLER, epsLpNum);
00214   EGlpNumSet (SZERO_TOLER, 4.5036);
00215   EGlpNumMultTo (SZERO_TOLER, epsLpNum);
00216   EGlpNumSet (PIVZ_TOLER, 4.5036e3);
00217   EGlpNumMultTo (PIVZ_TOLER, epsLpNum);
00218   EGlpNumSet (OBJBND_TOLER, 4.5036e13);
00219   EGlpNumMultTo (OBJBND_TOLER, epsLpNum);
00220   EGlpNumSet (ALTPIV_TOLER, 4.5036e7);
00221   EGlpNumMultTo (ALTPIV_TOLER, epsLpNum);
00222   EGlpNumSet (PROGRESS_ZERO, 4.5036e8);
00223   EGlpNumMultTo (PROGRESS_ZERO, epsLpNum);
00224   EGlpNumSet (PROGRESS_THRESH, 4.5036e10);
00225   EGlpNumMultTo (PROGRESS_THRESH, epsLpNum);
00226 }
00227 
00228 /* ========================================================================= */
00229 void ILLend ( void)
00230 {
00231   if (!__QSEX_SETUP)
00232     return;
00233   EGlpNumClearVar (PARAM_IBASIS_RPIVOT);
00234   EGlpNumClearVar (PARAM_IBASIS_RTRIANG);
00235   EGlpNumClearVar (PARAM_MIN_DNORM);
00236   EGlpNumClearVar (PFEAS_TOLER);
00237   EGlpNumClearVar (BD_TOLER);
00238   EGlpNumClearVar (DFEAS_TOLER);
00239   EGlpNumClearVar (PIVOT_TOLER);
00240   EGlpNumClearVar (SZERO_TOLER);
00241   EGlpNumClearVar (PIVZ_TOLER);
00242   EGlpNumClearVar (OBJBND_TOLER);
00243   EGlpNumClearVar (DBNDPIV_TOLER);
00244   EGlpNumClearVar (DBNDPIV_RATIO);
00245   EGlpNumClearVar (ALTPIV_TOLER);
00246   //EGlpNumClearVar (DJZERO_TOLER);
00247   EGlpNumClearVar (PROGRESS_ZERO);  /*            1e-7 */
00248   EGlpNumClearVar (PROGRESS_THRESH);  /*          1e-5 */
00249   EGlpNumClearVar (CB_EPS);
00250   EGlpNumClearVar (CB_INF_RATIO);
00251   EGlpNumClearVar (CB_PRI_RLIMIT);
00252   EGlpNumClearVar (ILL_MAXDOUBLE);
00253   EGlpNumClearVar (ILL_MINDOUBLE);
00254   __QSEX_SETUP = 0;
00255 }
00256 
00257 QSdata *ILLread (
00258   qsline_reader * file,
00259   const char *fname,
00260   int isMps)
00261 {
00262   int rval = 0;
00263   QSdata *p = 0;
00264   ILLlpdata *lp;
00265   rawlpdata rawlp;
00266 
00267   ILL_FAILfalse (file != NULL, NULL);
00268   ILL_FAILfalse (fname != NULL, NULL);
00269 
00270   p = QScreate_prob (fname, QS_MIN);
00271   ILL_CHECKnull (p, NULL);
00272   ILL_IFFREE (p->qslp->probname, char);
00273 
00274   lp = p->qslp;
00275 
00276   ILLinit_rawlpdata (&rawlp, file->error_collector);
00277   ILLlpdata_init (lp);
00278 
00279   if (isMps != 0)
00280   {
00281     rval = ILLread_mps (file, fname, &rawlp);
00282   }
00283   else
00284   {
00285     rval = ILLread_lp (file, fname, &rawlp);
00286   }
00287   CHECKRVALG (rval, CLEANUP);
00288 
00289   rval = ILLrawlpdata_to_lpdata (&rawlp, lp);
00290   CHECKRVALG (rval, CLEANUP);
00291 
00292 CLEANUP:
00293   ILLfree_rawlpdata (&rawlp);
00294   if (rval != 0)
00295   {
00296     QSfree_prob (p);
00297     p = 0;
00298   }
00299   return p;
00300 }
00301 
00302 void ILLlpdata_init (
00303   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 = 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     ILLmatrix_init (&lp->A);
00323     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 ILLlpdata_free (
00348   ILLlpdata * lp)
00349 {
00350   int i;
00351 
00352   if (lp)
00353   {
00354     ILL_IFFREE (lp->sense, char);
00355 
00356     EGlpNumFreeArray (lp->obj);
00357     EGlpNumFreeArray (lp->rhs);
00358     EGlpNumFreeArray (lp->rangeval);
00359     EGlpNumFreeArray (lp->lower);
00360     EGlpNumFreeArray (lp->upper);
00361     ILLmatrix_free (&lp->A);
00362     if (lp->rA)
00363     {
00364       ILLlp_rows_clear (lp->rA);
00365       ILL_IFFREE (lp->rA, ILLlp_rows);
00366     }
00367     ILL_IFFREE (lp->is_sos_mem, int);
00368     ILL_IFFREE (lp->refrowname, char);
00369 
00370     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       ILLlp_sinfo_free (lp->sinfo);
00398       ILL_IFFREE (lp->sinfo, ILLlp_sinfo);
00399     }
00400     ILLlpdata_init (lp);
00401   }
00402 }
00403 
00404 void ILLlp_basis_init (
00405   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 ILLlp_basis_free (
00419   ILLlp_basis * B)
00420 {
00421   if (B)
00422   {
00423     ILL_IFFREE (B->cstat, char);
00424     ILL_IFFREE (B->rstat, char);
00425 
00426     EGlpNumFreeArray (B->rownorms);
00427     EGlpNumFreeArray (B->colnorms);
00428     B->nstruct = 0;
00429     B->nrows = 0;
00430   }
00431 }
00432 
00433 int ILLlp_basis_alloc (
00434   ILLlp_basis * B,
00435   int nstruct,
00436   int nrows)
00437 {
00438   int rval = 0;
00439 
00440   ILL_FAILtrue (B == NULL, "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     ILLlp_basis_free (B);
00460   }
00461 
00462   EG_RETURN (rval);
00463 }
00464 
00465 void ILLlp_cache_init (
00466   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     EGlpNumZero (C->val);
00478   }
00479 }
00480 
00481 void ILLlp_cache_free (
00482   ILLlp_cache * C)
00483 {
00484   if (C)
00485   {
00486     EGlpNumFreeArray (C->x);
00487     EGlpNumFreeArray (C->rc);
00488     EGlpNumFreeArray (C->pi);
00489     EGlpNumFreeArray (C->slack);
00490     C->nstruct = 0;
00491     C->nrows = 0;
00492     C->status = 0;
00493   }
00494 }
00495 
00496 int ILLlp_cache_alloc (
00497   ILLlp_cache * C,
00498   int nstruct,
00499   int nrows)
00500 {
00501   int rval = 0;
00502 
00503   ILL_FAILtrue (C == NULL, "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 = EGlpNumAllocArray (nstruct);
00511     C->rc = EGlpNumAllocArray (nstruct);
00512   }
00513 
00514   if (nrows > 0)
00515   {
00516     C->pi = EGlpNumAllocArray (nrows);
00517     C->slack = EGlpNumAllocArray (nrows);
00518   }
00519 
00520 CLEANUP:
00521 
00522   if (rval)
00523   {
00524     ILLlp_cache_free (C);
00525   }
00526 
00527   EG_RETURN (rval);
00528 }
00529 
00530 
00531 int ILLlp_rows_init (
00532   ILLlp_rows * lprows,
00533   ILLlpdata * lp,
00534   int include_logicals)
00535 {
00536   int rval = 0;
00537   int i, k, st;
00538   int *beg, *cnt, *ind;
00539   EGlpNum_t *val;
00540   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 = EGlpNumAllocArray (lp->nzcount);
00596       }
00597       else
00598       {
00599         ILL_SAFE_MALLOC (lprows->rowind, lp->nzcount - lp->nrows, int);
00600 
00601         lprows->rowval = 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           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     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 ILLlp_rows_clear (
00675   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     EGlpNumFreeArray (lprows->rowval);
00684   }
00685 }
00686 
00687 static int wr_line (
00688   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 ILLprint_report (
00713   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 = wr_line (lp, format, marker);
00722   va_end (marker);              /* Reset variable arguments.      */
00723   return rval;
00724 }

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