fp20_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: fp20_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 (fp20_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 fp20_ILLlpdata_init (fp20_ILLlpdata *lp)                                   */
00045 /*    void fp20_ILLlpdata_free (fp20_ILLlpdata *lp)                                   */
00046 /*                                                                          */
00047 /*    void fp20_ILLlp_basis_init (fp20_ILLlp_basis *B)                                */
00048 /*    void fp20_ILLlp_basis_free (fp20_ILLlp_basis *B)                                */
00049 /*    int fp20_ILLlp_basis_alloc (fp20_ILLlp_basis *B, int nstruct, int nrows)        */
00050 /*                                                                          */
00051 /*    void fp20_ILLlp_cache_init (fp20_ILLlp_cache *C)                                */
00052 /*    void fp20_ILLlp_cache_free (fp20_ILLlp_cache *C)                                */
00053 /*    int fp20_ILLlp_cache_alloc (fp20_ILLlp_cache *C, int nstruct, int nrows)        */
00054 /*                                                                          */
00055 /*    void fp20_ILLlp_sinfo_init (fp20_ILLlp_sinfo *sinfo)                            */
00056 /*    void fp20_ILLlp_sinfo_free (fp20_ILLlp_sinfo *sinfo)                            */
00057 /*                                                                          */
00058 /*    int fp20_ILLlp_rows_init(fp20_ILLlp_rows *lprows, fp20_ILLlpdata *lp,                */
00059 /*                                           int include_logicals)          */
00060 /*                                                                          */
00061 /****************************************************************************/
00062 
00063 #include "qs_config.h"
00064 #include "fp20_iqsutil.h"
00065 #include "fp20_lpdata.h"
00066 #include "fp20_qstruct.h"
00067 #include "fp20_qsopt.h"
00068 #include "fp20_lp.h"
00069 #include "fp20_mps.h"
00070 #include "fp20_rawlp.h"
00071 #ifdef USEDMALLOC
00072 #include "dmalloc.h"
00073 #endif
00074 
00075 //static int TRACE = 0;
00076 
00077 EGfp20_t fp20_PARAM_IBASIS_RPIVOT;
00078 EGfp20_t fp20_PARAM_IBASIS_RTRIANG;
00079 EGfp20_t fp20_PARAM_MIN_DNORM;
00080 EGfp20_t fp20_PFEAS_TOLER;
00081 EGfp20_t fp20_BD_TOLER;
00082 EGfp20_t fp20_DFEAS_TOLER;
00083 EGfp20_t fp20_PIVOT_TOLER;
00084 EGfp20_t fp20_SZERO_TOLER;
00085 EGfp20_t fp20_PIVZ_TOLER;
00086 EGfp20_t fp20_OBJBND_TOLER;
00087 EGfp20_t fp20_DBNDPIV_TOLER;
00088 EGfp20_t fp20_DBNDPIV_RATIO;
00089 EGfp20_t fp20_ALTPIV_TOLER;
00090 //EGfp20_t DJZERO_TOLER;
00091 EGfp20_t fp20_PROGRESS_ZERO;        /*   1e-7 */
00092 EGfp20_t fp20_PROGRESS_THRESH;      /*   1e-5 */
00093 EGfp20_t fp20_CB_EPS;
00094 EGfp20_t fp20_CB_INF_RATIO;
00095 EGfp20_t fp20_CB_PRI_RLIMIT;
00096 EGfp20_t fp20_ILL_MAXDOUBLE;
00097 EGfp20_t fp20_ILL_MINDOUBLE;
00098 
00099 /* ========================================================================= */
00100 int fp20___QSEX_SETUP = 0;
00101 /* ========================================================================= */
00102 void fp20_ILLstart ( void)
00103 {
00104   if (fp20___QSEX_SETUP)
00105     return;
00106   fp20_EGlpNumInitVar (fp20_PARAM_IBASIS_RPIVOT);
00107   fp20_EGlpNumInitVar (fp20_PARAM_IBASIS_RTRIANG);
00108   fp20_EGlpNumInitVar (fp20_PARAM_MIN_DNORM);
00109   fp20_EGlpNumInitVar (fp20_PFEAS_TOLER);
00110   fp20_EGlpNumInitVar (fp20_BD_TOLER);
00111   fp20_EGlpNumInitVar (fp20_DFEAS_TOLER);
00112   fp20_EGlpNumInitVar (fp20_PIVOT_TOLER);
00113   fp20_EGlpNumInitVar (fp20_SZERO_TOLER);
00114   fp20_EGlpNumInitVar (fp20_PIVZ_TOLER);
00115   fp20_EGlpNumInitVar (fp20_OBJBND_TOLER);
00116   fp20_EGlpNumInitVar (fp20_DBNDPIV_TOLER);
00117   fp20_EGlpNumInitVar (fp20_DBNDPIV_RATIO);
00118   fp20_EGlpNumInitVar (fp20_ALTPIV_TOLER);
00119   //fp20_EGlpNumInitVar (DJZERO_TOLER);
00120   fp20_EGlpNumInitVar (fp20_PROGRESS_ZERO); /*            1e-7 */
00121   fp20_EGlpNumInitVar (fp20_PROGRESS_THRESH); /*          1e-5 */
00122   fp20_EGlpNumInitVar (fp20_CB_PRI_RLIMIT);
00123   fp20_EGlpNumInitVar (fp20_CB_INF_RATIO);
00124   fp20_EGlpNumInitVar (fp20_CB_EPS);
00125   fp20_EGlpNumInitVar (fp20_ILL_MAXDOUBLE);
00126   fp20_EGlpNumInitVar (fp20_ILL_MINDOUBLE);
00127   /* parameters that do depend on the tolerance to zero */
00128   fp20_EGlpNumSet (fp20_PARAM_MIN_DNORM, 4.5036e-9);
00129   fp20_EGlpNumMultTo (fp20_PARAM_MIN_DNORM, fp20_epsLpNum);
00130   fp20_EGlpNumSet (fp20_PFEAS_TOLER, 4.5036e9);
00131   fp20_EGlpNumMultTo (fp20_PFEAS_TOLER, fp20_epsLpNum);
00132   fp20_EGlpNumSet (fp20_BD_TOLER, 4.5036e8);
00133   fp20_EGlpNumMultTo (fp20_BD_TOLER, fp20_epsLpNum);
00134   fp20_EGlpNumSet (fp20_DFEAS_TOLER, 4.5036e9);
00135   fp20_EGlpNumMultTo (fp20_DFEAS_TOLER, fp20_epsLpNum);
00136   fp20_EGlpNumSet (fp20_PIVOT_TOLER, 4.5036e5);
00137   fp20_EGlpNumMultTo (fp20_PIVOT_TOLER, fp20_epsLpNum);
00138   fp20_EGlpNumSet (fp20_SZERO_TOLER, 4.5036);
00139   fp20_EGlpNumMultTo (fp20_SZERO_TOLER, fp20_epsLpNum);
00140   fp20_EGlpNumSet (fp20_PIVZ_TOLER, 4.5036e3);
00141   fp20_EGlpNumMultTo (fp20_PIVZ_TOLER, fp20_epsLpNum);
00142   fp20_EGlpNumSet (fp20_OBJBND_TOLER, 4.5036e13);
00143   fp20_EGlpNumMultTo (fp20_OBJBND_TOLER, fp20_epsLpNum);
00144   fp20_EGlpNumSet (fp20_ALTPIV_TOLER, 4.5036e7);
00145   fp20_EGlpNumMultTo (fp20_ALTPIV_TOLER, fp20_epsLpNum);
00146   fp20_EGlpNumSet (fp20_PROGRESS_ZERO, 4.5036e8);
00147   fp20_EGlpNumMultTo (fp20_PROGRESS_ZERO, fp20_epsLpNum);
00148   fp20_EGlpNumSet (fp20_PROGRESS_THRESH, 4.5036e10);
00149   fp20_EGlpNumMultTo (fp20_PROGRESS_THRESH, fp20_epsLpNum);
00150 #if VERBOSE_LEVEL <= DEBUG
00151   MESSAGE (VERBOSE_LEVEL, "Setting fp20_PARAM_MIN_DNORM to %lg", fp20_EGlpNumToLf (fp20_PARAM_MIN_DNORM));
00152   MESSAGE (VERBOSE_LEVEL, "Setting fp20_PFEAS_TOLER to %lg", fp20_EGlpNumToLf (fp20_PFEAS_TOLER));
00153   MESSAGE (VERBOSE_LEVEL, "Setting fp20_BD_TOLER to %lg", fp20_EGlpNumToLf (fp20_BD_TOLER));
00154   MESSAGE (VERBOSE_LEVEL, "Setting fp20_DFEAS_TOLER to %lg", fp20_EGlpNumToLf (fp20_DFEAS_TOLER));
00155   MESSAGE (VERBOSE_LEVEL, "Setting fp20_PIVOT_TOLER to %lg", fp20_EGlpNumToLf (fp20_PIVOT_TOLER));
00156   MESSAGE (VERBOSE_LEVEL, "Setting fp20_SZERO_TOLER to %lg", fp20_EGlpNumToLf (fp20_SZERO_TOLER));
00157   MESSAGE (VERBOSE_LEVEL, "Setting fp20_PIVZ_TOLER to %lg", fp20_EGlpNumToLf (fp20_PIVZ_TOLER));
00158   MESSAGE (VERBOSE_LEVEL, "Setting fp20_OBJBND_TOLER to %lg", fp20_EGlpNumToLf (fp20_OBJBND_TOLER));
00159   MESSAGE (VERBOSE_LEVEL, "Setting fp20_ALTPIV_TOLER to %lg", fp20_EGlpNumToLf (fp20_ALTPIV_TOLER));
00160   MESSAGE (VERBOSE_LEVEL, "Setting fp20_PROGRESS_ZERO to %lg", fp20_EGlpNumToLf (fp20_PROGRESS_ZERO));
00161   MESSAGE (VERBOSE_LEVEL, "Setting fp20_PROGRESS_THRESH to %lg", fp20_EGlpNumToLf (fp20_PROGRESS_THRESH));
00162 #endif
00163   /* parameters that do not depend on the tolerance to zero */
00164   fp20_EGlpNumSet (fp20_ILL_MAXDOUBLE, 1e150);
00165   fp20_EGlpNumSet (fp20_ILL_MINDOUBLE, -1e150);
00166   fp20_EGlpNumSet (fp20_PARAM_IBASIS_RPIVOT, 0.98);
00167   fp20_EGlpNumSet (fp20_PARAM_IBASIS_RTRIANG, 0.01);
00168   fp20_EGlpNumSet (fp20_DBNDPIV_TOLER, 1e-3);
00169   fp20_EGlpNumSet (fp20_DBNDPIV_RATIO, 1e-2);
00170   //fp20_EGlpNumSet (DJZERO_TOLER, 1e-8);
00171   fp20_EGlpNumSet (fp20_CB_EPS, 0.001);
00172   fp20_EGlpNumSet (fp20_CB_INF_RATIO, 10.0);
00173   fp20_EGlpNumSet (fp20_CB_PRI_RLIMIT, 0.25);
00174   fp20___QSEX_SETUP = 1;
00175 }
00176 
00177 /* ========================================================================= */
00178 void fp20_ILLchange_precision (
00179   void)
00180 {
00181   fp20_EGlpNumClearVar (fp20_PFEAS_TOLER);
00182   fp20_EGlpNumClearVar (fp20_BD_TOLER);
00183   fp20_EGlpNumClearVar (fp20_DFEAS_TOLER);
00184   fp20_EGlpNumClearVar (fp20_PIVOT_TOLER);
00185   fp20_EGlpNumClearVar (fp20_SZERO_TOLER);
00186   fp20_EGlpNumClearVar (fp20_PIVZ_TOLER);
00187   fp20_EGlpNumClearVar (fp20_OBJBND_TOLER);
00188   fp20_EGlpNumClearVar (fp20_ALTPIV_TOLER);
00189   fp20_EGlpNumClearVar (fp20_PARAM_MIN_DNORM);
00190   fp20_EGlpNumClearVar (fp20_PROGRESS_ZERO);
00191   fp20_EGlpNumClearVar (fp20_PROGRESS_THRESH);
00192   fp20_EGlpNumInitVar (fp20_PROGRESS_ZERO);
00193   fp20_EGlpNumInitVar (fp20_PROGRESS_THRESH);
00194   fp20_EGlpNumInitVar (fp20_PFEAS_TOLER);
00195   fp20_EGlpNumInitVar (fp20_BD_TOLER);
00196   fp20_EGlpNumInitVar (fp20_DFEAS_TOLER);
00197   fp20_EGlpNumInitVar (fp20_PIVOT_TOLER);
00198   fp20_EGlpNumInitVar (fp20_SZERO_TOLER);
00199   fp20_EGlpNumInitVar (fp20_PIVZ_TOLER);
00200   fp20_EGlpNumInitVar (fp20_OBJBND_TOLER);
00201   fp20_EGlpNumInitVar (fp20_ALTPIV_TOLER);
00202   fp20_EGlpNumInitVar (fp20_PARAM_MIN_DNORM);
00203   /* parameters that do depend on the tolerance to zero */
00204   fp20_EGlpNumSet (fp20_PARAM_MIN_DNORM, 4.5036e-9);
00205   fp20_EGlpNumMultTo (fp20_PARAM_MIN_DNORM, fp20_epsLpNum);
00206   fp20_EGlpNumSet (fp20_PFEAS_TOLER, 4.5036e9);
00207   fp20_EGlpNumMultTo (fp20_PFEAS_TOLER, fp20_epsLpNum);
00208   fp20_EGlpNumSet (fp20_BD_TOLER, 4.5036e8);
00209   fp20_EGlpNumMultTo (fp20_BD_TOLER, fp20_epsLpNum);
00210   fp20_EGlpNumSet (fp20_DFEAS_TOLER, 4.5036e9);
00211   fp20_EGlpNumMultTo (fp20_DFEAS_TOLER, fp20_epsLpNum);
00212   fp20_EGlpNumSet (fp20_PIVOT_TOLER, 4.5036e5);
00213   fp20_EGlpNumMultTo (fp20_PIVOT_TOLER, fp20_epsLpNum);
00214   fp20_EGlpNumSet (fp20_SZERO_TOLER, 4.5036);
00215   fp20_EGlpNumMultTo (fp20_SZERO_TOLER, fp20_epsLpNum);
00216   fp20_EGlpNumSet (fp20_PIVZ_TOLER, 4.5036e3);
00217   fp20_EGlpNumMultTo (fp20_PIVZ_TOLER, fp20_epsLpNum);
00218   fp20_EGlpNumSet (fp20_OBJBND_TOLER, 4.5036e13);
00219   fp20_EGlpNumMultTo (fp20_OBJBND_TOLER, fp20_epsLpNum);
00220   fp20_EGlpNumSet (fp20_ALTPIV_TOLER, 4.5036e7);
00221   fp20_EGlpNumMultTo (fp20_ALTPIV_TOLER, fp20_epsLpNum);
00222   fp20_EGlpNumSet (fp20_PROGRESS_ZERO, 4.5036e8);
00223   fp20_EGlpNumMultTo (fp20_PROGRESS_ZERO, fp20_epsLpNum);
00224   fp20_EGlpNumSet (fp20_PROGRESS_THRESH, 4.5036e10);
00225   fp20_EGlpNumMultTo (fp20_PROGRESS_THRESH, fp20_epsLpNum);
00226 }
00227 
00228 /* ========================================================================= */
00229 void fp20_ILLend ( void)
00230 {
00231   if (!fp20___QSEX_SETUP)
00232     return;
00233   fp20_EGlpNumClearVar (fp20_PARAM_IBASIS_RPIVOT);
00234   fp20_EGlpNumClearVar (fp20_PARAM_IBASIS_RTRIANG);
00235   fp20_EGlpNumClearVar (fp20_PARAM_MIN_DNORM);
00236   fp20_EGlpNumClearVar (fp20_PFEAS_TOLER);
00237   fp20_EGlpNumClearVar (fp20_BD_TOLER);
00238   fp20_EGlpNumClearVar (fp20_DFEAS_TOLER);
00239   fp20_EGlpNumClearVar (fp20_PIVOT_TOLER);
00240   fp20_EGlpNumClearVar (fp20_SZERO_TOLER);
00241   fp20_EGlpNumClearVar (fp20_PIVZ_TOLER);
00242   fp20_EGlpNumClearVar (fp20_OBJBND_TOLER);
00243   fp20_EGlpNumClearVar (fp20_DBNDPIV_TOLER);
00244   fp20_EGlpNumClearVar (fp20_DBNDPIV_RATIO);
00245   fp20_EGlpNumClearVar (fp20_ALTPIV_TOLER);
00246   //fp20_EGlpNumClearVar (DJZERO_TOLER);
00247   fp20_EGlpNumClearVar (fp20_PROGRESS_ZERO);  /*            1e-7 */
00248   fp20_EGlpNumClearVar (fp20_PROGRESS_THRESH);  /*          1e-5 */
00249   fp20_EGlpNumClearVar (fp20_CB_EPS);
00250   fp20_EGlpNumClearVar (fp20_CB_INF_RATIO);
00251   fp20_EGlpNumClearVar (fp20_CB_PRI_RLIMIT);
00252   fp20_EGlpNumClearVar (fp20_ILL_MAXDOUBLE);
00253   fp20_EGlpNumClearVar (fp20_ILL_MINDOUBLE);
00254   fp20___QSEX_SETUP = 0;
00255 }
00256 
00257 fp20_QSdata *fp20_ILLread (
00258   fp20_qsline_reader * file,
00259   const char *fp20_fname,
00260   int isMps)
00261 {
00262   int rval = 0;
00263   fp20_QSdata *p = 0;
00264   fp20_ILLlpdata *lp;
00265   fp20_rawlpdata rawlp;
00266 
00267   ILL_FAILfalse (file != NULL, NULL);
00268   ILL_FAILfalse (fp20_fname != NULL, NULL);
00269 
00270   p = fp20_QScreate_prob (fp20_fname, QS_MIN);
00271   ILL_CHECKnull (p, NULL);
00272   ILL_IFFREE (p->qslp->probname, char);
00273 
00274   lp = p->qslp;
00275 
00276   fp20_ILLinit_rawlpdata (&rawlp, file->error_collector);
00277   fp20_ILLlpdata_init (lp);
00278 
00279   if (isMps != 0)
00280   {
00281     rval = fp20_ILLread_mps (file, fp20_fname, &rawlp);
00282   }
00283   else
00284   {
00285     rval = fp20_ILLread_lp (file, fp20_fname, &rawlp);
00286   }
00287   CHECKRVALG (rval, CLEANUP);
00288 
00289   rval = fp20_ILLrawlpdata_to_lpdata (&rawlp, lp);
00290   CHECKRVALG (rval, CLEANUP);
00291 
00292 CLEANUP:
00293   fp20_ILLfree_rawlpdata (&rawlp);
00294   if (rval != 0)
00295   {
00296     fp20_QSfree_prob (p);
00297     p = 0;
00298   }
00299   return p;
00300 }
00301 
00302 void fp20_ILLlpdata_init (
00303   fp20_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 = fp20_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     fp20_ILLmatrix_init (&lp->A);
00323     fp20_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 fp20_ILLlpdata_free (
00348   fp20_ILLlpdata * lp)
00349 {
00350   int i;
00351 
00352   if (lp)
00353   {
00354     ILL_IFFREE (lp->sense, char);
00355 
00356     fp20_EGlpNumFreeArray (lp->obj);
00357     fp20_EGlpNumFreeArray (lp->rhs);
00358     fp20_EGlpNumFreeArray (lp->rangeval);
00359     fp20_EGlpNumFreeArray (lp->lower);
00360     fp20_EGlpNumFreeArray (lp->upper);
00361     fp20_ILLmatrix_free (&lp->A);
00362     if (lp->rA)
00363     {
00364       fp20_ILLlp_rows_clear (lp->rA);
00365       ILL_IFFREE (lp->rA, fp20_ILLlp_rows);
00366     }
00367     ILL_IFFREE (lp->is_sos_mem, int);
00368     ILL_IFFREE (lp->refrowname, char);
00369 
00370     fp20_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       fp20_ILLlp_sinfo_free (lp->sinfo);
00398       ILL_IFFREE (lp->sinfo, fp20_ILLlp_sinfo);
00399     }
00400     fp20_ILLlpdata_init (lp);
00401   }
00402 }
00403 
00404 void fp20_ILLlp_basis_init (
00405   fp20_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 fp20_ILLlp_basis_free (
00419   fp20_ILLlp_basis * B)
00420 {
00421   if (B)
00422   {
00423     ILL_IFFREE (B->cstat, char);
00424     ILL_IFFREE (B->rstat, char);
00425 
00426     fp20_EGlpNumFreeArray (B->rownorms);
00427     fp20_EGlpNumFreeArray (B->colnorms);
00428     B->nstruct = 0;
00429     B->nrows = 0;
00430   }
00431 }
00432 
00433 int fp20_ILLlp_basis_alloc (
00434   fp20_ILLlp_basis * B,
00435   int nstruct,
00436   int nrows)
00437 {
00438   int rval = 0;
00439 
00440   ILL_FAILtrue (B == NULL, "fp20_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     fp20_ILLlp_basis_free (B);
00460   }
00461 
00462   EG_RETURN (rval);
00463 }
00464 
00465 void fp20_ILLlp_cache_init (
00466   fp20_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     fp20_EGlpNumZero (C->val);
00478   }
00479 }
00480 
00481 void fp20_ILLlp_cache_free (
00482   fp20_ILLlp_cache * C)
00483 {
00484   if (C)
00485   {
00486     fp20_EGlpNumFreeArray (C->x);
00487     fp20_EGlpNumFreeArray (C->rc);
00488     fp20_EGlpNumFreeArray (C->pi);
00489     fp20_EGlpNumFreeArray (C->slack);
00490     C->nstruct = 0;
00491     C->nrows = 0;
00492     C->status = 0;
00493   }
00494 }
00495 
00496 int fp20_ILLlp_cache_alloc (
00497   fp20_ILLlp_cache * C,
00498   int nstruct,
00499   int nrows)
00500 {
00501   int rval = 0;
00502 
00503   ILL_FAILtrue (C == NULL, "fp20_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 = fp20_EGlpNumAllocArray (nstruct);
00511     C->rc = fp20_EGlpNumAllocArray (nstruct);
00512   }
00513 
00514   if (nrows > 0)
00515   {
00516     C->pi = fp20_EGlpNumAllocArray (nrows);
00517     C->slack = fp20_EGlpNumAllocArray (nrows);
00518   }
00519 
00520 CLEANUP:
00521 
00522   if (rval)
00523   {
00524     fp20_ILLlp_cache_free (C);
00525   }
00526 
00527   EG_RETURN (rval);
00528 }
00529 
00530 
00531 int fp20_ILLlp_rows_init (
00532   fp20_ILLlp_rows * lprows,
00533   fp20_ILLlpdata * lp,
00534   int include_logicals)
00535 {
00536   int rval = 0;
00537   int i, k, st;
00538   int *beg, *cnt, *ind;
00539   EGfp20_t *val;
00540   fp20_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 = fp20_EGlpNumAllocArray (lp->nzcount);
00596       }
00597       else
00598       {
00599         ILL_SAFE_MALLOC (lprows->rowind, lp->nzcount - lp->nrows, int);
00600 
00601         lprows->rowval = fp20_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           fp20_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     fp20_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 fp20_ILLlp_rows_clear (
00675   fp20_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     fp20_EGlpNumFreeArray (lprows->rowval);
00684   }
00685 }
00686 
00687 static int fp20_wr_line (
00688   fp20_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 fp20_ILLprint_report (
00713   fp20_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 = fp20_wr_line (lp, format, marker);
00722   va_end (marker);              /* Reset variable arguments.      */
00723   return rval;
00724 }

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