/home/coin/SVN-release/Cbc-1.1.1/CoinUtils/src/CoinModelUseful.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2005, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #ifndef CoinModelUseful_H
00004 #define CoinModelUseful_H
00005 
00006 
00007 #include <cmath>
00008 #include <cassert>
00009 #include <cfloat>
00010 #include <string>
00011 #include <cstdio>
00012 #include <iostream>
00013 
00014 
00015 #include "CoinPragma.hpp"
00016 #include "CoinFinite.hpp"
00017 
00025 
00026 
00027 class CoinModelLink {
00028   
00029 public:
00033    CoinModelLink();
00035    ~CoinModelLink();
00037 
00041    CoinModelLink(const CoinModelLink&);
00043    CoinModelLink& operator=(const CoinModelLink&);
00045 
00048 
00049   inline int row() const
00050   { return row_;};
00052   inline int column() const
00053   { return column_;};
00055   inline double value() const
00056   { return value_;};
00058   inline double element() const
00059   { return value_;};
00061   inline int position() const
00062   { return position_;};
00064   inline bool onRow() const
00065   { return onRow_;};
00067   inline void setRow(int row)
00068   { row_=row;};
00070   inline void setColumn(int column)
00071   { column_=column;};
00073   inline void setValue(double value)
00074   { value_=value;};
00076   inline void setElement(double value)
00077   { value_=value;};
00079   inline void setPosition(int position)
00080   { position_=position;};
00082   inline void setOnRow(bool onRow)
00083   { onRow_=onRow;};
00085 
00086 private:
00089 
00090   int row_;
00092   int column_;
00094   double value_;
00096   int position_;
00098   bool onRow_;
00100 };
00101 
00103 // for specifying triple
00104 typedef struct {
00105   unsigned int string:1; // nonzero if string
00106   unsigned int row:31;
00107   //CoinModelRowIndex row;
00108   int column;
00109   double value; // If string then index into strings
00110 } CoinModelTriple;
00111 
00113 // for hashing
00114 typedef struct {
00115   int index, next;
00116 } CoinModelHashLink;
00117 
00118 /* Function type.  */
00119 typedef double (*func_t) (double);
00120 
00122 /* Data type for links in the chain of symbols.  */
00123 struct symrec
00124 {
00125   char *name;  /* name of symbol */
00126   int type;    /* type of symbol: either VAR or FNCT */
00127   union
00128   {
00129     double var;      /* value of a VAR */
00130     func_t fnctptr;  /* value of a FNCT */
00131   } value;
00132   struct symrec *next;  /* link field */
00133 };
00134      
00135 typedef struct symrec symrec;
00136 
00137 typedef struct {
00138   symrec * symtable;
00139   char * symbuf;
00140   int length;
00141   double unsetValue;
00142 } CoinYacc;
00143 class CoinModelHash {
00144   
00145 public:
00149   CoinModelHash();
00151   ~CoinModelHash();
00153   
00157   CoinModelHash(const CoinModelHash&);
00159   CoinModelHash& operator=(const CoinModelHash&);
00161 
00164 
00165   void resize(int maxItems,bool forceReHash=false);
00167   inline int numberItems() const
00168   { return numberItems_;};
00170   void setNumberItems(int number);
00172   inline int maximumItems() const
00173   { return maximumItems_;};
00175   inline const char *const * names() const
00176   { return names_;};
00178 
00181 
00182   int hash(const char * name) const;
00184   void addHash(int index, const char * name);
00186   void deleteHash(int index);
00188   const char * name(int which) const;
00190   char * getName(int which) const;
00192   void setName(int which,char * name ) ;
00193 private:
00195   int hashValue(const char * name) const;
00196 public:
00198 private:
00201 
00202   char ** names_;
00204   CoinModelHashLink * hash_;
00206   int numberItems_;
00208   int maximumItems_;
00210   int lastSlot_;
00212 };
00214 class CoinModelHash2 {
00215   
00216 public:
00220   CoinModelHash2();
00222   ~CoinModelHash2();
00224   
00228   CoinModelHash2(const CoinModelHash2&);
00230   CoinModelHash2& operator=(const CoinModelHash2&);
00232 
00235 
00236   void resize(int maxItems, const CoinModelTriple * triples,bool forceReHash=false);
00238   inline int numberItems() const
00239   { return numberItems_;};
00241   void setNumberItems(int number);
00243   inline int maximumItems() const
00244   { return maximumItems_;};
00246 
00249 
00250   int hash(int row, int column, const CoinModelTriple * triples) const;
00252   void addHash(int index, int row, int column, const CoinModelTriple * triples);
00254   void deleteHash(int index, int row, int column);
00255 private:
00257   int hashValue(int row, int column) const;
00258 public:
00260 private:
00263 
00264   CoinModelHashLink * hash_;
00266   int numberItems_;
00268   int maximumItems_;
00270   int lastSlot_;
00272 };
00273 class CoinModelLinkedList {
00274   
00275 public:
00279   CoinModelLinkedList();
00281   ~CoinModelLinkedList();
00283   
00287   CoinModelLinkedList(const CoinModelLinkedList&);
00289   CoinModelLinkedList& operator=(const CoinModelLinkedList&);
00291 
00296   void resize(int maxMajor,int maxElements);
00300   void create(int maxMajor,int maxElements,
00301               int numberMajor, int numberMinor,
00302               int type,
00303               int numberElements, const CoinModelTriple * triples);
00305   inline int numberMajor() const
00306   { return numberMajor_;};
00308   inline int maximumMajor() const
00309   { return maximumMajor_;};
00311   inline int numberElements() const
00312   { return numberElements_;};
00314   inline int maximumElements() const
00315   { return maximumElements_;};
00317   inline int firstFree() const
00318   { return first_[maximumMajor_];};
00320   inline int lastFree() const
00321   { return last_[maximumMajor_];};
00323   inline int first(int which) const
00324   { return first_[which];};
00326   inline int last(int which) const
00327   { return last_[which];};
00329   inline const int * next() const
00330   { return next_;};
00332   inline const int * previous() const
00333   { return previous_;};
00335 
00341   int addEasy(int majorIndex, int numberOfElements, const int * indices,
00342               const double * elements, CoinModelTriple * triples,
00343               CoinModelHash2 & hash);
00346   void addHard(int minorIndex, int numberOfElements, const int * indices,
00347                const double * elements, CoinModelTriple * triples,
00348                CoinModelHash2 & hash);
00352   void addHard(int first, const CoinModelTriple * triples,
00353                int firstFree, int lastFree,const int * nextOther);
00356   void deleteSame(int which, CoinModelTriple * triples,
00357                  CoinModelHash2 & hash, bool zapTriples);
00361   void updateDeleted(int which, CoinModelTriple * triples,
00362                      CoinModelLinkedList & otherList);
00365   void deleteRowOne(int position, CoinModelTriple * triples,
00366                  CoinModelHash2 & hash);
00370   void updateDeletedOne(int position, const CoinModelTriple * triples);
00372   void fill(int first,int last);
00374   void synchronize(CoinModelLinkedList & other);
00376   void validateLinks(const CoinModelTriple * triples) const;
00378 private:
00381 
00382   int * previous_;
00384   int * next_;
00386   int * first_;
00388   int * last_;
00390   int numberMajor_;
00392   int maximumMajor_;
00394   int numberElements_;
00396   int maximumElements_;
00398   int type_;
00400 };
00402 inline char * CoinStrdup(const char * name)
00403 { return (name ) ? strdup(name) : NULL;}
00404 
00405 #endif

Generated on Thu May 15 21:59:05 2008 by  doxygen 1.4.7