- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# /home/coin/SVN-release/DyLP-1.5.0/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 <cstring>
    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 class CoinYacc {
    00138 private:
    00139   CoinYacc(const CoinYacc& rhs);
    00140   CoinYacc& operator=(const CoinYacc& rhs);
    00141
    00142 public:
    00143   CoinYacc() : symtable(NULL), symbuf(NULL), length(0), unsetValue(0) {}
    00144   ~CoinYacc()
    00145   {
    00146     if (length) {
    00147       free(symbuf);
    00148       symbuf = NULL;
    00149     }
    00150     symrec* s = symtable;
    00151     while (s) {
    00152       free(s->name);
    00153       symtable = s;
    00154       s = s->next;
    00155       free(symtable);
    00156     }
    00157   }
    00158
    00159 public:
    00160   symrec * symtable;
    00161   char * symbuf;
    00162   int length;
    00163   double unsetValue;
    00164 };
    00165
    00166 class CoinModelHash {
    00167
    00168 public:
    00172   CoinModelHash();
    00174   ~CoinModelHash();
    00176
    00180   CoinModelHash(const CoinModelHash&);
    00182   CoinModelHash& operator=(const CoinModelHash&);
    00184
    00187
    00188   void resize(int maxItems,bool forceReHash=false);
    00190   inline int numberItems() const
    00191   { return numberItems_;}
    00193   void setNumberItems(int number);
    00195   inline int maximumItems() const
    00196   { return maximumItems_;}
    00198   inline const char *const * names() const
    00199   { return names_;}
    00201
    00204
    00205   int hash(const char * name) const;
    00207   void addHash(int index, const char * name);
    00209   void deleteHash(int index);
    00211   const char * name(int which) const;
    00213   char * getName(int which) const;
    00215   void setName(int which,char * name ) ;
    00217   void validateHash() const;
    00218 private:
    00220   int hashValue(const char * name) const;
    00221 public:
    00223 private:
    00226
    00227   char ** names_;
    00229   CoinModelHashLink * hash_;
    00231   int numberItems_;
    00233   int maximumItems_;
    00235   int lastSlot_;
    00237 };
    00239 class CoinModelHash2 {
    00240
    00241 public:
    00245   CoinModelHash2();
    00247   ~CoinModelHash2();
    00249
    00253   CoinModelHash2(const CoinModelHash2&);
    00255   CoinModelHash2& operator=(const CoinModelHash2&);
    00257
    00260
    00261   void resize(int maxItems, const CoinModelTriple * triples,bool forceReHash=false);
    00263   inline int numberItems() const
    00264   { return numberItems_;}
    00266   void setNumberItems(int number);
    00268   inline int maximumItems() const
    00269   { return maximumItems_;}
    00271
    00274
    00275   int hash(int row, int column, const CoinModelTriple * triples) const;
    00277   void addHash(int index, int row, int column, const CoinModelTriple * triples);
    00279   void deleteHash(int index, int row, int column);
    00280 private:
    00282   int hashValue(int row, int column) const;
    00283 public:
    00285 private:
    00288
    00289   CoinModelHashLink * hash_;
    00291   int numberItems_;
    00293   int maximumItems_;
    00295   int lastSlot_;
    00297 };
    00298 class CoinModelLinkedList {
    00299
    00300 public:
    00304   CoinModelLinkedList();
    00306   ~CoinModelLinkedList();
    00308
    00312   CoinModelLinkedList(const CoinModelLinkedList&);
    00314   CoinModelLinkedList& operator=(const CoinModelLinkedList&);
    00316
    00321   void resize(int maxMajor,int maxElements);
    00325   void create(int maxMajor,int maxElements,
    00326               int numberMajor, int numberMinor,
    00327               int type,
    00328               int numberElements, const CoinModelTriple * triples);
    00330   inline int numberMajor() const
    00331   { return numberMajor_;}
    00333   inline int maximumMajor() const
    00334   { return maximumMajor_;}
    00336   inline int numberElements() const
    00337   { return numberElements_;}
    00339   inline int maximumElements() const
    00340   { return maximumElements_;}
    00342   inline int firstFree() const
    00343   { return first_[maximumMajor_];}
    00345   inline int lastFree() const
    00346   { return last_[maximumMajor_];}
    00348   inline int first(int which) const
    00349   { return first_[which];}
    00351   inline int last(int which) const
    00352   { return last_[which];}
    00354   inline const int * next() const
    00355   { return next_;}
    00357   inline const int * previous() const
    00358   { return previous_;}
    00360
    00366   int addEasy(int majorIndex, int numberOfElements, const int * indices,
    00367               const double * elements, CoinModelTriple * triples,
    00368               CoinModelHash2 & hash);
    00371   void addHard(int minorIndex, int numberOfElements, const int * indices,
    00372                const double * elements, CoinModelTriple * triples,
    00373                CoinModelHash2 & hash);
    00377   void addHard(int first, const CoinModelTriple * triples,
    00378                int firstFree, int lastFree,const int * nextOther);
    00381   void deleteSame(int which, CoinModelTriple * triples,
    00382                  CoinModelHash2 & hash, bool zapTriples);
    00386   void updateDeleted(int which, CoinModelTriple * triples,
    00387                      CoinModelLinkedList & otherList);
    00390   void deleteRowOne(int position, CoinModelTriple * triples,
    00391                  CoinModelHash2 & hash);
    00395   void updateDeletedOne(int position, const CoinModelTriple * triples);
    00397   void fill(int first,int last);
    00399   void synchronize(CoinModelLinkedList & other);
    00401   void validateLinks(const CoinModelTriple * triples) const;
    00403 private:
    00406
    00407   int * previous_;
    00409   int * next_;
    00411   int * first_;
    00413   int * last_;
    00415   int numberMajor_;
    00417   int maximumMajor_;
    00419   int numberElements_;
    00421   int maximumElements_;
    00423   int type_;
    00425 };
    00426
    00427 #endif