1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// Copyright (C) 2005, 2008 International Business Machines and others.
// All Rights Reserved.
// This code is published under the Eclipse Public License.
//
// Authors: Andreas Waechter IBM 2005-12-24
#ifndef __IPMULTIVECTORMATRIX_HPP__
#define __IPMULTIVECTORMATRIX_HPP__
#include "IpUtils.hpp"
#include "IpMatrix.hpp"
namespace Ipopt
{
/** forward declarations */
class MultiVectorMatrixSpace;
/** Class for Matrices with few columns that consists of Vectors.
*
* Those matrices are for example useful in the implementation of
* limited memory quasi-Newton methods.
*/
class IPOPTLIB_EXPORT MultiVectorMatrix: public Matrix
{
public:
/**@name Constructors / Destructors */
///@{
/** Constructor, taking the owner_space.
*/
MultiVectorMatrix(
const MultiVectorMatrixSpace* owner_space
);
/** Destructor */
~MultiVectorMatrix();
///@}
/** Create a new MultiVectorMatrix from same MatrixSpace */
SmartPtr<MultiVectorMatrix> MakeNewMultiVectorMatrix() const;
/** Set a particular Vector at a given column position, replacing
* another vector if there has been one.
*
* Depending on whether the Vector is const or not, it is stored
* in the const or non-const internal column. */
///@{
void SetVector(
Index i,
const Vector& vec
);
/* For the non-const version, keep in mind that operations that
* change this matrix also change the Vector that has been given
* here.
*/
void SetVectorNonConst(
Index i,
Vector& vec
);
///@}
/** Get a Vector in a particular column as a const Vector */
inline SmartPtr<const Vector> GetVector(
Index i
) const
{
return ConstVec(i);
}
/** Get a Vector in a particular column as a non-const
* Vector.
*
* This is fail if the column has currently only a non-const Vector stored.
*/
inline SmartPtr<Vector> GetVectorNonConst(
Index i
)
{
ObjectChanged();
return Vec(i);
}
/** Method for scaling the rows of the matrix, using the
* ElementWiseMultiply method for each column vector.
*/
void ScaleRows(
const Vector& scal_vec
);
/** Method for scaling the columns of the matrix, using the Scale
* method for each column vector.
*/
void ScaleColumns(
const Vector& scal_vec);
/** Adding another MultiVectorMatrix, using the AddOneVector
* methods for the individual column vectors
*/
void AddOneMultiVectorMatrix(
Number a,
const MultiVectorMatrix& mv1,
Number c
);
/** Multiplying a Matrix C (for now assumed to be a DenseGenMatrix)
* from the right to a MultiVectorMatrix U and adding the result
* to this MultiVectorMatrix V. V = a * U * C + b * V.
*/
void AddRightMultMatrix(
Number a,
const MultiVectorMatrix& U,
const Matrix& C,
Number b
);
/** Method for initializing all Vectors with new (uninitialized) Vectors. */
void FillWithNewVectors();
/** Method for adding the low-rank update matrix corresponding to
* this matrix to a vector.
*
* If V is this MultiVectorMatrix, the
* operation is y = beta*y + alpha*V*V^T*x.
*/
void LRMultVector(
Number alpha,
const Vector& x,
Number beta,
Vector& y
) const;
/** Vector space for the columns */
SmartPtr<const VectorSpace> ColVectorSpace() const;
/** Return the MultiVectorMatrixSpace */
SmartPtr<const MultiVectorMatrixSpace> MultiVectorMatrixOwnerSpace() const;
protected:
/**@name Overloaded methods from Matrix base class */
///@{
virtual void MultVectorImpl(
Number alpha,
const Vector& x,
Number beta,
Vector& y
) const;
virtual void TransMultVectorImpl(
Number alpha,
const Vector& x,
Number beta,
Vector& y
) const;
virtual bool HasValidNumbersImpl() const;
virtual void ComputeRowAMaxImpl(
Vector& rows_norms,
bool init
) const;
virtual void ComputeColAMaxImpl(
Vector& cols_norms,
bool init
) const;
virtual void PrintImpl(
const Journalist& jnlst,
EJournalLevel level,
EJournalCategory category,
const std::string& name,
Index indent,
const std::string& prefix
) const;
///@}
private:
/**@name Default Compiler Generated Methods
* (Hidden to avoid implicit creation/calling).
* These methods are not implemented and
* we do not want the compiler to implement
* them for us, so we declare them private
* and do not define them. This ensures that
* they will not be implicitly created/called.
*/
///@{
/** Default Constructor */
MultiVectorMatrix();
/** Copy Constructor */
MultiVectorMatrix(
const MultiVectorMatrix&
);
/** Default Assignment Operator */
void operator=(
const MultiVectorMatrix&
);
///@}
const MultiVectorMatrixSpace* owner_space_;
/** space for storing the const Vector's */
std::vector<SmartPtr<const Vector> > const_vecs_;
/** space for storing the non-const Vector's */
std::vector<SmartPtr<Vector> > non_const_vecs_;
/** Method for accessing the internal Vectors internally */
///@{
inline const Vector* ConstVec(
Index i
) const
{
DBG_ASSERT(i < NCols());
DBG_ASSERT(IsValid(const_vecs_[i]) || IsValid(non_const_vecs_[i]));
if( IsValid(non_const_vecs_[i]) )
{
return GetRawPtr(non_const_vecs_[i]);
}
else
{
return GetRawPtr(const_vecs_[i]);
}
}
inline Vector* Vec(
Index i
)
{
DBG_ASSERT(i < NCols());
DBG_ASSERT(IsValid(non_const_vecs_[i]));
return GetRawPtr(non_const_vecs_[i]);
}
///@}
};
/** This is the matrix space for MultiVectorMatrix. */
class IPOPTLIB_EXPORT MultiVectorMatrixSpace: public MatrixSpace
{
public:
/** @name Constructors / Destructors */
///@{
/** Constructor, given the number of columns (i.e., Vectors to be
* stored) and given the VectorSpace for the Vectors.
*/
MultiVectorMatrixSpace(
Index ncols,
const VectorSpace& vec_space
);
/** Destructor */
~MultiVectorMatrixSpace()
{ }
///@}
/** Method for creating a new matrix of this specific type. */
MultiVectorMatrix* MakeNewMultiVectorMatrix() const
{
return new MultiVectorMatrix(this);
}
virtual Matrix* MakeNew() const
{
return MakeNewMultiVectorMatrix();
}
/** Accessor method for the VectorSpace for the columns */
SmartPtr<const VectorSpace> ColVectorSpace() const
{
return vec_space_;
}
private:
SmartPtr<const VectorSpace> vec_space_;
};
inline MultiVectorMatrix::~MultiVectorMatrix()
{ }
inline SmartPtr<MultiVectorMatrix> MultiVectorMatrix::MakeNewMultiVectorMatrix() const
{
return owner_space_->MakeNewMultiVectorMatrix();
}
inline SmartPtr<const VectorSpace> MultiVectorMatrix::ColVectorSpace() const
{
return owner_space_->ColVectorSpace();
}
inline SmartPtr<const MultiVectorMatrixSpace> MultiVectorMatrix::MultiVectorMatrixOwnerSpace() const
{
return owner_space_;
}
} // namespace Ipopt
#endif