Cgl 0.60.2

- 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 2083 2019-01-06 19:38:09Z unxusr $ */
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 #include <cstdlib>
10 #include <cmath>
11 #include <cassert>
12 #include <cfloat>
13 #include <cstring>
14 #include <cstdio>
15 #include <iostream>
16
17 #include "CoinTypes.hpp"
18 #include "CoinPragma.hpp"
19
27
29 class CoinModelLink {
30
31 public:
35 CoinModelLink();
37 ~CoinModelLink();
39
43 CoinModelLink(const CoinModelLink &);
45 CoinModelLink &operator=(const CoinModelLink &);
47
50 inline int row() const
52 {
53 return row_;
54 }
56 inline int column() const
57 {
58 return column_;
59 }
61 inline double value() const
62 {
63 return value_;
64 }
66 inline double element() const
67 {
68 return value_;
69 }
71 inline CoinBigIndex position() const
72 {
73 return position_;
74 }
76 inline bool onRow() const
77 {
78 return onRow_;
79 }
81 inline void setRow(int row)
82 {
83 row_ = row;
84 }
86 inline void setColumn(int column)
87 {
88 column_ = column;
89 }
91 inline void setValue(double value)
92 {
93 value_ = value;
94 }
96 inline void setElement(double value)
97 {
98 value_ = value;
99 }
101 inline void setPosition(CoinBigIndex position)
102 {
103 position_ = position;
104 }
106 inline void setOnRow(bool onRow)
107 {
108 onRow_ = onRow;
109 }
111
112 private:
115 int row_;
118 int column_;
120 double value_;
122 CoinBigIndex position_;
124 bool onRow_;
126 };
127
129 // for specifying triple
130 typedef struct {
131 // top bit is nonzero if string
132 // rest is row
133 unsigned int row;
134 //CoinModelRowIndex row;
135 int column;
136 double value; // If string then index into strings
137 } CoinModelTriple;
138 inline int rowInTriple(const CoinModelTriple &triple)
139 {
140 return triple.row & 0x7fffffff;
141 }
142 inline void setRowInTriple(CoinModelTriple &triple, int iRow)
143 {
144 triple.row = iRow | (triple.row & 0x80000000);
145 }
146 inline bool stringInTriple(const CoinModelTriple &triple)
147 {
148 return (triple.row & 0x80000000) != 0;
149 }
150 inline void setStringInTriple(CoinModelTriple &triple, bool string)
151 {
152 triple.row = (string ? 0x80000000 : 0) | (triple.row & 0x7fffffff);
153 }
154 inline void setRowAndStringInTriple(CoinModelTriple &triple,
155 int iRow, bool string)
156 {
157 triple.row = (string ? 0x80000000 : 0) | iRow;
158 }
160 // for hashing
161 typedef struct {
162 int index, next;
163 } CoinModelHashLink;
164 typedef struct {
165 CoinBigIndex index, next;
166 } CoinModelHashLink2;
167
168 /* Function type. */
169 typedef double (*func_t)(double);
170
172 /* Data type for links in the chain of symbols. */
173 struct symrec {
174 char *name; /* name of symbol */
175 int type; /* type of symbol: either VAR or FNCT */
176 union {
177 double var; /* value of a VAR */
178 func_t fnctptr; /* value of a FNCT */
179 } value;
180 struct symrec *next; /* link field */
181 };
182
183 typedef struct symrec symrec;
184
185 class CoinYacc {
186 private:
187 CoinYacc(const CoinYacc &rhs);
188 CoinYacc &operator=(const CoinYacc &rhs);
189
190 public:
191 CoinYacc()
192 : symtable(NULL)
193 , symbuf(NULL)
194 , length(0)
195 , unsetValue(0)
196 {
197 }
198 ~CoinYacc()
199 {
200 if (length) {
201 free(symbuf);
202 symbuf = NULL;
203 }
204 symrec *s = symtable;
205 while (s) {
206 free(s->name);
207 symtable = s;
208 s = s->next;
209 free(symtable);
210 }
211 }
212
213 public:
214 symrec *symtable;
215 char *symbuf;
216 int length;
217 double unsetValue;
218 };
219
220 class CoinModelHash {
221
222 public:
226 CoinModelHash();
228 ~CoinModelHash();
230
234 CoinModelHash(const CoinModelHash &);
236 CoinModelHash &operator=(const CoinModelHash &);
238
241 void resize(int maxItems, bool forceReHash = false);
244 inline int numberItems() const
245 {
246 return numberItems_;
247 }
249 void setNumberItems(int number);
251 inline int maximumItems() const
252 {
253 return maximumItems_;
254 }
256 inline const char *const *names() const
257 {
258 return names_;
259 }
261
264 int hash(const char *name) const;
267 void addHash(int index, const char *name);
269 void deleteHash(int index);
271 const char *name(int which) const;
273 char *getName(int which) const;
275 void setName(int which, char *name);
277 void validateHash() const;
278
279 private:
281 int hashValue(const char *name) const;
282
283 public:
285 private:
288 char **names_;
291 CoinModelHashLink *hash_;
293 int numberItems_;
295 int maximumItems_;
297 int lastSlot_;
299 };
301 class CoinModelHash2 {
302
303 public:
307 CoinModelHash2();
309 ~CoinModelHash2();
311
315 CoinModelHash2(const CoinModelHash2 &);
317 CoinModelHash2 &operator=(const CoinModelHash2 &);
319
322 void resize(CoinBigIndex maxItems, const CoinModelTriple *triples, bool forceReHash = false);
325 inline CoinBigIndex numberItems() const
326 {
327 return numberItems_;
328 }
330 void setNumberItems(CoinBigIndex number);
332 inline CoinBigIndex maximumItems() const
333 {
334 return maximumItems_;
335 }
337
340 CoinBigIndex hash(int row, int column, const CoinModelTriple *triples) const;
343 void addHash(CoinBigIndex index, int row, int column, const CoinModelTriple *triples);
345 void deleteHash(CoinBigIndex index, int row, int column);
346
347 private:
349 CoinBigIndex hashValue(int row, int column) const;
350
351 public:
353 private:
356 CoinModelHashLink2 *hash_;
359 CoinBigIndex numberItems_;
361 CoinBigIndex maximumItems_;
363 CoinBigIndex lastSlot_;
365 };
366 class CoinModelLinkedList {
367
368 public:
372 CoinModelLinkedList();
374 ~CoinModelLinkedList();
376
380 CoinModelLinkedList(const CoinModelLinkedList &);
382 CoinModelLinkedList &operator=(const CoinModelLinkedList &);
384
389 void resize(int maxMajor, CoinBigIndex maxElements);
393 void create(int maxMajor, CoinBigIndex maxElements,
394 int numberMajor, int numberMinor,
395 int type,
396 CoinBigIndex numberElements, const CoinModelTriple *triples);
398 inline int numberMajor() const
399 {
400 return numberMajor_;
401 }
403 inline int maximumMajor() const
404 {
405 return maximumMajor_;
406 }
408 inline CoinBigIndex numberElements() const
409 {
410 return numberElements_;
411 }
413 inline CoinBigIndex maximumElements() const
414 {
415 return maximumElements_;
416 }
418 inline CoinBigIndex firstFree() const
419 {
420 return first_[maximumMajor_];
421 }
423 inline CoinBigIndex lastFree() const
424 {
425 return last_[maximumMajor_];
426 }
428 inline CoinBigIndex first(int which) const
429 {
430 return first_[which];
431 }
433 inline CoinBigIndex last(int which) const
434 {
435 return last_[which];
436 }
438 inline const CoinBigIndex *next() const
439 {
440 return next_;
441 }
443 inline const CoinBigIndex *previous() const
444 {
445 return previous_;
446 }
448
454 CoinBigIndex addEasy(int majorIndex, CoinBigIndex numberOfElements, const int *indices,
455 const double *elements, CoinModelTriple *triples,
456 CoinModelHash2 &hash);
459 void addHard(int minorIndex, CoinBigIndex numberOfElements, const int *indices,
460 const double *elements, CoinModelTriple *triples,
461 CoinModelHash2 &hash);
465 void addHard(CoinBigIndex first, const CoinModelTriple *triples,
466 CoinBigIndex firstFree, CoinBigIndex lastFree, const CoinBigIndex *nextOther);
469 void deleteSame(int which, CoinModelTriple *triples,
470 CoinModelHash2 &hash, bool zapTriples);
474 void updateDeleted(int which, CoinModelTriple *triples,
475 CoinModelLinkedList &otherList);
478 void deleteRowOne(CoinBigIndex position, CoinModelTriple *triples,
479 CoinModelHash2 &hash);
483 void updateDeletedOne(CoinBigIndex position, const CoinModelTriple *triples);
485 void fill(int first, int last);
487 void synchronize(CoinModelLinkedList &other);
489 void validateLinks(const CoinModelTriple *triples) const;
491 private:
494 CoinBigIndex *previous_;
497 CoinBigIndex *next_;
499 CoinBigIndex *first_;
501 CoinBigIndex *last_;
503 int numberMajor_;
505 int maximumMajor_;
507 CoinBigIndex numberElements_;
509 CoinBigIndex maximumElements_;
511 int type_;
513 };
514
515 #endif
516
517 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
518 */
CoinModelLink::operator=
CoinModelLink & operator=(const CoinModelLink &)
=
CoinModelHash2::resize
void resize(CoinBigIndex maxItems, const CoinModelTriple *triples, bool forceReHash=false)
Resize hash (also re-hashs)
CoinModelLink::value
double value() const
Get value.
Definition: CoinModelUseful.hpp:61
CoinModelLink::setValue
void setValue(double value)
Set value.
Definition: CoinModelUseful.hpp:91
CoinModelTriple::value
double value
Definition: CoinModelUseful.hpp:136
CoinModelLinkedList::previous_
CoinBigIndex * previous_
Previous - maximumElements long.
Definition: CoinModelUseful.hpp:495
CoinModelLinkedList::numberMajor_
int numberMajor_
Number of major items i.e. rows if just row links.
Definition: CoinModelUseful.hpp:503
CoinModelHash2::hashValue
CoinBigIndex hashValue(int row, int column) const
Returns a hash value.
CoinModelHash::names_
char ** names_
Names.
Definition: CoinModelUseful.hpp:289
CoinModelHash2::maximumItems_
CoinBigIndex maximumItems_
Maximum number of items.
Definition: CoinModelUseful.hpp:361
CoinYacc::symbuf
char * symbuf
Definition: CoinModelUseful.hpp:215
CoinModelLinkedList::firstFree
CoinBigIndex firstFree() const
First on free chain.
Definition: CoinModelUseful.hpp:418
CoinModelLink::value_
double value_
Value as double.
Definition: CoinModelUseful.hpp:120
CoinModelHash::operator=
CoinModelHash & operator=(const CoinModelHash &)
=
rowInTriple
int rowInTriple(const CoinModelTriple &triple)
Definition: CoinModelUseful.hpp:138
CoinModelLinkedList::maximumMajor_
int maximumMajor_
Maximum number of major items i.e. rows if just row links.
Definition: CoinModelUseful.hpp:505
CoinTypes.hpp
CoinModelLink::~CoinModelLink
~CoinModelLink()
Destructor.
func_t
double(* func_t)(double)
Definition: CoinModelUseful.hpp:169
CoinModelLinkedList::addHard
void addHard(int minorIndex, CoinBigIndex numberOfElements, const int *indices, const double *elements, CoinModelTriple *triples, CoinModelHash2 &hash)
Adds to list - hard case i.e.
CoinModelLinkedList::previous
const CoinBigIndex * previous() const
Previous array.
Definition: CoinModelUseful.hpp:443
CoinModelHashLink2::next
CoinBigIndex next
Definition: CoinModelUseful.hpp:165
CoinModelLink::setOnRow
void setOnRow(bool onRow)
Set onRow.
Definition: CoinModelUseful.hpp:106
CoinModelLinkedList::maximumElements
CoinBigIndex maximumElements() const
Maximum number of elements.
Definition: CoinModelUseful.hpp:413
CoinModelHash::resize
void resize(int maxItems, bool forceReHash=false)
Resize hash (also re-hashs)
CoinModelHash2::numberItems
CoinBigIndex numberItems() const
Number of items.
Definition: CoinModelUseful.hpp:325
setRowAndStringInTriple
void setRowAndStringInTriple(CoinModelTriple &triple, int iRow, bool string)
Definition: CoinModelUseful.hpp:154
CoinModelLink
This is for various structures/classes needed by CoinModel.
Definition: CoinModelUseful.hpp:29
CoinModelLinkedList::last_
CoinBigIndex * last_
Last - maximumMajor+1 long (last free element chain)
Definition: CoinModelUseful.hpp:501
CoinModelHash::maximumItems
int maximumItems() const
Maximum number of items.
Definition: CoinModelUseful.hpp:251
CoinModelHash::deleteHash
void deleteHash(int index)
Deletes from hash.
CoinModelHash::hashValue
int hashValue(const char *name) const
Returns a hash value.
CoinModelLinkedList::next_
CoinBigIndex * next_
Next - maximumElements long.
Definition: CoinModelUseful.hpp:497
CoinModelLinkedList::numberMajor
int numberMajor() const
Number of major items i.e. rows if just row links.
Definition: CoinModelUseful.hpp:398
CoinModelLinkedList::updateDeleted
void updateDeleted(int which, CoinModelTriple *triples, CoinModelLinkedList &otherList)
Deletes from list - other case i.e.
CoinModelHashLink::next
int next
Definition: CoinModelUseful.hpp:162
CoinModelLinkedList::addEasy
CoinBigIndex addEasy(int majorIndex, CoinBigIndex numberOfElements, const int *indices, const double *elements, CoinModelTriple *triples, CoinModelHash2 &hash)
Adds to list - easy case i.e.
CoinModelLinkedList::deleteRowOne
void deleteRowOne(CoinBigIndex position, CoinModelTriple *triples, CoinModelHash2 &hash)
Deletes one element from Row list.
CoinModelHash2::lastSlot_
CoinBigIndex lastSlot_
Last slot looked at.
Definition: CoinModelUseful.hpp:363
CoinModelHash2::deleteHash
void deleteHash(CoinBigIndex index, int row, int column)
Deletes from hash.
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:301
CoinModelLinkedList::updateDeletedOne
void updateDeletedOne(CoinBigIndex position, const CoinModelTriple *triples)
Update column list for one element when one element deleted from row copy.
CoinModelHash
Definition: CoinModelUseful.hpp:220
CoinModelHash2::maximumItems
CoinBigIndex maximumItems() const
Maximum number of items.
Definition: CoinModelUseful.hpp:332
CoinModelLinkedList::numberElements_
CoinBigIndex numberElements_
Number of elements.
Definition: CoinModelUseful.hpp:507
CoinYacc
Definition: CoinModelUseful.hpp:185
CoinModelLinkedList::lastFree
CoinBigIndex lastFree() const
Last on free chain.
Definition: CoinModelUseful.hpp:423
CoinYacc::~CoinYacc
~CoinYacc()
Definition: CoinModelUseful.hpp:198
CoinYacc::unsetValue
double unsetValue
Definition: CoinModelUseful.hpp:217
CoinModelLinkedList::type_
int type_
0 row list, 1 column list
Definition: CoinModelUseful.hpp:511
CoinModelLink::column_
int column_
Column.
Definition: CoinModelUseful.hpp:118
CoinModelLink::setPosition
void setPosition(CoinBigIndex position)
Set position.
Definition: CoinModelUseful.hpp:101
CoinModelHash2::hash_
CoinModelHashLink2 * hash_
hash
Definition: CoinModelUseful.hpp:357
CoinModelLink::position
CoinBigIndex position() const
Get position.
Definition: CoinModelUseful.hpp:71
CoinModelLinkedList::~CoinModelLinkedList
~CoinModelLinkedList()
Destructor.
CoinModelHash::hash_
CoinModelHashLink * hash_
hash
Definition: CoinModelUseful.hpp:291
CoinModelHashLink2
Definition: CoinModelUseful.hpp:164
CoinModelLink::CoinModelLink
CoinModelLink()
Default constructor.
setStringInTriple
void setStringInTriple(CoinModelTriple &triple, bool string)
Definition: CoinModelUseful.hpp:150
symrec::type
int type
Definition: CoinModelUseful.hpp:175
CoinModelLinkedList::next
const CoinBigIndex * next() const
Next array.
Definition: CoinModelUseful.hpp:438
symrec::next
struct symrec * next
Definition: CoinModelUseful.hpp:180
CoinModelHash::names
const char *const * names() const
Names.
Definition: CoinModelUseful.hpp:256
CoinModelLinkedList
Definition: CoinModelUseful.hpp:366
CoinModelLinkedList::CoinModelLinkedList
CoinModelLinkedList()
Default constructor.
CoinPragma.hpp
CoinModelHash::setNumberItems
void setNumberItems(int number)
Set number of items.
CoinModelHashLink
for names and hashing
Definition: CoinModelUseful.hpp:161
CoinModelLinkedList::first
CoinBigIndex first(int which) const
First on chain.
Definition: CoinModelUseful.hpp:428
symrec
For string evaluation.
Definition: CoinModelUseful.hpp:173
CoinModelTriple::row
unsigned int row
Definition: CoinModelUseful.hpp:133
CoinModelLink::row_
int row_
Row.
Definition: CoinModelUseful.hpp:116
CoinModelHash::CoinModelHash
CoinModelHash()
Default constructor.
CoinModelTriple
for linked lists
Definition: CoinModelUseful.hpp:130
CoinModelLink::onRow_
bool onRow_
If on row chain.
Definition: CoinModelUseful.hpp:124
CoinYacc::CoinYacc
CoinYacc()
Definition: CoinModelUseful.hpp:191
CoinModelLinkedList::first_
CoinBigIndex * first_
First - maximumMajor+1 long (last free element chain)
Definition: CoinModelUseful.hpp:499
CoinModelLinkedList::validateLinks
void validateLinks(const CoinModelTriple *triples) const
Checks that links are consistent.
CoinModelHash::numberItems_
int numberItems_
Number of items.
Definition: CoinModelUseful.hpp:293
CoinModelLinkedList::last
CoinBigIndex last(int which) const
Last on chain.
Definition: CoinModelUseful.hpp:433
CoinModelLinkedList::create
void create(int maxMajor, CoinBigIndex maxElements, int numberMajor, int numberMinor, int type, CoinBigIndex numberElements, const CoinModelTriple *triples)
Create list - for row list maxMajor is maximum rows.
CoinModelLinkedList::numberElements
CoinBigIndex numberElements() const
Number of elements.
Definition: CoinModelUseful.hpp:408
CoinModelHash::name
const char * name(int which) const
Returns name at position (or NULL)
CoinModelHash::~CoinModelHash
~CoinModelHash()
Destructor.
symrec::value
union symrec::@0 value
CoinModelLink::setColumn
void setColumn(int column)
Set column.
Definition: CoinModelUseful.hpp:86
CoinModelHash2::addHash
void addHash(CoinBigIndex index, int row, int column, const CoinModelTriple *triples)
Adds to hash.
stringInTriple
bool stringInTriple(const CoinModelTriple &triple)
Definition: CoinModelUseful.hpp:146
CoinModelLink::setElement
void setElement(double value)
Set value.
Definition: CoinModelUseful.hpp:96
CoinModelHash2::hash
CoinBigIndex hash(int row, int column, const CoinModelTriple *triples) const
Returns index or -1.
CoinModelHash::lastSlot_
int lastSlot_
Last slot looked at.
Definition: CoinModelUseful.hpp:297
CoinModelLinkedList::maximumMajor
int maximumMajor() const
Maximum number of major items i.e. rows if just row links.
Definition: CoinModelUseful.hpp:403
CoinModelHash::hash
int hash(const char *name) const
Returns index or -1.
CoinModelLink::onRow
bool onRow() const
Get onRow.
Definition: CoinModelUseful.hpp:76
CoinBigIndex
int CoinBigIndex
Definition: Coin_C_defines.h:136
CoinModelLinkedList::resize
void resize(int maxMajor, CoinBigIndex maxElements)
Resize list - for row list maxMajor is maximum rows.
CoinYacc::length
int length
Definition: CoinModelUseful.hpp:216
CoinModelHash::maximumItems_
int maximumItems_
Maximum number of items.
Definition: CoinModelUseful.hpp:295
CoinModelHash::numberItems
int numberItems() const
Number of items i.e. rows if just row names.
Definition: CoinModelUseful.hpp:244
CoinModelLink::position_
CoinBigIndex position_
Position in data.
Definition: CoinModelUseful.hpp:122
CoinModelLinkedList::maximumElements_
CoinBigIndex maximumElements_
Maximum number of elements.
Definition: CoinModelUseful.hpp:509
CoinModelLink::column
int column() const
Get column.
Definition: CoinModelUseful.hpp:56
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:142
CoinYacc::operator=
CoinYacc & operator=(const CoinYacc &rhs)
CoinModelHash::validateHash
void validateHash() const
Validates.
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:81
CoinModelHash::getName
char * getName(int which) const
Returns non const name at position (or NULL)
CoinYacc::symtable
symrec * symtable
Definition: CoinModelUseful.hpp:214
CoinModelHash2::operator=
CoinModelHash2 & operator=(const CoinModelHash2 &)
=
symrec::name
char * name
Definition: CoinModelUseful.hpp:174
CoinModelHash2::setNumberItems
void setNumberItems(CoinBigIndex number)
Set number of items.
CoinModelTriple::column
int column
Definition: CoinModelUseful.hpp:135
symrec::var
double var
Definition: CoinModelUseful.hpp:177
symrec::fnctptr
func_t fnctptr
Definition: CoinModelUseful.hpp:178
CoinModelHash2::CoinModelHash2
CoinModelHash2()
Default constructor.
CoinModelLink::row
int row() const
Get row.
Definition: CoinModelUseful.hpp:51
CoinModelLinkedList::operator=
CoinModelLinkedList & operator=(const CoinModelLinkedList &)
=
CoinModelLink::element
double element() const
Get value.
Definition: CoinModelUseful.hpp:66
CoinModelHash::addHash
void addHash(int index, const char *name)
Adds to hash.
CoinModelHash2::numberItems_
CoinBigIndex numberItems_
Number of items.
Definition: CoinModelUseful.hpp:359
CoinModelHash2::~CoinModelHash2
~CoinModelHash2()
Destructor.