ldbl_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: ldbl_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 (ldbl_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 ldbl_ILLlpdata_init (ldbl_ILLlpdata *lp)                                   */
00045 /*    void ldbl_ILLlpdata_free (ldbl_ILLlpdata *lp)                                   */
00046 /*                                                                          */
00047 /*    void ldbl_ILLlp_basis_init (ldbl_ILLlp_basis *B)                                */
00048 /*    void ldbl_ILLlp_basis_free (ldbl_ILLlp_basis *B)                                */
00049 /*    int ldbl_ILLlp_basis_alloc (ldbl_ILLlp_basis *B, int nstruct, int nrows)        */
00050 /*                                                                          */
00051 /*    void ldbl_ILLlp_cache_init (ldbl_ILLlp_cache *C)                                */
00052 /*    void ldbl_ILLlp_cache_free (ldbl_ILLlp_cache *C)                                */
00053 /*    int ldbl_ILLlp_cache_alloc (ldbl_ILLlp_cache *C, int nstruct, int nrows)        */
00054 /*                                                                          */
00055 /*    void ldbl_ILLlp_sinfo_init (ldbl_ILLlp_sinfo *sinfo)                            */
00056 /*    void ldbl_ILLlp_sinfo_free (ldbl_ILLlp_sinfo *sinfo)                            */
00057 /*                                                                          */
00058 /*    int ldbl_ILLlp_rows_init(ldbl_ILLlp_rows *lprows, ldbl_ILLlpdata *lp,                */
00059 /*                                           int include_logicals)          */
00060 /*                                                                          */
00061 /****************************************************************************/
00062 
00063 #include "qs_config.h"
00064 #include "ldbl_iqsutil.h"
00065 #include "ldbl_lpdata.h"
00066 #include "ldbl_qstruct.h"
00067 #include "ldbl_qsopt.h"
00068 #include "ldbl_lp.h"
00069 #include "ldbl_mps.h"
00070 #include "ldbl_rawlp.h"
00071 #ifdef USEDMALLOC
00072 #include "dmalloc.h"
00073 #endif
00074 
00075 //static int TRACE = 0;
00076 
00077 long double ldbl_PARAM_IBASIS_RPIVOT;
00078 long double ldbl_PARAM_IBASIS_RTRIANG;
00079 long double ldbl_PARAM_MIN_DNORM;
00080 long double ldbl_PFEAS_TOLER;
00081 long double ldbl_BD_TOLER;
00082 long double ldbl_DFEAS_TOLER;
00083 long double ldbl_PIVOT_TOLER;
00084 long double ldbl_SZERO_TOLER;
00085 long double ldbl_PIVZ_TOLER;
00086 long double ldbl_OBJBND_TOLER;
00087 long double ldbl_DBNDPIV_TOLER;
00088 long double ldbl_DBNDPIV_RATIO;
00089 long double ldbl_ALTPIV_TOLER;
00090 //long double DJZERO_TOLER;
00091 long double ldbl_PROGRESS_ZERO;       /*   1e-7 */
00092 long double ldbl_PROGRESS_THRESH;     /*   1e-5 */
00093 long double ldbl_CB_EPS;
00094 long double ldbl_CB_INF_RATIO;
00095 long double ldbl_CB_PRI_RLIMIT;
00096 long double ldbl_ILL_MAXDOUBLE;
00097 long double ldbl_ILL_MINDOUBLE;
00098 
00099 /* ========================================================================= */
00100 int ldbl___QSEX_SETUP = 0;
00101 /* ========================================================================= */
00102 void ldbl_ILLstart ( void)
00103 {
00104   if (ldbl___QSEX_SETUP)
00105     return;
00106   ldbl_EGlpNumInitVar (ldbl_PARAM_IBASIS_RPIVOT);
00107   ldbl_EGlpNumInitVar (ldbl_PARAM_IBASIS_RTRIANG);
00108   ldbl_EGlpNumInitVar (ldbl_PARAM_MIN_DNORM);
00109   ldbl_EGlpNumInitVar (ldbl_PFEAS_TOLER);
00110   ldbl_EGlpNumInitVar (ldbl_BD_TOLER);
00111   ldbl_EGlpNumInitVar (ldbl_DFEAS_TOLER);
00112   ldbl_EGlpNumInitVar (ldbl_PIVOT_TOLER);
00113   ldbl_EGlpNumInitVar (ldbl_SZERO_TOLER);
00114   ldbl_EGlpNumInitVar (ldbl_PIVZ_TOLER);
00115   ldbl_EGlpNumInitVar (ldbl_OBJBND_TOLER);
00116   ldbl_EGlpNumInitVar (ldbl_DBNDPIV_TOLER);
00117   ldbl_EGlpNumInitVar (ldbl_DBNDPIV_RATIO);
00118   ldbl_EGlpNumInitVar (ldbl_ALTPIV_TOLER);
00119   //ldbl_EGlpNumInitVar (DJZERO_TOLER);
00120   ldbl_EGlpNumInitVar (ldbl_PROGRESS_ZERO); /*            1e-7 */
00121   ldbl_EGlpNumInitVar (ldbl_PROGRESS_THRESH); /*          1e-5 */
00122   ldbl_EGlpNumInitVar (ldbl_CB_PRI_RLIMIT);
00123   ldbl_EGlpNumInitVar (ldbl_CB_INF_RATIO);
00124   ldbl_EGlpNumInitVar (ldbl_CB_EPS);
00125   ldbl_EGlpNumInitVar (ldbl_ILL_MAXDOUBLE);
00126   ldbl_EGlpNumInitVar (ldbl_ILL_MINDOUBLE);
00127   /* parameters that do depend on the tolerance to zero */
00128   ldbl_EGlpNumSet (ldbl_PARAM_MIN_DNORM, 4.5036e-9);
00129   ldbl_EGlpNumMultTo (ldbl_PARAM_MIN_DNORM, ldbl_epsLpNum);
00130   ldbl_EGlpNumSet (ldbl_PFEAS_TOLER, 4.5036e9);
00131   ldbl_EGlpNumMultTo (ldbl_PFEAS_TOLER, ldbl_epsLpNum);
00132   ldbl_EGlpNumSet (ldbl_BD_TOLER, 4.5036e8);
00133   ldbl_EGlpNumMultTo (ldbl_BD_TOLER, ldbl_epsLpNum);
00134   ldbl_EGlpNumSet (ldbl_DFEAS_TOLER, 4.5036e9);
00135   ldbl_EGlpNumMultTo (ldbl_DFEAS_TOLER, ldbl_epsLpNum);
00136   ldbl_EGlpNumSet (ldbl_PIVOT_TOLER, 4.5036e5);
00137   ldbl_EGlpNumMultTo (ldbl_PIVOT_TOLER, ldbl_epsLpNum);
00138   ldbl_EGlpNumSet (ldbl_SZERO_TOLER, 4.5036);
00139   ldbl_EGlpNumMultTo (ldbl_SZERO_TOLER, ldbl_epsLpNum);
00140   ldbl_EGlpNumSet (ldbl_PIVZ_TOLER, 4.5036e3);
00141   ldbl_EGlpNumMultTo (ldbl_PIVZ_TOLER, ldbl_epsLpNum);
00142   ldbl_EGlpNumSet (ldbl_OBJBND_TOLER, 4.5036e13);
00143   ldbl_EGlpNumMultTo (ldbl_OBJBND_TOLER, ldbl_epsLpNum);
00144   ldbl_EGlpNumSet (ldbl_ALTPIV_TOLER, 4.5036e7);
00145   ldbl_EGlpNumMultTo (ldbl_ALTPIV_TOLER, ldbl_epsLpNum);
00146   ldbl_EGlpNumSet (ldbl_PROGRESS_ZERO, 4.5036e8);
00147   ldbl_EGlpNumMultTo (ldbl_PROGRESS_ZERO, ldbl_epsLpNum);
00148   ldbl_EGlpNumSet (ldbl_PROGRESS_THRESH, 4.5036e10);
00149   ldbl_EGlpNumMultTo (ldbl_PROGRESS_THRESH, ldbl_epsLpNum);
00150 #if VERBOSE_LEVEL <= DEBUG
00151   MESSAGE (VERBOSE_LEVEL, "Setting ldbl_PARAM_MIN_DNORM to %lg", ldbl_EGlpNumToLf (ldbl_PARAM_MIN_DNORM));
00152   MESSAGE (VERBOSE_LEVEL, "Setting ldbl_PFEAS_TOLER to %lg", ldbl_EGlpNumToLf (ldbl_PFEAS_TOLER));
00153   MESSAGE (VERBOSE_LEVEL, "Setting ldbl_BD_TOLER to %lg", ldbl_EGlpNumToLf (ldbl_BD_TOLER));
00154   MESSAGE (VERBOSE_LEVEL, "Setting ldbl_DFEAS_TOLER to %lg", ldbl_EGlpNumToLf (ldbl_DFEAS_TOLER));
00155   MESSAGE (VERBOSE_LEVEL, "Setting ldbl_PIVOT_TOLER to %lg", ldbl_EGlpNumToLf (ldbl_PIVOT_TOLER));
00156   MESSAGE (VERBOSE_LEVEL, "Setting ldbl_SZERO_TOLER to %lg", ldbl_EGlpNumToLf (ldbl_SZERO_TOLER));
00157   MESSAGE (VERBOSE_LEVEL, "Setting ldbl_PIVZ_TOLER to %lg", ldbl_EGlpNumToLf (ldbl_PIVZ_TOLER));
00158   MESSAGE (VERBOSE_LEVEL, "Setting ldbl_OBJBND_TOLER to %lg", ldbl_EGlpNumToLf (ldbl_OBJBND_TOLER));
00159   MESSAGE (VERBOSE_LEVEL, "Setting ldbl_ALTPIV_TOLER to %lg", ldbl_EGlpNumToLf (ldbl_ALTPIV_TOLER));
00160   MESSAGE (VERBOSE_LEVEL, "Setting ldbl_PROGRESS_ZERO to %lg", ldbl_EGlpNumToLf (ldbl_PROGRESS_ZERO));
00161   MESSAGE (VERBOSE_LEVEL, "Setting ldbl_PROGRESS_THRESH to %lg", ldbl_EGlpNumToLf (ldbl_PROGRESS_THRESH));
00162 #endif
00163   /* parameters that do not depend on the tolerance to zero */
00164   ldbl_EGlpNumSet (ldbl_ILL_MAXDOUBLE, 1e150);
00165   ldbl_EGlpNumSet (ldbl_ILL_MINDOUBLE, -1e150);
00166   ldbl_EGlpNumSet (ldbl_PARAM_IBASIS_RPIVOT, 0.98);
00167   ldbl_EGlpNumSet (ldbl_PARAM_IBASIS_RTRIANG, 0.01);
00168   ldbl_EGlpNumSet (ldbl_DBNDPIV_TOLER, 1e-3);
00169   ldbl_EGlpNumSet (ldbl_DBNDPIV_RATIO, 1e-2);
00170   //ldbl_EGlpNumSet (DJZERO_TOLER, 1e-8);
00171   ldbl_EGlpNumSet (ldbl_CB_EPS, 0.001);
00172   ldbl_EGlpNumSet (ldbl_CB_INF_RATIO, 10.0);
00173   ldbl_EGlpNumSet (ldbl_CB_PRI_RLIMIT, 0.25);
00174   ldbl___QSEX_SETUP = 1;
00175 }
00176 
00177 /* ========================================================================= */
00178 void ldbl_ILLchange_precision (
00179   void)
00180 {
00181   ldbl_EGlpNumClearVar (ldbl_PFEAS_TOLER);
00182   ldbl_EGlpNumClearVar (ldbl_BD_TOLER);
00183   ldbl_EGlpNumClearVar (ldbl_DFEAS_TOLER);
00184   ldbl_EGlpNumClearVar (ldbl_PIVOT_TOLER);
00185   ldbl_EGlpNumClearVar (ldbl_SZERO_TOLER);
00186   ldbl_EGlpNumClearVar (ldbl_PIVZ_TOLER);
00187   ldbl_EGlpNumClearVar (ldbl_OBJBND_TOLER);
00188   ldbl_EGlpNumClearVar (ldbl_ALTPIV_TOLER);
00189   ldbl_EGlpNumClearVar (ldbl_PARAM_MIN_DNORM);
00190   ldbl_EGlpNumClearVar (ldbl_PROGRESS_ZERO);
00191   ldbl_EGlpNumClearVar (ldbl_PROGRESS_THRESH);
00192   ldbl_EGlpNumInitVar (ldbl_PROGRESS_ZERO);
00193   ldbl_EGlpNumInitVar (ldbl_PROGRESS_THRESH);
00194   ldbl_EGlpNumInitVar (ldbl_PFEAS_TOLER);
00195   ldbl_EGlpNumInitVar (ldbl_BD_TOLER);
00196   ldbl_EGlpNumInitVar (ldbl_DFEAS_TOLER);
00197   ldbl_EGlpNumInitVar (ldbl_PIVOT_TOLER);
00198   ldbl_EGlpNumInitVar (ldbl_SZERO_TOLER);
00199   ldbl_EGlpNumInitVar (ldbl_PIVZ_TOLER);
00200   ldbl_EGlpNumInitVar (ldbl_OBJBND_TOLER);
00201   ldbl_EGlpNumInitVar (ldbl_ALTPIV_TOLER);
00202   ldbl_EGlpNumInitVar (ldbl_PARAM_MIN_DNORM);
00203   /* parameters that do depend on the tolerance to zero */
00204   ldbl_EGlpNumSet (ldbl_PARAM_MIN_DNORM, 4.5036e-9);
00205   ldbl_EGlpNumMultTo (ldbl_PARAM_MIN_DNORM, ldbl_epsLpNum);
00206   ldbl_EGlpNumSet (ldbl_PFEAS_TOLER, 4.5036e9);
00207   ldbl_EGlpNumMultTo (ldbl_PFEAS_TOLER, ldbl_epsLpNum);
00208   ldbl_EGlpNumSet (ldbl_BD_TOLER, 4.5036e8);
00209   ldbl_EGlpNumMultTo (ldbl_BD_TOLER, ldbl_epsLpNum);
00210   ldbl_EGlpNumSet (ldbl_DFEAS_TOLER, 4.5036e9);
00211   ldbl_EGlpNumMultTo (ldbl_DFEAS_TOLER, ldbl_epsLpNum);
00212   ldbl_EGlpNumSet (ldbl_PIVOT_TOLER, 4.5036e5);
00213   ldbl_EGlpNumMultTo (ldbl_PIVOT_TOLER, ldbl_epsLpNum);
00214   ldbl_EGlpNumSet (ldbl_SZERO_TOLER, 4.5036);
00215   ldbl_EGlpNumMultTo (ldbl_SZERO_TOLER, ldbl_epsLpNum);
00216   ldbl_EGlpNumSet (ldbl_PIVZ_TOLER, 4.5036e3);
00217   ldbl_EGlpNumMultTo (ldbl_PIVZ_TOLER, ldbl_epsLpNum);
00218   ldbl_EGlpNumSet (ldbl_OBJBND_TOLER, 4.5036e13);
00219   ldbl_EGlpNumMultTo (ldbl_OBJBND_TOLER, ldbl_epsLpNum);
00220   ldbl_EGlpNumSet (ldbl_ALTPIV_TOLER, 4.5036e7);
00221   ldbl_EGlpNumMultTo (ldbl_ALTPIV_TOLER, ldbl_epsLpNum);
00222   ldbl_EGlpNumSet (ldbl_PROGRESS_ZERO, 4.5036e8);
00223   ldbl_EGlpNumMultTo (ldbl_PROGRESS_ZERO, ldbl_epsLpNum);
00224   ldbl_EGlpNumSet (ldbl_PROGRESS_THRESH, 4.5036e10);
00225   ldbl_EGlpNumMultTo (ldbl_PROGRESS_THRESH, ldbl_epsLpNum);
00226 }
00227 
00228 /* ========================================================================= */
00229 void ldbl_ILLend ( void)
00230 {
00231   if (!ldbl___QSEX_SETUP)
00232     return;
00233   ldbl_EGlpNumClearVar (ldbl_PARAM_IBASIS_RPIVOT);
00234   ldbl_EGlpNumClearVar (ldbl_PARAM_IBASIS_RTRIANG);
00235   ldbl_EGlpNumClearVar (ldbl_PARAM_MIN_DNORM);
00236   ldbl_EGlpNumClearVar (ldbl_PFEAS_TOLER);
00237   ldbl_EGlpNumClearVar (ldbl_BD_TOLER);
00238   ldbl_EGlpNumClearVar (ldbl_DFEAS_TOLER);
00239   ldbl_EGlpNumClearVar (ldbl_PIVOT_TOLER);
00240   ldbl_EGlpNumClearVar (ldbl_SZERO_TOLER);
00241   ldbl_EGlpNumClearVar (ldbl_PIVZ_TOLER);
00242   ldbl_EGlpNumClearVar (ldbl_OBJBND_TOLER);
00243   ldbl_EGlpNumClearVar (ldbl_DBNDPIV_TOLER);
00244   ldbl_EGlpNumClearVar (ldbl_DBNDPIV_RATIO);
00245   ldbl_EGlpNumClearVar (ldbl_ALTPIV_TOLER);
00246   //ldbl_EGlpNumClearVar (DJZERO_TOLER);
00247   ldbl_EGlpNumClearVar (ldbl_PROGRESS_ZERO);  /*            1e-7 */
00248   ldbl_EGlpNumClearVar (ldbl_PROGRESS_THRESH);  /*          1e-5 */
00249   ldbl_EGlpNumClearVar (ldbl_CB_EPS);
00250   ldbl_EGlpNumClearVar (ldbl_CB_INF_RATIO);
00251   ldbl_EGlpNumClearVar (ldbl_CB_PRI_RLIMIT);
00252   ldbl_EGlpNumClearVar (ldbl_ILL_MAXDOUBLE);
00253   ldbl_EGlpNumClearVar (ldbl_ILL_MINDOUBLE);
00254   ldbl___QSEX_SETUP = 0;
00255 }
00256 
00257 ldbl_QSdata *ldbl_ILLread (
00258   ldbl_qsline_reader * file,
00259   const char *ldbl_fname,
00260   int isMps)
00261 {
00262   int rval = 0;
00263   ldbl_QSdata *p = 0;
00264   ldbl_ILLlpdata *lp;
00265   ldbl_rawlpdata rawlp;
00266 
00267   ILL_FAILfalse (file != NULL, NULL);
00268   ILL_FAILfalse (ldbl_fname != NULL, NULL);
00269 
00270   p = ldbl_QScreate_prob (ldbl_fname, QS_MIN);
00271   ILL_CHECKnull (p, NULL);
00272   ILL_IFFREE (p->qslp->probname, char);
00273 
00274   lp = p->qslp;
00275 
00276   ldbl_ILLinit_rawlpdata (&rawlp, file->error_collector);
00277   ldbl_ILLlpdata_init (lp);
00278 
00279   if (isMps != 0)
00280   {
00281     rval = ldbl_ILLread_mps (file, ldbl_fname, &rawlp);
00282   }
00283   else
00284   {
00285     rval = ldbl_ILLread_lp (file, ldbl_fname, &rawlp);
00286   }
00287   CHECKRVALG (rval, CLEANUP);
00288 
00289   rval = ldbl_ILLrawlpdata_to_lpdata (&rawlp, lp);
00290   CHECKRVALG (rval, CLEANUP);
00291 
00292 CLEANUP:
00293   ldbl_ILLfree_rawlpdata (&rawlp);
00294   if (rval != 0)
00295   {
00296     ldbl_QSfree_prob (p);
00297     p = 0;
00298   }
00299   return p;
00300 }
00301 
00302 void ldbl_ILLlpdata_init (
00303   ldbl_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 = ldbl_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     ldbl_ILLmatrix_init (&lp->A);
00323     ldbl_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 ldbl_ILLlpdata_free (
00348   ldbl_ILLlpdata * lp)
00349 {
00350   int i;
00351 
00352   if (lp)
00353   {
00354     ILL_IFFREE (lp->sense, char);
00355 
00356     ldbl_EGlpNumFreeArray (lp->obj);
00357     ldbl_EGlpNumFreeArray (lp->rhs);
00358     ldbl_EGlpNumFreeArray (lp->rangeval);
00359     ldbl_EGlpNumFreeArray (lp->lower);
00360     ldbl_EGlpNumFreeArray (lp->upper);
00361     ldbl_ILLmatrix_free (&lp->A);
00362     if (lp->rA)
00363     {
00364       ldbl_ILLlp_rows_clear (lp->rA);
00365       ILL_IFFREE (lp->rA, ldbl_ILLlp_rows);
00366     }
00367     ILL_IFFREE (lp->is_sos_mem, int);
00368     ILL_IFFREE (lp->refrowname, char);
00369 
00370     ldbl_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       ldbl_ILLlp_sinfo_free (lp->sinfo);
00398       ILL_IFFREE (lp->sinfo, ldbl_ILLlp_sinfo);
00399     }
00400     ldbl_ILLlpdata_init (lp);
00401   }
00402 }
00403 
00404 void ldbl_ILLlp_basis_init (
00405   ldbl_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 ldbl_ILLlp_basis_free (
00419   ldbl_ILLlp_basis * B)
00420 {
00421   if (B)
00422   {
00423     ILL_IFFREE (B->cstat, char);
00424     ILL_IFFREE (B->rstat, char);
00425 
00426     ldbl_EGlpNumFreeArray (B->rownorms);
00427     ldbl_EGlpNumFreeArray (B->colnorms);
00428     B->nstruct = 0;
00429     B->nrows = 0;
00430   }
00431 }
00432 
00433 int ldbl_ILLlp_basis_alloc (
00434   ldbl_ILLlp_basis * B,
00435   int nstruct,
00436   int nrows)
00437 {
00438   int rval = 0;
00439 
00440   ILL_FAILtrue (B == NULL, "ldbl_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     ldbl_ILLlp_basis_free (B);
00460   }
00461 
00462   EG_RETURN (rval);
00463 }
00464 
00465 void ldbl_ILLlp_cache_init (
00466   ldbl_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     ldbl_EGlpNumZero (C->val);
00478   }
00479 }
00480 
00481 void ldbl_ILLlp_cache_free (
00482   ldbl_ILLlp_cache * C)
00483 {
00484   if (C)
00485   {
00486     ldbl_EGlpNumFreeArray (C->x);
00487     ldbl_EGlpNumFreeArray (C->rc);
00488     ldbl_EGlpNumFreeArray (C->pi);
00489     ldbl_EGlpNumFreeArray (C->slack);
00490     C->nstruct = 0;
00491     C->nrows = 0;
00492     C->status = 0;
00493   }
00494 }
00495 
00496 int ldbl_ILLlp_cache_alloc (
00497   ldbl_ILLlp_cache * C,
00498   int nstruct,
00499   int nrows)
00500 {
00501   int rval = 0;
00502 
00503   ILL_FAILtrue (C == NULL, "ldbl_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 = ldbl_EGlpNumAllocArray (nstruct);
00511     C->rc = ldbl_EGlpNumAllocArray (nstruct);
00512   }
00513 
00514   if (nrows > 0)
00515   {
00516     C->pi = ldbl_EGlpNumAllocArray (nrows);
00517     C->slack = ldbl_EGlpNumAllocArray (nrows);
00518   }
00519 
00520 CLEANUP:
00521 
00522   if (rval)
00523   {
00524     ldbl_ILLlp_cache_free (C);
00525   }
00526 
00527   EG_RETURN (rval);
00528 }
00529 
00530 
00531 int ldbl_ILLlp_rows_init (
00532   ldbl_ILLlp_rows * lprows,
00533   ldbl_ILLlpdata * lp,
00534   int include_logicals)
00535 {
00536   int rval = 0;
00537   int i, k, st;
00538   int *beg, *cnt, *ind;
00539   long double *val;
00540   ldbl_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 = ldbl_EGlpNumAllocArray (lp->nzcount);
00596       }
00597       else
00598       {
00599         ILL_SAFE_MALLOC (lprows->rowind, lp->nzcount - lp->nrows, int);
00600 
00601         lprows->rowval = ldbl_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           ldbl_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     ldbl_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 ldbl_ILLlp_rows_clear (
00675   ldbl_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     ldbl_EGlpNumFreeArray (lprows->rowval);
00684   }
00685 }
00686 
00687 static int ldbl_wr_line (
00688   ldbl_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 ldbl_ILLprint_report (
00713   ldbl_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 = ldbl_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