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

- File List
- File Members

# /home/coin/SVN-release/Blis-0.91.2/CoinUtils/src/CoinModelUseful.hpp

Go to the documentation of this file.

    00001 /* $Id: CoinModelUseful.hpp 1215 2009-11-05 11:03:04Z forrest $ */
    00002 // Copyright (C) 2005, International Business Machines
    00003 // Corporation and others.  All Rights Reserved.
    00004 #ifndef CoinModelUseful_H
    00005 #define CoinModelUseful_H
    00006
    00007
    00008 #include <cmath>
    00009 #include <cassert>
    00010 #include <cfloat>
    00011 #include <cstring>
    00012 #include <cstdio>
    00013 #include <iostream>
    00014
    00015
    00016 #include "CoinPragma.hpp"
    00017 #include "CoinFinite.hpp"
    00018
    00026
    00027
    00028 class CoinModelLink {
    00029
    00030 public:
    00034    CoinModelLink();
    00036    ~CoinModelLink();
    00038
    00042    CoinModelLink(const CoinModelLink&);
    00044    CoinModelLink& operator=(const CoinModelLink&);
    00046
    00049
    00050   inline int row() const
    00051   { return row_;}
    00053   inline int column() const
    00054   { return column_;}
    00056   inline double value() const
    00057   { return value_;}
    00059   inline double element() const
    00060   { return value_;}
    00062   inline int position() const
    00063   { return position_;}
    00065   inline bool onRow() const
    00066   { return onRow_;}
    00068   inline void setRow(int row)
    00069   { row_=row;}
    00071   inline void setColumn(int column)
    00072   { column_=column;}
    00074   inline void setValue(double value)
    00075   { value_=value;}
    00077   inline void setElement(double value)
    00078   { value_=value;}
    00080   inline void setPosition(int position)
    00081   { position_=position;}
    00083   inline void setOnRow(bool onRow)
    00084   { onRow_=onRow;}
    00086
    00087 private:
    00090
    00091   int row_;
    00093   int column_;
    00095   double value_;
    00097   int position_;
    00099   bool onRow_;
    00101 };
    00102
    00104 // for specifying triple
    00105 typedef struct {
    00106   // top bit is nonzero if string
    00107   // rest is row
    00108   unsigned int row;
    00109   //CoinModelRowIndex row;
    00110   int column;
    00111   double value; // If string then index into strings
    00112 } CoinModelTriple;
    00113 inline int rowInTriple(const CoinModelTriple & triple)
    00114 { return triple.row&0x7fffffff;}
    00115 inline void setRowInTriple(CoinModelTriple & triple,int iRow)
    00116 { triple.row = iRow|(triple.row&0x80000000);}
    00117 inline bool stringInTriple(const CoinModelTriple & triple)
    00118 { return (triple.row&0x80000000)!=0;}
    00119 inline void setStringInTriple(CoinModelTriple & triple,bool string)
    00120 { triple.row = (string ? 0x80000000 : 0)|(triple.row&0x7fffffff);}
    00121 inline void setRowAndStringInTriple(CoinModelTriple & triple,
    00122                                     int iRow,bool string)
    00123 { triple.row = (string ? 0x80000000 : 0)|iRow;}
    00125 // for hashing
    00126 typedef struct {
    00127   int index, next;
    00128 } CoinModelHashLink;
    00129
    00130 /* Function type.  */
    00131 typedef double (*func_t) (double);
    00132
    00134 /* Data type for links in the chain of symbols.  */
    00135 struct symrec
    00136 {
    00137   char *name;  /* name of symbol */
    00138   int type;    /* type of symbol: either VAR or FNCT */
    00139   union
    00140   {
    00141     double var;      /* value of a VAR */
    00142     func_t fnctptr;  /* value of a FNCT */
    00143   } value;
    00144   struct symrec *next;  /* link field */
    00145 };
    00146
    00147 typedef struct symrec symrec;
    00148
    00149 class CoinYacc {
    00150 private:
    00151   CoinYacc(const CoinYacc& rhs);
    00152   CoinYacc& operator=(const CoinYacc& rhs);
    00153
    00154 public:
    00155   CoinYacc() : symtable(NULL), symbuf(NULL), length(0), unsetValue(0) {}
    00156   ~CoinYacc()
    00157   {
    00158     if (length) {
    00159       free(symbuf);
    00160       symbuf = NULL;
    00161     }
    00162     symrec* s = symtable;
    00163     while (s) {
    00164       free(s->name);
    00165       symtable = s;
    00166       s = s->next;
    00167       free(symtable);
    00168     }
    00169   }
    00170
    00171 public:
    00172   symrec * symtable;
    00173   char * symbuf;
    00174   int length;
    00175   double unsetValue;
    00176 };
    00177
    00178 class CoinModelHash {
    00179
    00180 public:
    00184   CoinModelHash();
    00186   ~CoinModelHash();
    00188
    00192   CoinModelHash(const CoinModelHash&);
    00194   CoinModelHash& operator=(const CoinModelHash&);
    00196
    00199
    00200   void resize(int maxItems,bool forceReHash=false);
    00202   inline int numberItems() const
    00203   { return numberItems_;}
    00205   void setNumberItems(int number);
    00207   inline int maximumItems() const
    00208   { return maximumItems_;}
    00210   inline const char *const * names() const
    00211   { return names_;}
    00213
    00216
    00217   int hash(const char * name) const;
    00219   void addHash(int index, const char * name);
    00221   void deleteHash(int index);
    00223   const char * name(int which) const;
    00225   char * getName(int which) const;
    00227   void setName(int which,char * name ) ;
    00229   void validateHash() const;
    00230 private:
    00232   int hashValue(const char * name) const;
    00233 public:
    00235 private:
    00238
    00239   char ** names_;
    00241   CoinModelHashLink * hash_;
    00243   int numberItems_;
    00245   int maximumItems_;
    00247   int lastSlot_;
    00249 };
    00251 class CoinModelHash2 {
    00252
    00253 public:
    00257   CoinModelHash2();
    00259   ~CoinModelHash2();
    00261
    00265   CoinModelHash2(const CoinModelHash2&);
    00267   CoinModelHash2& operator=(const CoinModelHash2&);
    00269
    00272
    00273   void resize(int maxItems, const CoinModelTriple * triples,bool forceReHash=false);
    00275   inline int numberItems() const
    00276   { return numberItems_;}
    00278   void setNumberItems(int number);
    00280   inline int maximumItems() const
    00281   { return maximumItems_;}
    00283
    00286
    00287   int hash(int row, int column, const CoinModelTriple * triples) const;
    00289   void addHash(int index, int row, int column, const CoinModelTriple * triples);
    00291   void deleteHash(int index, int row, int column);
    00292 private:
    00294   int hashValue(int row, int column) const;
    00295 public:
    00297 private:
    00300
    00301   CoinModelHashLink * hash_;
    00303   int numberItems_;
    00305   int maximumItems_;
    00307   int lastSlot_;
    00309 };
    00310 class CoinModelLinkedList {
    00311
    00312 public:
    00316   CoinModelLinkedList();
    00318   ~CoinModelLinkedList();
    00320
    00324   CoinModelLinkedList(const CoinModelLinkedList&);
    00326   CoinModelLinkedList& operator=(const CoinModelLinkedList&);
    00328
    00333   void resize(int maxMajor,int maxElements);
    00337   void create(int maxMajor,int maxElements,
    00338               int numberMajor, int numberMinor,
    00339               int type,
    00340               int numberElements, const CoinModelTriple * triples);
    00342   inline int numberMajor() const
    00343   { return numberMajor_;}
    00345   inline int maximumMajor() const
    00346   { return maximumMajor_;}
    00348   inline int numberElements() const
    00349   { return numberElements_;}
    00351   inline int maximumElements() const
    00352   { return maximumElements_;}
    00354   inline int firstFree() const
    00355   { return first_[maximumMajor_];}
    00357   inline int lastFree() const
    00358   { return last_[maximumMajor_];}
    00360   inline int first(int which) const
    00361   { return first_[which];}
    00363   inline int last(int which) const
    00364   { return last_[which];}
    00366   inline const int * next() const
    00367   { return next_;}
    00369   inline const int * previous() const
    00370   { return previous_;}
    00372
    00378   int addEasy(int majorIndex, int numberOfElements, const int * indices,
    00379               const double * elements, CoinModelTriple * triples,
    00380               CoinModelHash2 & hash);
    00383   void addHard(int minorIndex, int numberOfElements, const int * indices,
    00384                const double * elements, CoinModelTriple * triples,
    00385                CoinModelHash2 & hash);
    00389   void addHard(int first, const CoinModelTriple * triples,
    00390                int firstFree, int lastFree,const int * nextOther);
    00393   void deleteSame(int which, CoinModelTriple * triples,
    00394                  CoinModelHash2 & hash, bool zapTriples);
    00398   void updateDeleted(int which, CoinModelTriple * triples,
    00399                      CoinModelLinkedList & otherList);
    00402   void deleteRowOne(int position, CoinModelTriple * triples,
    00403                  CoinModelHash2 & hash);
    00407   void updateDeletedOne(int position, const CoinModelTriple * triples);
    00409   void fill(int first,int last);
    00411   void synchronize(CoinModelLinkedList & other);
    00413   void validateLinks(const CoinModelTriple * triples) const;
    00415 private:
    00418
    00419   int * previous_;
    00421   int * next_;
    00423   int * first_;
    00425   int * last_;
    00427   int numberMajor_;
    00429   int maximumMajor_;
    00431   int numberElements_;
    00433   int maximumElements_;
    00435   int type_;
    00437 };
    00438
    00439 #endif