Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
opt
build
coinutils
coinutils-2.6.4
CoinUtils
src
CoinModelUseful.hpp
Go to the documentation of this file.
1
/* $Id: CoinModelUseful.hpp 1215 2009-11-05 11:03:04Z forrest $ */
2
// Copyright (C) 2005, International Business Machines
3
// Corporation and others. All Rights Reserved.
4
#ifndef CoinModelUseful_H
5
#define CoinModelUseful_H
6
7
8
#include <cmath>
9
#include <cassert>
10
#include <cfloat>
11
#include <cstring>
12
#include <cstdio>
13
#include <iostream>
14
15
16
#include "
CoinPragma.hpp
"
17
#include "
CoinFinite.hpp
"
18
26
28
class
CoinModelLink
{
29
30
public
:
34
CoinModelLink
();
36
~CoinModelLink
();
38
42
CoinModelLink
(
const
CoinModelLink
&);
44
CoinModelLink
&
operator=
(
const
CoinModelLink
&);
46
49
inline
int
row
()
const
51
{
return
row_
;}
53
inline
int
column
()
const
54
{
return
column_
;}
56
inline
double
value
()
const
57
{
return
value_
;}
59
inline
double
element
()
const
60
{
return
value_
;}
62
inline
int
position
()
const
63
{
return
position_
;}
65
inline
bool
onRow
()
const
66
{
return
onRow_
;}
68
inline
void
setRow
(
int
row
)
69
{
row_
=
row
;}
71
inline
void
setColumn
(
int
column
)
72
{
column_
=
column
;}
74
inline
void
setValue
(
double
value
)
75
{
value_
=
value
;}
77
inline
void
setElement
(
double
value
)
78
{
value_
=
value
;}
80
inline
void
setPosition
(
int
position
)
81
{
position_
=
position
;}
83
inline
void
setOnRow
(
bool
onRow
)
84
{
onRow_
=
onRow
;}
86
87
private
:
90
int
row_
;
93
int
column_
;
95
double
value_
;
97
int
position_
;
99
bool
onRow_
;
101
};
102
104
// for specifying triple
105
typedef
struct
{
106
// top bit is nonzero if string
107
// rest is row
108
unsigned
int
row
;
109
//CoinModelRowIndex row;
110
int
column
;
111
double
value
;
// If string then index into strings
112
}
CoinModelTriple
;
113
inline
int
rowInTriple
(
const
CoinModelTriple
& triple)
114
{
return
triple.
row
&0x7fffffff;}
115
inline
void
setRowInTriple
(
CoinModelTriple
& triple,
int
iRow)
116
{ triple.
row
= iRow|(triple.
row
&0x80000000);}
117
inline
bool
stringInTriple
(
const
CoinModelTriple
& triple)
118
{
return
(triple.
row
&0x80000000)!=0;}
119
inline
void
setStringInTriple
(
CoinModelTriple
& triple,
bool
string
)
120
{ triple.
row
= (
string
? 0x80000000 : 0)|(triple.
row
&0x7fffffff);}
121
inline
void
setRowAndStringInTriple
(
CoinModelTriple
& triple,
122
int
iRow,
bool
string
)
123
{ triple.
row
= (
string
? 0x80000000 : 0)|iRow;}
125
// for hashing
126
typedef
struct
{
127
int
index,
next
;
128
}
CoinModelHashLink
;
129
130
/* Function type. */
131
typedef
double (*
func_t
) (double);
132
134
/* Data type for links in the chain of symbols. */
135
struct
symrec
136
{
137
char
*
name
;
/* name of symbol */
138
int
type
;
/* type of symbol: either VAR or FNCT */
139
union
140
{
141
double
var
;
/* value of a VAR */
142
func_t
fnctptr
;
/* value of a FNCT */
143
}
value
;
144
struct
symrec
*
next
;
/* link field */
145
};
146
147
typedef
struct
symrec
symrec
;
148
149
class
CoinYacc
{
150
private
:
151
CoinYacc
(
const
CoinYacc
& rhs);
152
CoinYacc
&
operator=
(
const
CoinYacc
& rhs);
153
154
public
:
155
CoinYacc
() :
symtable
(NULL),
symbuf
(NULL),
length
(0),
unsetValue
(0) {}
156
~CoinYacc
()
157
{
158
if
(
length
) {
159
free(
symbuf
);
160
symbuf
= NULL;
161
}
162
symrec
* s =
symtable
;
163
while
(s) {
164
free(s->
name
);
165
symtable
= s;
166
s = s->
next
;
167
free(
symtable
);
168
}
169
}
170
171
public
:
172
symrec
*
symtable
;
173
char
*
symbuf
;
174
int
length
;
175
double
unsetValue
;
176
};
177
178
class
CoinModelHash
{
179
180
public
:
184
CoinModelHash
();
186
~CoinModelHash
();
188
192
CoinModelHash
(
const
CoinModelHash
&);
194
CoinModelHash
&
operator=
(
const
CoinModelHash
&);
196
199
void
resize
(
int
maxItems,
bool
forceReHash=
false
);
202
inline
int
numberItems
()
const
203
{
return
numberItems_
;}
205
void
setNumberItems
(
int
number);
207
inline
int
maximumItems
()
const
208
{
return
maximumItems_
;}
210
inline
const
char
*
const
*
names
()
const
211
{
return
names_
;}
213
216
int
hash
(
const
char
*
name
)
const
;
219
void
addHash
(
int
index,
const
char
*
name
);
221
void
deleteHash
(
int
index);
223
const
char
*
name
(
int
which)
const
;
225
char
*
getName
(
int
which)
const
;
227
void
setName
(
int
which,
char
*
name
) ;
229
void
validateHash
()
const
;
230
private
:
232
int
hashValue
(
const
char
*
name
)
const
;
233
public
:
235
private
:
238
char
**
names_
;
241
CoinModelHashLink
*
hash_
;
243
int
numberItems_
;
245
int
maximumItems_
;
247
int
lastSlot_
;
249
};
251
class
CoinModelHash2
{
252
253
public
:
257
CoinModelHash2
();
259
~CoinModelHash2
();
261
265
CoinModelHash2
(
const
CoinModelHash2
&);
267
CoinModelHash2
&
operator=
(
const
CoinModelHash2
&);
269
272
void
resize
(
int
maxItems,
const
CoinModelTriple
* triples,
bool
forceReHash=
false
);
275
inline
int
numberItems
()
const
276
{
return
numberItems_
;}
278
void
setNumberItems
(
int
number);
280
inline
int
maximumItems
()
const
281
{
return
maximumItems_
;}
283
286
int
hash
(
int
row,
int
column,
const
CoinModelTriple
* triples)
const
;
289
void
addHash
(
int
index,
int
row,
int
column,
const
CoinModelTriple
* triples);
291
void
deleteHash
(
int
index,
int
row,
int
column);
292
private
:
294
int
hashValue
(
int
row,
int
column)
const
;
295
public
:
297
private
:
300
CoinModelHashLink
*
hash_
;
303
int
numberItems_
;
305
int
maximumItems_
;
307
int
lastSlot_
;
309
};
310
class
CoinModelLinkedList
{
311
312
public
:
316
CoinModelLinkedList
();
318
~CoinModelLinkedList
();
320
324
CoinModelLinkedList
(
const
CoinModelLinkedList
&);
326
CoinModelLinkedList
&
operator=
(
const
CoinModelLinkedList
&);
328
333
void
resize
(
int
maxMajor,
int
maxElements);
337
void
create
(
int
maxMajor,
int
maxElements,
338
int
numberMajor
,
int
numberMinor,
339
int
type,
340
int
numberElements
,
const
CoinModelTriple
* triples);
342
inline
int
numberMajor
()
const
343
{
return
numberMajor_
;}
345
inline
int
maximumMajor
()
const
346
{
return
maximumMajor_
;}
348
inline
int
numberElements
()
const
349
{
return
numberElements_
;}
351
inline
int
maximumElements
()
const
352
{
return
maximumElements_
;}
354
inline
int
firstFree
()
const
355
{
return
first_
[
maximumMajor_
];}
357
inline
int
lastFree
()
const
358
{
return
last_
[
maximumMajor_
];}
360
inline
int
first
(
int
which)
const
361
{
return
first_
[which];}
363
inline
int
last
(
int
which)
const
364
{
return
last_
[which];}
366
inline
const
int
*
next
()
const
367
{
return
next_
;}
369
inline
const
int
*
previous
()
const
370
{
return
previous_
;}
372
378
int
addEasy
(
int
majorIndex,
int
numberOfElements,
const
int
* indices,
379
const
double
* elements,
CoinModelTriple
* triples,
380
CoinModelHash2
& hash);
383
void
addHard
(
int
minorIndex,
int
numberOfElements,
const
int
* indices,
384
const
double
* elements,
CoinModelTriple
* triples,
385
CoinModelHash2
& hash);
389
void
addHard
(
int
first
,
const
CoinModelTriple
* triples,
390
int
firstFree
,
int
lastFree
,
const
int
* nextOther);
393
void
deleteSame
(
int
which,
CoinModelTriple
* triples,
394
CoinModelHash2
& hash,
bool
zapTriples);
398
void
updateDeleted
(
int
which,
CoinModelTriple
* triples,
399
CoinModelLinkedList
& otherList);
402
void
deleteRowOne
(
int
position,
CoinModelTriple
* triples,
403
CoinModelHash2
& hash);
407
void
updateDeletedOne
(
int
position,
const
CoinModelTriple
* triples);
409
void
fill
(
int
first
,
int
last
);
411
void
synchronize
(
CoinModelLinkedList
& other);
413
void
validateLinks
(
const
CoinModelTriple
* triples)
const
;
415
private
:
418
int
*
previous_
;
421
int
*
next_
;
423
int
*
first_
;
425
int
*
last_
;
427
int
numberMajor_
;
429
int
maximumMajor_
;
431
int
numberElements_
;
433
int
maximumElements_
;
435
int
type_
;
437
};
438
439
#endif
Generated on Tue Mar 1 2016 22:31:56 by
1.8.4