CoinUtils 2.11.10
Loading...
Searching...
No Matches
CoinModelUseful.hpp
Go to the documentation of this file.
1/* $Id$ */
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
28
30
31public:
39
47
51 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 {
89 }
91 inline void setValue(double value)
92 {
93 value_ = value;
94 }
96 inline void setElement(double value)
97 {
98 value_ = value;
99 }
102 {
104 }
106 inline void setOnRow(bool onRow)
107 {
108 onRow_ = onRow;
109 }
111
112private:
116 int row_;
120 double value_;
124 bool onRow_;
126};
127
129// for specifying triple
130typedef struct {
131 // top bit is nonzero if string
132 // rest is row
133 unsigned int row;
134 //CoinModelRowIndex row;
136 double value; // If string then index into strings
138inline int rowInTriple(const CoinModelTriple &triple)
139{
140 return triple.row & 0x7fffffff;
141}
142inline void setRowInTriple(CoinModelTriple &triple, int iRow)
143{
144 triple.row = iRow | (triple.row & 0x80000000);
145}
146inline bool stringInTriple(const CoinModelTriple &triple)
147{
148 return (triple.row & 0x80000000) != 0;
149}
150inline void setStringInTriple(CoinModelTriple &triple, bool string)
151{
152 triple.row = (string ? 0x80000000 : 0) | (triple.row & 0x7fffffff);
153}
155 int iRow, bool string)
156{
157 triple.row = (string ? 0x80000000 : 0) | iRow;
158}
160// for hashing
161typedef struct {
162 int index, next;
164typedef struct {
167
168/* Function type. */
169typedef double (*func_t)(double);
170
172/* Data type for links in the chain of symbols. */
173struct 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 */
180 struct symrec *next; /* link field */
181};
182
183typedef struct symrec symrec;
184
185class CoinYacc {
186private:
187 CoinYacc(const CoinYacc &rhs);
189
190public:
192 : symtable(NULL)
193 , symbuf(NULL)
194 , length(0)
195 , unsetValue(0)
196 {
197 }
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
213public:
215 char *symbuf;
218};
219
221
222public:
230
238
242 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
265 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
279private:
281 int hashValue(const char *name) const;
282
283public:
285private:
289 char **names_;
299};
302
303public:
311
319
323 void resize(CoinBigIndex maxItems, const CoinModelTriple *triples, bool forceReHash = false);
326 {
327 return numberItems_;
328 }
333 {
334 return maximumItems_;
335 }
337
341 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
347private:
349 CoinBigIndex hashValue(int row, int column) const;
350
351public:
353private:
365};
367
368public:
376
384
389 void resize(int maxMajor, CoinBigIndex maxElements);
393 void create(int maxMajor, CoinBigIndex maxElements,
394 int numberMajor, int numberMinor,
395 int type,
398 inline int numberMajor() const
399 {
400 return numberMajor_;
401 }
403 inline int maximumMajor() const
404 {
405 return maximumMajor_;
406 }
409 {
410 return numberElements_;
411 }
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);
469 void deleteSame(int which, CoinModelTriple *triples,
470 CoinModelHash2 &hash, bool zapTriples);
474 void updateDeleted(int which, CoinModelTriple *triples,
475 CoinModelLinkedList &otherList);
479 CoinModelHash2 &hash);
483 void updateDeletedOne(CoinBigIndex position, const CoinModelTriple *triples);
485 void fill(int first, int last);
489 void validateLinks(const CoinModelTriple *triples) const;
491private:
511 int type_;
513};
514
515#endif
516
517/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
518*/
void setStringInTriple(CoinModelTriple &triple, bool string)
int rowInTriple(const CoinModelTriple &triple)
bool stringInTriple(const CoinModelTriple &triple)
double(* func_t)(double)
void setRowInTriple(CoinModelTriple &triple, int iRow)
void setRowAndStringInTriple(CoinModelTriple &triple, int iRow, bool string)
int CoinBigIndex
For int,int hashing.
CoinBigIndex hashValue(int row, int column) const
Returns a hash value.
void resize(CoinBigIndex maxItems, const CoinModelTriple *triples, bool forceReHash=false)
Resize hash (also re-hashs)
CoinBigIndex maximumItems_
Maximum number of items.
CoinBigIndex numberItems() const
Number of items.
CoinModelHash2 & operator=(const CoinModelHash2 &)
=
CoinBigIndex maximumItems() const
Maximum number of items.
CoinBigIndex numberItems_
Number of items.
void deleteHash(CoinBigIndex index, int row, int column)
Deletes from hash.
CoinBigIndex lastSlot_
Last slot looked at.
CoinModelHash2()
Default constructor.
CoinModelHash2(const CoinModelHash2 &)
The copy constructor.
~CoinModelHash2()
Destructor.
void setNumberItems(CoinBigIndex number)
Set number of items.
void addHash(CoinBigIndex index, int row, int column, const CoinModelTriple *triples)
Adds to hash.
CoinModelHashLink2 * hash_
hash
CoinBigIndex hash(int row, int column, const CoinModelTriple *triples) const
Returns index or -1.
int numberItems_
Number of items.
int lastSlot_
Last slot looked at.
void resize(int maxItems, bool forceReHash=false)
Resize hash (also re-hashs)
int maximumItems() const
Maximum number of items.
void setName(int which, char *name)
Sets name at position (does not create)
int numberItems() const
Number of items i.e. rows if just row names.
char ** names_
Names.
CoinModelHash()
Default constructor.
int hash(const char *name) const
Returns index or -1.
int maximumItems_
Maximum number of items.
void addHash(int index, const char *name)
Adds to hash.
CoinModelHashLink * hash_
hash
const char * name(int which) const
Returns name at position (or NULL)
CoinModelHash(const CoinModelHash &)
The copy constructor.
void validateHash() const
Validates.
const char *const * names() const
Names.
char * getName(int which) const
Returns non const name at position (or NULL)
~CoinModelHash()
Destructor.
int hashValue(const char *name) const
Returns a hash value.
void setNumberItems(int number)
Set number of items.
void deleteHash(int index)
Deletes from hash.
CoinModelHash & operator=(const CoinModelHash &)
=
const CoinBigIndex * previous() const
Previous array.
void updateDeleted(int which, CoinModelTriple *triples, CoinModelLinkedList &otherList)
Deletes from list - other case i.e.
void validateLinks(const CoinModelTriple *triples) const
Checks that links are consistent.
~CoinModelLinkedList()
Destructor.
CoinBigIndex lastFree() const
Last on free chain.
CoinBigIndex firstFree() const
First on free chain.
CoinBigIndex * first_
First - maximumMajor+1 long (last free element chain)
CoinBigIndex numberElements_
Number of elements.
int numberMajor_
Number of major items i.e. rows if just row links.
int type_
0 row list, 1 column list
void addHard(CoinBigIndex first, const CoinModelTriple *triples, CoinBigIndex firstFree, CoinBigIndex lastFree, const CoinBigIndex *nextOther)
Adds to list - hard case i.e.
CoinBigIndex * next_
Next - maximumElements long.
CoinBigIndex * previous_
Previous - maximumElements long.
CoinBigIndex maximumElements() const
Maximum number of elements.
void deleteRowOne(CoinBigIndex position, CoinModelTriple *triples, CoinModelHash2 &hash)
Deletes one element from Row list.
CoinBigIndex addEasy(int majorIndex, CoinBigIndex numberOfElements, const int *indices, const double *elements, CoinModelTriple *triples, CoinModelHash2 &hash)
Adds to list - easy case i.e.
CoinBigIndex numberElements() const
Number of elements.
CoinModelLinkedList & operator=(const CoinModelLinkedList &)
=
CoinModelLinkedList(const CoinModelLinkedList &)
The copy constructor.
void resize(int maxMajor, CoinBigIndex maxElements)
Resize list - for row list maxMajor is maximum rows.
CoinBigIndex last(int which) const
Last on chain.
CoinBigIndex maximumElements_
Maximum number of elements.
void synchronize(CoinModelLinkedList &other)
Puts in free list from other list.
int maximumMajor() const
Maximum number of major items i.e. rows if just row links.
void fill(int first, int last)
Fills first,last with -1.
CoinBigIndex first(int which) const
First on chain.
CoinModelLinkedList()
Default constructor.
void addHard(int minorIndex, CoinBigIndex numberOfElements, const int *indices, const double *elements, CoinModelTriple *triples, CoinModelHash2 &hash)
Adds to list - hard case i.e.
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.
int maximumMajor_
Maximum number of major items i.e. rows if just row links.
CoinBigIndex * last_
Last - maximumMajor+1 long (last free element chain)
void deleteSame(int which, CoinModelTriple *triples, CoinModelHash2 &hash, bool zapTriples)
Deletes from list - same case i.e.
void updateDeletedOne(CoinBigIndex position, const CoinModelTriple *triples)
Update column list for one element when one element deleted from row copy.
const CoinBigIndex * next() const
Next array.
int numberMajor() const
Number of major items i.e. rows if just row links.
CoinYacc(const CoinYacc &rhs)
symrec * symtable
CoinYacc & operator=(const CoinYacc &rhs)
for linked lists
For string evaluation.
struct symrec * next
union symrec::@0 value