/home/coin/SVN-release/Alps-1.2.2/CoinUtils/src/CoinPresolveMatrix.hpp

Go to the documentation of this file.
00001 /* $Id: CoinPresolveMatrix.hpp 1362 2010-12-19 16:56:55Z stefan $ */
00002 // Copyright (C) 2002, International Business Machines
00003 // Corporation and others.  All Rights Reserved.
00004 #ifndef CoinPresolveMatrix_H
00005 #define CoinPresolveMatrix_H
00006 
00007 #include "CoinPragma.hpp"
00008 #include "CoinPackedMatrix.hpp"
00009 #include "CoinMessage.hpp"
00010 #include "CoinTime.hpp"
00011 
00012 #include <cmath>
00013 #include <cassert>
00014 #include <cfloat>
00015 #include <cassert>
00016 
00025 #if defined(_MSC_VER)
00026 // Avoid MS Compiler problem in recognizing type to delete
00027 // by casting to type.
00028 #define deleteAction(array,type) delete [] ((type) array)
00029 #else
00030 #define deleteAction(array,type) delete [] array
00031 #endif
00032 
00037 const double ZTOLDP      = 1e-12;
00038 // But use a different one if we are doing doubletons etc
00039 const double ZTOLDP2      = 1e-10;
00040 //#define PRESOLVE_DEBUG 1
00041 // Debugging macros/functions
00042 #ifndef PRESOLVE_DETAIL
00043 #define PRESOLVE_DETAIL_PRINT(s) {}
00044 #else
00045 #define PRESOLVE_DETAIL_PRINT(s) s
00046 #endif
00047 #if PRESOLVE_DEBUG || PRESOLVE_CONSISTENCY
00048 #define PRESOLVE_STMT(s)        s
00049 #define PRESOLVEASSERT(x) \
00050   ((x) ? 1 : \
00051         ((std::cerr << "FAILED ASSERTION at line " \
00052                     << __LINE__ << ":  " #x "\n"), abort(), 0))
00053 
00054 inline void DIE(const char *s)  { std::cout<<s; abort(); }
00055 
00056 // This code is used in [cr]done for columns and rows that are present in
00057 // the presolved system.
00058 #define PRESENT_IN_REDUCED      '\377'
00059 
00060 #else
00061 
00062 #define PRESOLVEASSERT(x) {} 
00063 #define PRESOLVE_STMT(s) {}
00064 
00065 inline void DIE(const char *)   {}
00066 
00067 #endif
00068 
00069 inline int ALIGN(int n, int m)  { return (((n + m - 1) / m) * m); }
00070 inline int ALIGN_DOUBLE(int n)  { return ALIGN(n,sizeof(double)); }
00071 
00072 // Plus infinity
00073 #ifndef COIN_DBL_MAX
00074 #define COIN_DBL_MAX DBL_MAX
00075 #endif
00076 #define PRESOLVE_INF COIN_DBL_MAX
00077 
00078 class CoinPostsolveMatrix;
00079 
00080 // Note 77
00081 // "Members and bases are constructed in order of declaration
00082 //  in the class and destroyed in the reverse order."  C++PL 3d Ed. p. 307
00083 //
00084 // That's why I put integer members (such as ncols) before the array members;
00085 // I like to use those integer values during initialization.
00086 // NOT ANYMORE
00087 
00137 class CoinPresolveAction
00138 {
00139  public:
00146   static void throwCoinError(const char *error, const char *ps_routine)
00147   { throw CoinError(error, ps_routine, "CoinPresolve"); } 
00148 
00149 
00154   const CoinPresolveAction *next;
00155   
00161   CoinPresolveAction(const CoinPresolveAction *next) : next(next) {}
00163   inline void setNext(const CoinPresolveAction *nextAction)
00164   { next = nextAction;}
00165 
00170   virtual const char *name() const = 0;
00171 
00175   virtual void postsolve(CoinPostsolveMatrix *prob) const = 0;
00176 
00178   virtual ~CoinPresolveAction() {}
00179 };
00180 
00181 /*
00182   These are needed for OSI-aware constructors associated with
00183   CoinPrePostsolveMatrix, CoinPresolveMatrix, and CoinPostsolveMatrix.
00184 */
00185   class ClpSimplex;
00186   class OsiSolverInterface;
00187 
00188 /*
00189   CoinWarmStartBasis is required for methods in CoinPrePostsolveMatrix
00190   that accept/return a CoinWarmStartBasis object.
00191 */
00192   class CoinWarmStartBasis ;
00193 
00244 class CoinPrePostsolveMatrix
00245 {
00246  public:
00247 
00257   CoinPrePostsolveMatrix(int ncols_alloc, int nrows_alloc,
00258                          CoinBigIndex nelems_alloc) ;
00259 
00264   CoinPrePostsolveMatrix(const OsiSolverInterface * si,
00265                         int ncols_,
00266                         int nrows_,
00267                         CoinBigIndex nelems_);
00268 
00273   CoinPrePostsolveMatrix(const ClpSimplex * si,
00274                         int ncols_,
00275                         int nrows_,
00276                         CoinBigIndex nelems_,
00277                          double bulkRatio);
00278 
00280   ~CoinPrePostsolveMatrix();
00282 
00292   enum Status {
00293     isFree = 0x00,
00294     basic = 0x01,
00295     atUpperBound = 0x02,
00296     atLowerBound = 0x03,
00297     superBasic = 0x04
00298   };
00299 
00306   
00308   inline void setRowStatus(int sequence, Status status)
00309   {
00310     unsigned char & st_byte = rowstat_[sequence];
00311     st_byte = static_cast<unsigned char>(st_byte & (~7)) ;
00312     st_byte = static_cast<unsigned char>(st_byte | status) ;
00313   }
00315   inline Status getRowStatus(int sequence) const
00316   {return static_cast<Status> (rowstat_[sequence]&7);}
00318   inline bool rowIsBasic(int sequence) const
00319   {return (static_cast<Status> (rowstat_[sequence]&7)==basic);}
00321   inline void setColumnStatus(int sequence, Status status)
00322   {
00323     unsigned char & st_byte = colstat_[sequence];
00324     st_byte = static_cast<unsigned char>(st_byte & (~7)) ;
00325     st_byte = static_cast<unsigned char>(st_byte | status) ;
00326 
00327 #   ifdef PRESOLVE_DEBUG
00328     switch (status)
00329     { case isFree:
00330       { if (clo_[sequence] > -PRESOLVE_INF || cup_[sequence] < PRESOLVE_INF)
00331         { std::cout << "Bad status: Var " << sequence
00332                     << " isFree, lb = " << clo_[sequence]
00333                     << ", ub = " << cup_[sequence] << std::endl ; }
00334         break ; }
00335       case basic:
00336       { break ; }
00337       case atUpperBound:
00338       { if (cup_[sequence] >= PRESOLVE_INF)
00339         { std::cout << "Bad status: Var " << sequence
00340                     << " atUpperBound, lb = " << clo_[sequence]
00341                     << ", ub = " << cup_[sequence] << std::endl ; }
00342         break ; }
00343       case atLowerBound:
00344       { if (clo_[sequence] <= -PRESOLVE_INF)
00345         { std::cout << "Bad status: Var " << sequence
00346                     << " atLowerBound, lb = " << clo_[sequence]
00347                     << ", ub = " << cup_[sequence] << std::endl ; }
00348         break ; }
00349       case superBasic:
00350       { if (clo_[sequence] <= -PRESOLVE_INF && cup_[sequence] >= PRESOLVE_INF)
00351         { std::cout << "Bad status: Var " << sequence
00352                     << " superBasic, lb = " << clo_[sequence]
00353                     << ", ub = " << cup_[sequence] << std::endl ; }
00354         break ; }
00355       default:
00356       { assert(false) ;
00357         break ; } }
00358 #   endif
00359   }
00361   inline Status getColumnStatus(int sequence) const
00362   {return static_cast<Status> (colstat_[sequence]&7);}
00364   inline bool columnIsBasic(int sequence) const
00365   {return (static_cast<Status> (colstat_[sequence]&7)==basic);}
00369   void setRowStatusUsingValue(int iRow);
00373   void setColumnStatusUsingValue(int iColumn);
00375   void setStructuralStatus(const char *strucStatus, int lenParam) ;
00377   void setArtificialStatus(const char *artifStatus, int lenParam) ;
00379   void setStatus(const CoinWarmStartBasis *basis) ;
00381   CoinWarmStartBasis *getStatus() ;
00385   const char *columnStatusString(int j) const ;
00389   const char *rowStatusString(int i) const ;
00391 
00399 
00400   void setObjOffset(double offset) ;
00405   void setObjSense(double objSense) ;
00407   void setPrimalTolerance(double primTol) ;
00409   void setDualTolerance(double dualTol) ;
00411   void setColLower(const double *colLower, int lenParam) ;
00413   void setColUpper(const double *colUpper, int lenParam) ;
00415   void setColSolution(const double *colSol, int lenParam) ;
00417   void setCost(const double *cost, int lenParam) ;
00419   void setReducedCost(const double *redCost, int lenParam) ;
00421   void setRowLower(const double *rowLower, int lenParam) ;
00423   void setRowUpper(const double *rowUpper, int lenParam) ;
00425   void setRowPrice(const double *rowSol, int lenParam) ;
00427   void setRowActivity(const double *rowAct, int lenParam) ;
00429 
00432 
00433   inline int getNumCols()
00434   { return (ncols_) ; } 
00436   inline int getNumRows()
00437   { return (nrows_) ; } 
00439   inline int getNumElems()
00440   { return (nelems_) ; } 
00442   inline const CoinBigIndex *getColStarts() const
00443   { return (mcstrt_) ; } 
00445   inline const int *getColLengths() const
00446   { return (hincol_) ; } 
00448   inline const int *getRowIndicesByCol() const
00449   { return (hrow_) ; } 
00451   inline const double *getElementsByCol() const
00452   { return (colels_) ; } 
00454   inline const double *getColLower() const
00455   { return (clo_) ; } 
00457   inline const double *getColUpper() const
00458   { return (cup_) ; } 
00460   inline const double *getCost() const
00461   { return (cost_) ; } 
00463   inline const double *getRowLower() const
00464   { return (rlo_) ; } 
00466   inline const double *getRowUpper() const
00467   { return (rup_) ; } 
00469   inline const double *getColSolution() const
00470   { return (sol_) ; }
00472   inline const double *getRowActivity() const
00473   { return (acts_) ; }
00475   inline const double *getRowPrice() const
00476   { return (rowduals_) ; }
00478   inline const double *getReducedCost() const
00479   { return (rcosts_) ; }
00481   inline int countEmptyCols()
00482   { int empty = 0 ;
00483     for (int i = 0 ; i < ncols_ ; i++) if (hincol_[i] == 0) empty++ ;
00484     return (empty) ; }
00486 
00487 
00490 
00491   inline CoinMessageHandler *messageHandler() const 
00492   { return handler_; }
00498   inline void setMessageHandler(CoinMessageHandler *handler)
00499   { if (defaultHandler_ == true)
00500     { delete handler_ ;
00501       defaultHandler_ = false ; }
00502     handler_ = handler ; }
00504   inline CoinMessages messages() const 
00505   { return messages_; }
00507 
00517 
00519   int ncols_;
00521   int nrows_;
00523   CoinBigIndex nelems_;
00524 
00526   int ncols0_;
00528   int nrows0_ ;
00530   CoinBigIndex nelems0_ ;
00539   CoinBigIndex bulk0_ ;
00541   double bulkRatio_;
00543 
00552 
00553   CoinBigIndex *mcstrt_;
00555   int *hincol_;
00557   int *hrow_;
00559   double *colels_;
00560 
00562   double *cost_;
00564   double originalOffset_;
00565 
00567   double *clo_;
00569   double *cup_;
00570 
00572   double *rlo_;
00574   double *rup_;
00575 
00577   int * originalColumn_;
00579   int * originalRow_;
00580 
00582   double ztolzb_;
00584   double ztoldj_;
00585 
00587   double maxmin_;
00589 
00610   double *sol_;
00616   double *rowduals_;
00622   double *acts_;
00628   double *rcosts_;
00629 
00636   unsigned char *colstat_;
00637 
00644   unsigned char *rowstat_;
00646 
00655 
00656   CoinMessageHandler *handler_; 
00658   bool defaultHandler_;
00660   CoinMessage messages_; 
00662 
00663 };
00664 
00665 
00690 class presolvehlink
00691 { public:
00692   int pre, suc;
00693 } ;
00694 
00695 #define NO_LINK -66666666
00696 
00702 inline void PRESOLVE_REMOVE_LINK(presolvehlink *link, int i)
00703 { 
00704   int ipre = link[i].pre;
00705   int isuc = link[i].suc;
00706   if (ipre >= 0) {
00707     link[ipre].suc = isuc;
00708   }
00709   if (isuc >= 0) {
00710     link[isuc].pre = ipre;
00711   }
00712   link[i].pre = NO_LINK, link[i].suc = NO_LINK;
00713 }
00714 
00720 inline void PRESOLVE_INSERT_LINK(presolvehlink *link, int i, int j)
00721 {
00722   int isuc = link[j].suc;
00723   link[j].suc = i;
00724   link[i].pre = j;
00725   if (isuc >= 0) {
00726     link[isuc].pre = i;
00727   }
00728   link[i].suc = isuc;
00729 }
00730 
00742 inline void PRESOLVE_MOVE_LINK(presolvehlink *link, int i, int j)
00743 { 
00744   int ipre = link[i].pre;
00745   int isuc = link[i].suc;
00746   if (ipre >= 0) {
00747     link[ipre].suc = j;
00748   }
00749   if (isuc >= 0) {
00750     link[isuc].pre = j;
00751   }
00752   link[i].pre = NO_LINK, link[i].suc = NO_LINK;
00753 }
00754 
00755 
00777 class CoinPresolveMatrix : public CoinPrePostsolveMatrix
00778 {
00779  public:
00780 
00787   CoinPresolveMatrix(int ncols_alloc, int nrows_alloc,
00788                      CoinBigIndex nelems_alloc) ;
00789 
00794   CoinPresolveMatrix(int ncols0,
00795                     double maxmin,
00796                     // end prepost members
00797 
00798                     ClpSimplex * si,
00799 
00800                     // rowrep
00801                     int nrows,
00802                     CoinBigIndex nelems,
00803                  bool doStatus,
00804                  double nonLinearVariable,
00805                      double bulkRatio);
00806 
00808   void update_model(ClpSimplex * si,
00809                             int nrows0,
00810                             int ncols0,
00811                             CoinBigIndex nelems0);
00816   CoinPresolveMatrix(int ncols0,
00817                      double maxmin,
00818                      // end prepost members
00819                      OsiSolverInterface * si,
00820                      // rowrep
00821                      int nrows,
00822                      CoinBigIndex nelems,
00823                      bool doStatus,
00824                      double nonLinearVariable,
00825                      const char * prohibited,
00826                      const char * rowProhibited=NULL);
00827 
00829   void update_model(OsiSolverInterface * si,
00830                             int nrows0,
00831                             int ncols0,
00832                             CoinBigIndex nelems0);
00833 
00835   ~CoinPresolveMatrix();
00836 
00842   friend void assignPresolveToPostsolve (CoinPresolveMatrix *&preObj) ;
00843 
00852   void setMatrix(const CoinPackedMatrix *mtx) ;
00853 
00855   inline int countEmptyRows()
00856   { int empty = 0 ;
00857     for (int i = 0 ; i < nrows_ ; i++) if (hinrow_[i] == 0) empty++ ;
00858     return (empty) ; }
00859 
00865   inline void setVariableType(int i, int variableType)
00866   { if (integerType_ == 0) integerType_ = new unsigned char [ncols0_] ;
00867     integerType_[i] = static_cast<unsigned char>(variableType) ; }
00868 
00874   void setVariableType(const unsigned char *variableType, int lenParam) ;
00875 
00881   void setVariableType (bool allIntegers, int lenParam) ;
00882 
00884   inline void setAnyInteger (bool anyInteger = true)
00885   { anyInteger_ = anyInteger ; }
00887 
00891 
00893   inline const CoinBigIndex *getRowStarts() const
00894   { return (mrstrt_) ; }
00896   inline const int *getColIndicesByRow() const
00897   { return (hcol_) ; }
00899   inline const double *getElementsByRow() const
00900   { return (rowels_) ; }
00901 
00907   inline bool isInteger (int i) const
00908   { if (integerType_ == 0)
00909     { return (anyInteger_) ; }
00910     else
00911     if (integerType_[i] == 1)
00912     { return (true) ; }
00913     else
00914     { return (false) ; } }
00915 
00920   inline bool anyInteger () const
00921   { return (anyInteger_) ; }
00923   inline int presolveOptions() const
00924   { return presolveOptions_;}
00926   inline void setPresolveOptions(int value)
00927   { presolveOptions_=value;}
00929 
00937 
00938   presolvehlink *clink_;
00940   presolvehlink *rlink_;
00942 
00944   double dobias_;
00945 
00947   inline void change_bias(double change_amount)
00948   {
00949     dobias_ += change_amount;
00950   #if PRESOLVE_DEBUG
00951     assert(fabs(change_amount)<1.0e50);
00952   #endif
00953     if (change_amount)
00954       PRESOLVE_STMT(printf("changing bias by %g to %g\n",
00955                             change_amount, dobias_));
00956   }
00957 
00966 
00967   CoinBigIndex *mrstrt_;
00969   int *hinrow_;
00971   double *rowels_;
00973   int *hcol_;
00975 
00977   unsigned char *integerType_;
00983   bool anyInteger_ ;
00985   bool tuning_;
00987   void statistics();
00989   double startTime_;
00990 
00992   double feasibilityTolerance_;
00994   inline double feasibilityTolerance()
00995   { return (feasibilityTolerance_) ; }
00997   inline void setFeasibilityTolerance (double val)
00998   { feasibilityTolerance_ = val ; }
00999 
01005   int status_;
01007   inline int status()
01008   { return (status_) ; }
01010   inline void setStatus(int status)
01011   { status_ = (status&0x3) ; }
01012 
01018   int pass_;
01020   inline void setPass (int pass = 0)
01021   { pass_ = pass ; }
01022 
01027   int maxSubstLevel_;
01029   inline void setMaximumSubstitutionLevel (int level)
01030   { maxSubstLevel_ = level ; }
01031 
01032 
01055   unsigned char * colChanged_;
01057   int * colsToDo_;
01059   int numberColsToDo_;
01061   int * nextColsToDo_;
01063   int numberNextColsToDo_;
01064 
01074   unsigned char * rowChanged_;
01076   int * rowsToDo_;
01078   int numberRowsToDo_;
01080   int * nextRowsToDo_;
01082   int numberNextRowsToDo_;
01091   int presolveOptions_;
01097   bool anyProhibited_;
01099   int * usefulRowInt_;
01101   double * usefulRowDouble_;
01103   int * usefulColumnInt_;
01105   double * usefulColumnDouble_;
01107   double * randomNumber_;
01109   int * infiniteUp_;
01111   double * sumUp_;
01113   int * infiniteDown_;
01115   double * sumDown_;
01117 
01120 
01126   void initColsToDo () ;
01127 
01133   int stepColsToDo () ;
01134 
01136   inline int numberColsToDo()
01137   { return (numberColsToDo_) ; }
01138 
01140   inline bool colChanged(int i) const {
01141     return (colChanged_[i]&1)!=0;
01142   }
01144   inline void unsetColChanged(int i) {
01145     colChanged_[i] = static_cast<unsigned char>(colChanged_[i] & (~1)) ;
01146   }
01148   inline void setColChanged(int i) {
01149     colChanged_[i] = static_cast<unsigned char>(colChanged_[i] | (1)) ;
01150   }
01152   inline void addCol(int i) {
01153     if ((colChanged_[i]&1)==0) {
01154       colChanged_[i] = static_cast<unsigned char>(colChanged_[i] | (1)) ;
01155       nextColsToDo_[numberNextColsToDo_++] = i;
01156     }
01157   }
01159   inline bool colProhibited(int i) const {
01160     return (colChanged_[i]&2)!=0;
01161   }
01168   inline bool colProhibited2(int i) const {
01169     if (!anyProhibited_)
01170       return false;
01171     else
01172       return (colChanged_[i]&2)!=0;
01173   }
01175   inline void setColProhibited(int i) {
01176     colChanged_[i] = static_cast<unsigned char>(colChanged_[i] | (2)) ;
01177   }
01183   inline bool colUsed(int i) const {
01184     return (colChanged_[i]&4)!=0;
01185   }
01187   inline void setColUsed(int i) {
01188     colChanged_[i] = static_cast<unsigned char>(colChanged_[i] | (4)) ;
01189   }
01191   inline void unsetColUsed(int i) {
01192     colChanged_[i] = static_cast<unsigned char>(colChanged_[i] & (~4)) ;
01193   }
01194 
01200   void initRowsToDo () ;
01201 
01207   int stepRowsToDo () ;
01208 
01210   inline int numberRowsToDo()
01211   { return (numberRowsToDo_) ; }
01212 
01214   inline bool rowChanged(int i) const {
01215     return (rowChanged_[i]&1)!=0;
01216   }
01218   inline void unsetRowChanged(int i) {
01219     rowChanged_[i] = static_cast<unsigned char>(rowChanged_[i] & (~1)) ;
01220   }
01222   inline void setRowChanged(int i) {
01223     rowChanged_[i] = static_cast<unsigned char>(rowChanged_[i] | (1)) ;
01224   }
01226   inline void addRow(int i) {
01227     if ((rowChanged_[i]&1)==0) {
01228       rowChanged_[i] = static_cast<unsigned char>(rowChanged_[i] | (1)) ;
01229       nextRowsToDo_[numberNextRowsToDo_++] = i;
01230     }
01231   }
01233   inline bool rowProhibited(int i) const {
01234     return (rowChanged_[i]&2)!=0;
01235   }
01242   inline bool rowProhibited2(int i) const {
01243     if (!anyProhibited_)
01244       return false;
01245     else
01246       return (rowChanged_[i]&2)!=0;
01247   }
01249   inline void setRowProhibited(int i) {
01250     rowChanged_[i] = static_cast<unsigned char>(rowChanged_[i] | (2)) ;
01251   }
01257   inline bool rowUsed(int i) const {
01258     return (rowChanged_[i]&4)!=0;
01259   }
01261   inline void setRowUsed(int i) {
01262     rowChanged_[i] = static_cast<unsigned char>(rowChanged_[i] | (4)) ;
01263   }
01265   inline void unsetRowUsed(int i) {
01266     rowChanged_[i] = static_cast<unsigned char>(rowChanged_[i] & (~4)) ;
01267   }
01268 
01269 
01271   inline bool anyProhibited() const
01272   { return anyProhibited_;}
01274   inline void setAnyProhibited(bool val = true)
01275   { anyProhibited_ = val ; }
01278   int recomputeSums(int iRow);
01280   int initializeStuff();
01282   void deleteStuff();
01284 
01285 };
01286 
01311 class CoinPostsolveMatrix : public CoinPrePostsolveMatrix
01312 {
01313  public:
01314 
01321   CoinPostsolveMatrix(int ncols_alloc, int nrows_alloc,
01322                       CoinBigIndex nelems_alloc) ;
01323 
01324 
01329   CoinPostsolveMatrix(ClpSimplex * si,
01330 
01331                    int ncols0,
01332                    int nrows0,
01333                    CoinBigIndex nelems0,
01334                      
01335                    double maxmin_,
01336                    // end prepost members
01337 
01338                    double *sol,
01339                    double *acts,
01340 
01341                    unsigned char *colstat,
01342                    unsigned char *rowstat);
01343 
01348   CoinPostsolveMatrix(OsiSolverInterface * si,
01349 
01350                    int ncols0,
01351                    int nrows0,
01352                    CoinBigIndex nelems0,
01353                      
01354                    double maxmin_,
01355                    // end prepost members
01356 
01357                    double *sol,
01358                    double *acts,
01359 
01360                    unsigned char *colstat,
01361                    unsigned char *rowstat);
01362 
01373   void assignPresolveToPostsolve (CoinPresolveMatrix *&preObj) ;
01374 
01376   ~CoinPostsolveMatrix();
01377 
01389 
01391   CoinBigIndex free_list_;
01393   int maxlink_;
01398   CoinBigIndex *link_;
01399 
01401 
01409   char *cdone_;
01410   char *rdone_;
01412 
01414   void check_nbasic();
01415 
01416 };
01417 
01418 
01419 #define PRESOLVEFINITE(n)       (-PRESOLVE_INF < (n) && (n) < PRESOLVE_INF)
01420 
01427 
01432 void presolve_make_memlists(/*CoinBigIndex *starts,*/ int *lengths,
01433                             presolvehlink *link, int n);
01434 
01442 bool presolve_expand_major(CoinBigIndex *majstrts, double *majels,
01443                            int *minndxs, int *majlens,
01444                            presolvehlink *majlinks, int nmaj, int k) ;
01445 
01451 inline bool presolve_expand_col(CoinBigIndex *mcstrt, double *colels,
01452                                 int *hrow, int *hincol,
01453                                 presolvehlink *clink, int ncols, int colx)
01454 { return presolve_expand_major(mcstrt,colels,
01455                                hrow,hincol,clink,ncols,colx) ; }
01456 
01462 inline bool presolve_expand_row(CoinBigIndex *mrstrt, double *rowels,
01463                                 int *hcol, int *hinrow,
01464                                 presolvehlink *rlink, int nrows, int rowx)
01465 { return presolve_expand_major(mrstrt,rowels,
01466                                hcol,hinrow,rlink,nrows,rowx) ; }
01467 
01468 
01477 inline CoinBigIndex presolve_find_minor(int tgt, CoinBigIndex ks, CoinBigIndex ke,
01478                                  const int *minndxs)
01479 { CoinBigIndex k ;
01480   for (k = ks ; k < ke ; k++)
01481 #ifndef NDEBUG
01482   { if (minndxs[k] == tgt)
01483       return (k) ; }
01484   DIE("FIND_MINOR") ;
01485 
01486   abort () ; return -1;
01487 #else
01488   { if (minndxs[k] == tgt)
01489       break ; }
01490   return (k) ;
01491 #endif
01492 }
01493 
01500 inline CoinBigIndex presolve_find_row(int row, CoinBigIndex kcs,
01501                                       CoinBigIndex kce, const int *hrow)
01502 { return presolve_find_minor(row,kcs,kce,hrow) ; }
01503 
01510 inline CoinBigIndex presolve_find_col(int col, CoinBigIndex krs,
01511                                       CoinBigIndex kre, const int *hcol)
01512 { return presolve_find_minor(col,krs,kre,hcol) ; }
01513 
01514 
01523 CoinBigIndex presolve_find_minor1(int tgt, CoinBigIndex ks, CoinBigIndex ke,
01524                                   const int *minndxs);
01525 
01532 inline CoinBigIndex presolve_find_row1(int row, CoinBigIndex kcs,
01533                                        CoinBigIndex kce, const int *hrow)
01534 { return presolve_find_minor1(row,kcs,kce,hrow) ; } 
01535 
01542 inline CoinBigIndex presolve_find_col1(int col, CoinBigIndex krs,
01543                                        CoinBigIndex kre, const int *hcol)
01544 { return presolve_find_minor1(col,krs,kre,hcol) ; } 
01545 
01554 CoinBigIndex presolve_find_minor2(int tgt, CoinBigIndex ks, int majlen,
01555                                   const int *minndxs,
01556                                   const CoinBigIndex *majlinks) ;
01557 
01565 inline CoinBigIndex presolve_find_row2(int row, CoinBigIndex kcs, int collen,
01566                                        const int *hrow,
01567                                        const CoinBigIndex *clinks)
01568 { return presolve_find_minor2(row,kcs,collen,hrow,clinks) ; }
01569 
01578 CoinBigIndex presolve_find_minor3(int tgt, CoinBigIndex ks, int majlen,
01579                                   const int *minndxs,
01580                                   const CoinBigIndex *majlinks) ;
01581 
01589 inline CoinBigIndex presolve_find_row3(int row, CoinBigIndex kcs, int collen,
01590                                        const int *hrow,
01591                                        const CoinBigIndex *clinks)
01592 { return presolve_find_minor3(row,kcs,collen,hrow,clinks) ; }
01593 
01603 inline void presolve_delete_from_major(int majndx, int minndx,
01604                                 const CoinBigIndex *majstrts,
01605                                 int *majlens, int *minndxs, double *els) 
01606 { CoinBigIndex ks = majstrts[majndx] ;
01607   CoinBigIndex ke = ks + majlens[majndx] ;
01608 
01609   CoinBigIndex kmi = presolve_find_minor(minndx,ks,ke,minndxs) ;
01610 
01611   minndxs[kmi] = minndxs[ke-1] ;
01612   els[kmi] = els[ke-1] ;
01613   majlens[majndx]-- ;
01614   
01615   return ; }
01616 // Delete all marked from major (and zero marked)
01617 inline void presolve_delete_many_from_major(int majndx, char * marked,
01618                                 const CoinBigIndex *majstrts,
01619                                 int *majlens, int *minndxs, double *els) 
01620 { 
01621   CoinBigIndex ks = majstrts[majndx] ;
01622   CoinBigIndex ke = ks + majlens[majndx] ;
01623   CoinBigIndex put=ks;
01624   for (CoinBigIndex k=ks;k<ke;k++) {
01625     int iMinor = minndxs[k];
01626     if (!marked[iMinor]) {
01627       minndxs[put]=iMinor;
01628       els[put++]=els[k];
01629     } else {
01630       marked[iMinor]=0;
01631     }
01632   } 
01633   majlens[majndx] = put-ks ;
01634   return ;
01635 }
01636 
01647 inline void presolve_delete_from_col(int row, int col,
01648                                      const CoinBigIndex *mcstrt,
01649                                      int *hincol, int *hrow, double *colels)
01650 { presolve_delete_from_major(col,row,mcstrt,hincol,hrow,colels) ; }
01651 
01662 inline void presolve_delete_from_row(int row, int col,
01663                                      const CoinBigIndex *mrstrt,
01664                                      int *hinrow, int *hcol, double *rowels)
01665 { presolve_delete_from_major(row,col,mrstrt,hinrow,hcol,rowels) ; }
01666 
01677 void presolve_delete_from_major2 (int majndx, int minndx,
01678                                   CoinBigIndex *majstrts, int *majlens,
01679                                   int *minndxs, /*double *els,*/ int *majlinks,
01680                                    CoinBigIndex *free_listp) ;
01681 
01692 inline void presolve_delete_from_col2(int row, int col, CoinBigIndex *mcstrt,
01693                                       int *hincol, int *hrow,
01694                                       /*double *colels,*/ int *clinks,
01695                                       CoinBigIndex *free_listp)
01696 { presolve_delete_from_major2(col,row,mcstrt,hincol,hrow,/*colels,*/clinks,
01697                               free_listp) ; }
01698 
01700 
01706 
01718 double *presolve_dupmajor(const double *elems, const int *indices,
01719                           int length, CoinBigIndex offset, int tgt = -1);
01721 void coin_init_random_vec(double *work, int n);
01723 
01724 
01725 #endif

Generated on Fri Jan 7 03:09:11 2011 by  doxygen 1.4.7