SoPlex Doxygen Documentation
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
src
dsvector.h
Go to the documentation of this file.
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2
/* */
3
/* This file is part of the class library */
4
/* SoPlex --- the Sequential object-oriented simPlex. */
5
/* */
6
/* Copyright (C) 1996-2012 Konrad-Zuse-Zentrum */
7
/* fuer Informationstechnik Berlin */
8
/* */
9
/* SoPlex is distributed under the terms of the ZIB Academic Licence. */
10
/* */
11
/* You should have received a copy of the ZIB Academic License */
12
/* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */
13
/* */
14
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15
16
/**@file dsvector.h
17
* @brief Dynamic sparse vectors.
18
*/
19
#ifndef _DSVECTOR_H_
20
#define _DSVECTOR_H_
21
22
#include <assert.h>
23
24
#include "
spxdefines.h
"
25
#include "
svector.h
"
26
#include "
ssvector.h
"
27
28
namespace
soplex
29
{
30
/**@brief Dynamic sparse vectors.
31
@ingroup Algebra
32
33
Class DSVector implements dynamic sparse vectors, i.e. #SVector%s
34
with an automatic memory management. This allows the user to freely add()
35
as many nonzeros to a DSVector as desired, without any precautions.
36
For saving memory method setMax() allows to reduce memory consumption to
37
the amount really required.
38
39
@todo Both DSVector and SVector have a member variable that points to
40
allocated memory. This does not seem to make too much sense.
41
Why doesn't DSVector use the element of its base class?
42
*/
43
class
DSVector
:
public
SVector
44
{
45
friend
class
SLinSolver
;
46
47
private
:
48
49
//-----------------------------------
50
/**@name Data */
51
//@{
52
Element*
theelem
;
///< here is where the memory is
53
//@}
54
55
//-----------------------------------
56
/**@name Private memory helpers */
57
//@{
58
/// allocate memory for \p n nonzeros.
59
void
allocMem
(
int
n);
60
/// make sure there is room for \p n new nonzeros.
61
void
makeMem
(
int
n)
62
{
63
if
(
max
() -
size
() < ++n)
64
setMax
(
size
() + n);
65
}
66
//@}
67
68
public
:
69
70
//-----------------------------------
71
/**@name Construction / destruction */
72
//@{
73
/// default constructor.
74
/** Creates a DSVector ready to hold \p n nonzeros. However, the memory is
75
* automatically enlarged, if more nonzeros are added to the DSVector.
76
*/
77
explicit
DSVector
(
int
n = 8);
78
79
/// destructor.
80
~DSVector
();
81
/// copy constructor from vector.
82
explicit
DSVector
(
const
Vector
& vec);
83
/// copy constructor from sparse vector.
84
explicit
DSVector
(
const
SVector
& old);
85
/// copy constructor from semi sparse vector.
86
explicit
DSVector
(
const
SSVector
& old);
87
/// copy constructor from DSVector.
88
DSVector
(
const
DSVector
& old);
89
90
/// assignment operator from semi sparse vector.
91
DSVector
&
operator=
(
const
SSVector
& sv)
92
{
93
int
n = sv.
size
();
94
clear
();
95
makeMem
(n);
96
SVector::operator=
(sv);
97
return
*
this
;
98
}
99
/// assignment operator from sparse vector.
100
DSVector
&
operator=
(
const
SVector
& sv)
101
{
102
int
n = sv.
size
();
103
clear
();
104
makeMem
(n);
105
SVector::operator=
(sv);
106
return
*
this
;
107
}
108
/// assignment operator.
109
DSVector
&
operator=
(
const
DSVector
& sv)
110
{
111
if
(
this
!= &sv)
112
{
113
int
n = sv.
size
();
114
clear
();
115
makeMem
(n);
116
SVector::operator=
(sv);
117
}
118
return
*
this
;
119
}
120
/// assignment operator from vector.
121
DSVector
&
operator=
(
const
Vector
& vec);
122
//@}
123
124
//-----------------------------------
125
/**@name Adding nonzeros */
126
//@{
127
/// append nonzeros of \p sv.
128
void
add
(
const
SVector
& sv)
129
{
130
int
n = sv.
size
();
131
clear
();
132
makeMem
(n);
133
SVector::add
(sv);
134
}
135
136
/// append one nonzero \p (i,v).
137
void
add
(
int
i,
Real
v)
138
{
139
makeMem
(1);
140
SVector::add
(i, v);
141
}
142
143
/// append \p n nonzeros.
144
void
add
(
int
n,
const
int
i[],
const
Real
v[])
145
{
146
makeMem
(n);
147
SVector::add
(n, i, v);
148
}
149
150
/// reset nonzero memory to >= \p newmax.
151
/** This methods resets the memory consumption of the DIdxSet to
152
* \p newmax. However, if \p newmax < size(), it is reset to size()
153
* only.
154
*/
155
void
setMax
(
int
newmax = 1);
156
//@}
157
158
//-----------------------------------
159
/**@name Consistency check */
160
//@{
161
/// consistency check.
162
bool
isConsistent
()
const
;
163
//@}
164
};
165
}
// namespace soplex
166
#endif // _DSVECTOR_H_
167
168
//-----------------------------------------------------------------------------
169
//Emacs Local Variables:
170
//Emacs mode:c++
171
//Emacs c-basic-offset:3
172
//Emacs tab-width:8
173
//Emacs indent-tabs-mode:nil
174
//Emacs End:
175
//-----------------------------------------------------------------------------
176
© 2003-2013 by Zuse Institute Berlin (ZIB),
Imprint
Generated on Wed Jan 9 2013 for SoPlex by
doxygen