Osi 0.107.10

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CoinModelUseful.hpp
Go to the documentation of this file.
1 /* $Id: CoinModelUseful.hpp 1416 2011-04-17 09:57:29Z stefan $ */
2 // Copyright (C) 2005, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5
6 #ifndef CoinModelUseful_H
7 #define CoinModelUseful_H
8
9
10 #include <cstdlib>
11 #include <cmath>
12 #include <cassert>
13 #include <cfloat>
14 #include <cstring>
15 #include <cstdio>
16 #include <iostream>
17
18
19 #include "CoinPragma.hpp"
20
28
30 class CoinModelLink {
31
32 public:
36 CoinModelLink();
38 ~CoinModelLink();
40
44 CoinModelLink(const CoinModelLink&);
46 CoinModelLink& operator=(const CoinModelLink&);
48
51 inline int row() const
53 { return row_;}
55 inline int column() const
56 { return column_;}
58 inline double value() const
59 { return value_;}
61 inline double element() const
62 { return value_;}
64 inline int position() const
65 { return position_;}
67 inline bool onRow() const
68 { return onRow_;}
70 inline void setRow(int row)
71 { row_=row;}
73 inline void setColumn(int column)
74 { column_=column;}
76 inline void setValue(double value)
77 { value_=value;}
79 inline void setElement(double value)
80 { value_=value;}
82 inline void setPosition(int position)
83 { position_=position;}
85 inline void setOnRow(bool onRow)
86 { onRow_=onRow;}
88
89 private:
92 int row_;
95 int column_;
97 double value_;
99 int position_;
101 bool onRow_;
103 };
104
106 // for specifying triple
107 typedef struct {
108 // top bit is nonzero if string
109 // rest is row
110 unsigned int row;
111 //CoinModelRowIndex row;
112 int column;
113 double value; // If string then index into strings
114 } CoinModelTriple;
115 inline int rowInTriple(const CoinModelTriple & triple)
116 { return triple.row&0x7fffffff;}
117 inline void setRowInTriple(CoinModelTriple & triple,int iRow)
118 { triple.row = iRow|(triple.row&0x80000000);}
119 inline bool stringInTriple(const CoinModelTriple & triple)
120 { return (triple.row&0x80000000)!=0;}
121 inline void setStringInTriple(CoinModelTriple & triple,bool string)
122 { triple.row = (string ? 0x80000000 : 0)|(triple.row&0x7fffffff);}
123 inline void setRowAndStringInTriple(CoinModelTriple & triple,
124 int iRow,bool string)
125 { triple.row = (string ? 0x80000000 : 0)|iRow;}
127 // for hashing
128 typedef struct {
129 int index, next;
130 } CoinModelHashLink;
131
132 /* Function type. */
133 typedef double (*func_t) (double);
134
136 /* Data type for links in the chain of symbols. */
137 struct symrec
138 {
139 char *name; /* name of symbol */
140 int type; /* type of symbol: either VAR or FNCT */
141 union
142 {
143 double var; /* value of a VAR */
144 func_t fnctptr; /* value of a FNCT */
145 } value;
146 struct symrec *next; /* link field */
147 };
148
149 typedef struct symrec symrec;
150
151 class CoinYacc {
152 private:
153 CoinYacc(const CoinYacc& rhs);
154 CoinYacc& operator=(const CoinYacc& rhs);
155
156 public:
157 CoinYacc() : symtable(NULL), symbuf(NULL), length(0), unsetValue(0) {}
158 ~CoinYacc()
159 {
160 if (length) {
161 free(symbuf);
162 symbuf = NULL;
163 }
164 symrec* s = symtable;
165 while (s) {
166 free(s->name);
167 symtable = s;
168 s = s->next;
169 free(symtable);
170 }
171 }
172
173 public:
174 symrec * symtable;
175 char * symbuf;
176 int length;
177 double unsetValue;
178 };
179
180 class CoinModelHash {
181
182 public:
186 CoinModelHash();
188 ~CoinModelHash();
190
194 CoinModelHash(const CoinModelHash&);
196 CoinModelHash& operator=(const CoinModelHash&);
198
201 void resize(int maxItems,bool forceReHash=false);
204 inline int numberItems() const
205 { return numberItems_;}
207 void setNumberItems(int number);
209 inline int maximumItems() const
210 { return maximumItems_;}
212 inline const char *const * names() const
213 { return names_;}
215
218 int hash(const char * name) const;
221 void addHash(int index, const char * name);
223 void deleteHash(int index);
225 const char * name(int which) const;
227 char * getName(int which) const;
229 void setName(int which,char * name ) ;
231 void validateHash() const;
232 private:
234 int hashValue(const char * name) const;
235 public:
237 private:
240 char ** names_;
243 CoinModelHashLink * hash_;
245 int numberItems_;
247 int maximumItems_;
249 int lastSlot_;
251 };
253 class CoinModelHash2 {
254
255 public:
259 CoinModelHash2();
261 ~CoinModelHash2();
263
267 CoinModelHash2(const CoinModelHash2&);
269 CoinModelHash2& operator=(const CoinModelHash2&);
271
274 void resize(int maxItems, const CoinModelTriple * triples,bool forceReHash=false);
277 inline int numberItems() const
278 { return numberItems_;}
280 void setNumberItems(int number);
282 inline int maximumItems() const
283 { return maximumItems_;}
285
288 int hash(int row, int column, const CoinModelTriple * triples) const;
291 void addHash(int index, int row, int column, const CoinModelTriple * triples);
293 void deleteHash(int index, int row, int column);
294 private:
296 int hashValue(int row, int column) const;
297 public:
299 private:
302 CoinModelHashLink * hash_;
305 int numberItems_;
307 int maximumItems_;
309 int lastSlot_;
311 };
312 class CoinModelLinkedList {
313
314 public:
318 CoinModelLinkedList();
320 ~CoinModelLinkedList();
322
326 CoinModelLinkedList(const CoinModelLinkedList&);
328 CoinModelLinkedList& operator=(const CoinModelLinkedList&);
330
335 void resize(int maxMajor,int maxElements);
339 void create(int maxMajor,int maxElements,
340 int numberMajor, int numberMinor,
341 int type,
342 int numberElements, const CoinModelTriple * triples);
344 inline int numberMajor() const
345 { return numberMajor_;}
347 inline int maximumMajor() const
348 { return maximumMajor_;}
350 inline int numberElements() const
351 { return numberElements_;}
353 inline int maximumElements() const
354 { return maximumElements_;}
356 inline int firstFree() const
357 { return first_[maximumMajor_];}
359 inline int lastFree() const
360 { return last_[maximumMajor_];}
362 inline int first(int which) const
363 { return first_[which];}
365 inline int last(int which) const
366 { return last_[which];}
368 inline const int * next() const
369 { return next_;}
371 inline const int * previous() const
372 { return previous_;}
374
380 int addEasy(int majorIndex, int numberOfElements, const int * indices,
381 const double * elements, CoinModelTriple * triples,
382 CoinModelHash2 & hash);
385 void addHard(int minorIndex, int numberOfElements, const int * indices,
386 const double * elements, CoinModelTriple * triples,
387 CoinModelHash2 & hash);
391 void addHard(int first, const CoinModelTriple * triples,
392 int firstFree, int lastFree,const int * nextOther);
395 void deleteSame(int which, CoinModelTriple * triples,
396 CoinModelHash2 & hash, bool zapTriples);
400 void updateDeleted(int which, CoinModelTriple * triples,
401 CoinModelLinkedList & otherList);
404 void deleteRowOne(int position, CoinModelTriple * triples,
405 CoinModelHash2 & hash);
409 void updateDeletedOne(int position, const CoinModelTriple * triples);
411 void fill(int first,int last);
413 void synchronize(CoinModelLinkedList & other);
415 void validateLinks(const CoinModelTriple * triples) const;
417 private:
420 int * previous_;
423 int * next_;
425 int * first_;
427 int * last_;
429 int numberMajor_;
431 int maximumMajor_;
433 int numberElements_;
435 int maximumElements_;
437 int type_;
439 };
440
441 #endif
CoinModelLink::operator=
CoinModelLink & operator=(const CoinModelLink &)
=
CoinModelLink::value
double value() const
Get value.
Definition: CoinModelUseful.hpp:58
CoinModelLink::setValue
void setValue(double value)
Set value.
Definition: CoinModelUseful.hpp:76
CoinModelTriple::value
double value
Definition: CoinModelUseful.hpp:113
CoinModelHash2::setNumberItems
void setNumberItems(int number)
Set number of items.
CoinModelLink::position_
int position_
Position in data.
Definition: CoinModelUseful.hpp:99
CoinModelLinkedList::numberMajor_
int numberMajor_
Number of major items i.e. rows if just row links.
Definition: CoinModelUseful.hpp:429
CoinModelHash::names_
char ** names_
Names.
Definition: CoinModelUseful.hpp:241
CoinYacc::symbuf
char * symbuf
Definition: CoinModelUseful.hpp:175
CoinModelLink::value_
double value_
Value as double.
Definition: CoinModelUseful.hpp:97
CoinModelHash::operator=
CoinModelHash & operator=(const CoinModelHash &)
=
rowInTriple
int rowInTriple(const CoinModelTriple &triple)
Definition: CoinModelUseful.hpp:115
CoinModelLinkedList::maximumMajor_
int maximumMajor_
Maximum number of major items i.e. rows if just row links.
Definition: CoinModelUseful.hpp:431
CoinModelLink::~CoinModelLink
~CoinModelLink()
Destructor.
func_t
double(* func_t)(double)
Definition: CoinModelUseful.hpp:133
CoinModelLink::setOnRow
void setOnRow(bool onRow)
Set onRow.
Definition: CoinModelUseful.hpp:85
CoinModelHash::resize
void resize(int maxItems, bool forceReHash=false)
Resize hash (also re-hashs)
CoinModelHash2::lastSlot_
int lastSlot_
Last slot looked at.
Definition: CoinModelUseful.hpp:309
setRowAndStringInTriple
void setRowAndStringInTriple(CoinModelTriple &triple, int iRow, bool string)
Definition: CoinModelUseful.hpp:123
CoinModelHash2::numberItems
int numberItems() const
Number of items.
Definition: CoinModelUseful.hpp:277
CoinModelLink
This is for various structures/classes needed by CoinModel.
Definition: CoinModelUseful.hpp:30
CoinModelHash2::resize
void resize(int maxItems, const CoinModelTriple *triples, bool forceReHash=false)
Resize hash (also re-hashs)
CoinModelHash::maximumItems
int maximumItems() const
Maximum number of items.
Definition: CoinModelUseful.hpp:209
CoinModelHash::deleteHash
void deleteHash(int index)
Deletes from hash.
CoinModelHash::hashValue
int hashValue(const char *name) const
Returns a hash value.
CoinModelLinkedList::numberMajor
int numberMajor() const
Number of major items i.e. rows if just row links.
Definition: CoinModelUseful.hpp:344
CoinModelLinkedList::updateDeleted
void updateDeleted(int which, CoinModelTriple *triples, CoinModelLinkedList &otherList)
Deletes from list - other case i.e.
CoinModelHashLink::next
int next
Definition: CoinModelUseful.hpp:129
CoinModelLinkedList::fill
void fill(int first, int last)
Fills first,last with -1.
CoinModelLinkedList::synchronize
void synchronize(CoinModelLinkedList &other)
Puts in free list from other list.
CoinModelHash2
For int,int hashing.
Definition: CoinModelUseful.hpp:253
CoinModelLinkedList::next_
int * next_
Next - maximumElements long.
Definition: CoinModelUseful.hpp:423
CoinModelHash
Definition: CoinModelUseful.hpp:180
CoinYacc
Definition: CoinModelUseful.hpp:151
CoinModelLinkedList::addEasy
int addEasy(int majorIndex, int numberOfElements, const int *indices, const double *elements, CoinModelTriple *triples, CoinModelHash2 &hash)
Adds to list - easy case i.e.
CoinModelLinkedList::deleteRowOne
void deleteRowOne(int position, CoinModelTriple *triples, CoinModelHash2 &hash)
Deletes one element from Row list.
CoinYacc::~CoinYacc
~CoinYacc()
Definition: CoinModelUseful.hpp:158
CoinYacc::unsetValue
double unsetValue
Definition: CoinModelUseful.hpp:177
CoinModelLinkedList::type_
int type_
0 row list, 1 column list
Definition: CoinModelUseful.hpp:437
CoinModelLink::column_
int column_
Column.
Definition: CoinModelUseful.hpp:95
CoinModelHash2::addHash
void addHash(int index, int row, int column, const CoinModelTriple *triples)
Adds to hash.
CoinModelLinkedList::numberElements_
int numberElements_
Number of elements.
Definition: CoinModelUseful.hpp:433
CoinModelLinkedList::~CoinModelLinkedList
~CoinModelLinkedList()
Destructor.
CoinModelHash::hash_
CoinModelHashLink * hash_
hash
Definition: CoinModelUseful.hpp:243
CoinModelHash2::hash
int hash(int row, int column, const CoinModelTriple *triples) const
Returns index or -1.
CoinModelLink::CoinModelLink
CoinModelLink()
Default constructor.
setStringInTriple
void setStringInTriple(CoinModelTriple &triple, bool string)
Definition: CoinModelUseful.hpp:121
symrec::type
int type
Definition: CoinModelUseful.hpp:140
symrec::next
struct symrec * next
Definition: CoinModelUseful.hpp:146
CoinModelLinkedList::maximumElements
int maximumElements() const
Maximum number of elements.
Definition: CoinModelUseful.hpp:353
CoinModelLinkedList::first
int first(int which) const
First on chain.
Definition: CoinModelUseful.hpp:362
CoinModelHash::names
const char *const * names() const
Names.
Definition: CoinModelUseful.hpp:212
CoinModelLinkedList
Definition: CoinModelUseful.hpp:312
CoinModelLinkedList::CoinModelLinkedList
CoinModelLinkedList()
Default constructor.
CoinModelLinkedList::last
int last(int which) const
Last on chain.
Definition: CoinModelUseful.hpp:365
CoinModelLinkedList::updateDeletedOne
void updateDeletedOne(int position, const CoinModelTriple *triples)
Update column list for one element when one element deleted from row copy.
CoinPragma.hpp
CoinModelLinkedList::create
void create(int maxMajor, int maxElements, int numberMajor, int numberMinor, int type, int numberElements, const CoinModelTriple *triples)
Create list - for row list maxMajor is maximum rows.
CoinModelLinkedList::lastFree
int lastFree() const
Last on free chain.
Definition: CoinModelUseful.hpp:359
CoinModelHash::setNumberItems
void setNumberItems(int number)
Set number of items.
CoinModelHashLink
for names and hashing
Definition: CoinModelUseful.hpp:128
symrec
For string evaluation.
Definition: CoinModelUseful.hpp:137
CoinModelTriple::row
unsigned int row
Definition: CoinModelUseful.hpp:110
CoinModelLink::row_
int row_
Row.
Definition: CoinModelUseful.hpp:93
CoinModelHash::CoinModelHash
CoinModelHash()
Default constructor.
CoinModelTriple
for linked lists
Definition: CoinModelUseful.hpp:107
CoinModelLinkedList::maximumElements_
int maximumElements_
Maximum number of elements.
Definition: CoinModelUseful.hpp:435
CoinModelLink::onRow_
bool onRow_
If on row chain.
Definition: CoinModelUseful.hpp:101
CoinYacc::CoinYacc
CoinYacc()
Definition: CoinModelUseful.hpp:157
CoinModelLink::setPosition
void setPosition(int position)
Set position.
Definition: CoinModelUseful.hpp:82
CoinModelLinkedList::validateLinks
void validateLinks(const CoinModelTriple *triples) const
Checks that links are consistent.
CoinModelHash::numberItems_
int numberItems_
Number of items.
Definition: CoinModelUseful.hpp:245
CoinModelHash2::hashValue
int hashValue(int row, int column) const
Returns a hash value.
CoinModelHash2::hash_
CoinModelHashLink * hash_
hash
Definition: CoinModelUseful.hpp:303
CoinModelHash::name
const char * name(int which) const
Returns name at position (or NULL)
CoinModelLinkedList::next
const int * next() const
Next array.
Definition: CoinModelUseful.hpp:368
CoinModelHash::~CoinModelHash
~CoinModelHash()
Destructor.
symrec::value
union symrec::@0 value
CoinModelLink::setColumn
void setColumn(int column)
Set column.
Definition: CoinModelUseful.hpp:73
CoinModelLinkedList::numberElements
int numberElements() const
Number of elements.
Definition: CoinModelUseful.hpp:350
stringInTriple
bool stringInTriple(const CoinModelTriple &triple)
Definition: CoinModelUseful.hpp:119
CoinModelLink::setElement
void setElement(double value)
Set value.
Definition: CoinModelUseful.hpp:79
CoinModelHash2::maximumItems_
int maximumItems_
Maximum number of items.
Definition: CoinModelUseful.hpp:307
CoinModelHash::lastSlot_
int lastSlot_
Last slot looked at.
Definition: CoinModelUseful.hpp:249
CoinModelLinkedList::last_
int * last_
Last - maximumMajor+1 long (last free element chain)
Definition: CoinModelUseful.hpp:427
CoinModelLinkedList::maximumMajor
int maximumMajor() const
Maximum number of major items i.e. rows if just row links.
Definition: CoinModelUseful.hpp:347
CoinModelLink::position
int position() const
Get position.
Definition: CoinModelUseful.hpp:64
CoinModelHash::hash
int hash(const char *name) const
Returns index or -1.
CoinModelLink::onRow
bool onRow() const
Get onRow.
Definition: CoinModelUseful.hpp:67
CoinYacc::length
int length
Definition: CoinModelUseful.hpp:176
CoinModelHash::maximumItems_
int maximumItems_
Maximum number of items.
Definition: CoinModelUseful.hpp:247
CoinModelHash::numberItems
int numberItems() const
Number of items i.e. rows if just row names.
Definition: CoinModelUseful.hpp:204
CoinModelLinkedList::first_
int * first_
First - maximumMajor+1 long (last free element chain)
Definition: CoinModelUseful.hpp:425
CoinModelLinkedList::previous
const int * previous() const
Previous array.
Definition: CoinModelUseful.hpp:371
CoinModelLink::column
int column() const
Get column.
Definition: CoinModelUseful.hpp:55
CoinModelHash::setName
void setName(int which, char *name)
Sets name at position (does not create)
setRowInTriple
void setRowInTriple(CoinModelTriple &triple, int iRow)
Definition: CoinModelUseful.hpp:117
CoinYacc::operator=
CoinYacc & operator=(const CoinYacc &rhs)
CoinModelLinkedList::previous_
int * previous_
Previous - maximumElements long.
Definition: CoinModelUseful.hpp:421
CoinModelHash::validateHash
void validateHash() const
Validates.
CoinModelLinkedList::addHard
void addHard(int minorIndex, int numberOfElements, const int *indices, const double *elements, CoinModelTriple *triples, CoinModelHash2 &hash)
Adds to list - hard case i.e.
CoinModelLinkedList::deleteSame
void deleteSame(int which, CoinModelTriple *triples, CoinModelHash2 &hash, bool zapTriples)
Deletes from list - same case i.e.
CoinModelLink::setRow
void setRow(int row)
Set row.
Definition: CoinModelUseful.hpp:70
CoinModelHash::getName
char * getName(int which) const
Returns non const name at position (or NULL)
CoinYacc::symtable
symrec * symtable
Definition: CoinModelUseful.hpp:174
CoinModelHash2::operator=
CoinModelHash2 & operator=(const CoinModelHash2 &)
=
symrec::name
char * name
Definition: CoinModelUseful.hpp:139
CoinModelTriple::column
int column
Definition: CoinModelUseful.hpp:112
symrec::var
double var
Definition: CoinModelUseful.hpp:143
symrec::fnctptr
func_t fnctptr
Definition: CoinModelUseful.hpp:144
CoinModelHash2::numberItems_
int numberItems_
Number of items.
Definition: CoinModelUseful.hpp:305
CoinModelHash2::CoinModelHash2
CoinModelHash2()
Default constructor.
CoinModelLink::row
int row() const
Get row.
Definition: CoinModelUseful.hpp:52
CoinModelLinkedList::operator=
CoinModelLinkedList & operator=(const CoinModelLinkedList &)
=
CoinModelLink::element
double element() const
Get value.
Definition: CoinModelUseful.hpp:61
CoinModelHash::addHash
void addHash(int index, const char *name)
Adds to hash.
CoinModelHash2::maximumItems
int maximumItems() const
Maximum number of items.
Definition: CoinModelUseful.hpp:282
CoinModelHash2::deleteHash
void deleteHash(int index, int row, int column)
Deletes from hash.
CoinModelLinkedList::firstFree
int firstFree() const
First on free chain.
Definition: CoinModelUseful.hpp:356
CoinModelHash2::~CoinModelHash2
~CoinModelHash2()
Destructor.
CoinModelLinkedList::resize
void resize(int maxMajor, int maxElements)
Resize list - for row list maxMajor is maximum rows.