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

Generated on Wed Apr 22 09:16:09 2009 for QSopt_ex by  doxygen 1.5.2