CoinUtils
2.9.0
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
CoinUtils
src
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
Generated by
1.8.4