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

- File List
- File Members

# /home/coin/SVN-release/Osi-0.98.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 <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 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 ) ;
    00194   void validateHash() const;
    00195 private:
    00197   int hashValue(const char * name) const;
    00198 public:
    00200 private:
    00203
    00204   char ** names_;
    00206   CoinModelHashLink * hash_;
    00208   int numberItems_;
    00210   int maximumItems_;
    00212   int lastSlot_;
    00214 };
    00216 class CoinModelHash2 {
    00217
    00218 public:
    00222   CoinModelHash2();
    00224   ~CoinModelHash2();
    00226
    00230   CoinModelHash2(const CoinModelHash2&);
    00232   CoinModelHash2& operator=(const CoinModelHash2&);
    00234
    00237
    00238   void resize(int maxItems, const CoinModelTriple * triples,bool forceReHash=false);
    00240   inline int numberItems() const
    00241   { return numberItems_;}
    00243   void setNumberItems(int number);
    00245   inline int maximumItems() const
    00246   { return maximumItems_;}
    00248
    00251
    00252   int hash(int row, int column, const CoinModelTriple * triples) const;
    00254   void addHash(int index, int row, int column, const CoinModelTriple * triples);
    00256   void deleteHash(int index, int row, int column);
    00257 private:
    00259   int hashValue(int row, int column) const;
    00260 public:
    00262 private:
    00265
    00266   CoinModelHashLink * hash_;
    00268   int numberItems_;
    00270   int maximumItems_;
    00272   int lastSlot_;
    00274 };
    00275 class CoinModelLinkedList {
    00276
    00277 public:
    00281   CoinModelLinkedList();
    00283   ~CoinModelLinkedList();
    00285
    00289   CoinModelLinkedList(const CoinModelLinkedList&);
    00291   CoinModelLinkedList& operator=(const CoinModelLinkedList&);
    00293
    00298   void resize(int maxMajor,int maxElements);
    00302   void create(int maxMajor,int maxElements,
    00303               int numberMajor, int numberMinor,
    00304               int type,
    00305               int numberElements, const CoinModelTriple * triples);
    00307   inline int numberMajor() const
    00308   { return numberMajor_;}
    00310   inline int maximumMajor() const
    00311   { return maximumMajor_;}
    00313   inline int numberElements() const
    00314   { return numberElements_;}
    00316   inline int maximumElements() const
    00317   { return maximumElements_;}
    00319   inline int firstFree() const
    00320   { return first_[maximumMajor_];}
    00322   inline int lastFree() const
    00323   { return last_[maximumMajor_];}
    00325   inline int first(int which) const
    00326   { return first_[which];}
    00328   inline int last(int which) const
    00329   { return last_[which];}
    00331   inline const int * next() const
    00332   { return next_;}
    00334   inline const int * previous() const
    00335   { return previous_;}
    00337
    00343   int addEasy(int majorIndex, int numberOfElements, const int * indices,
    00344               const double * elements, CoinModelTriple * triples,
    00345               CoinModelHash2 & hash);
    00348   void addHard(int minorIndex, int numberOfElements, const int * indices,
    00349                const double * elements, CoinModelTriple * triples,
    00350                CoinModelHash2 & hash);
    00354   void addHard(int first, const CoinModelTriple * triples,
    00355                int firstFree, int lastFree,const int * nextOther);
    00358   void deleteSame(int which, CoinModelTriple * triples,
    00359                  CoinModelHash2 & hash, bool zapTriples);
    00363   void updateDeleted(int which, CoinModelTriple * triples,
    00364                      CoinModelLinkedList & otherList);
    00367   void deleteRowOne(int position, CoinModelTriple * triples,
    00368                  CoinModelHash2 & hash);
    00372   void updateDeletedOne(int position, const CoinModelTriple * triples);
    00374   void fill(int first,int last);
    00376   void synchronize(CoinModelLinkedList & other);
    00378   void validateLinks(const CoinModelTriple * triples) const;
    00380 private:
    00383
    00384   int * previous_;
    00386   int * next_;
    00388   int * first_;
    00390   int * last_;
    00392   int numberMajor_;
    00394   int maximumMajor_;
    00396   int numberElements_;
    00398   int maximumElements_;
    00400   int type_;
    00402 };
    00404 inline char * CoinStrdup(const char * name)
    00405 { return (name ) ? strdup(name) : NULL;}
    00406
    00407 #endif