Ipopt 3.11.9
Loading...
Searching...
No Matches
IpCompoundVector.hpp
Go to the documentation of this file.
1// Copyright (C) 2004, 2006 International Business Machines and others.
2// All Rights Reserved.
3// This code is published under the Eclipse Public License.
4//
5// $Id: IpCompoundVector.hpp 1861 2010-12-21 21:34:47Z andreasw $
6//
7// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
8
9#ifndef __IPCOMPOUNDVECTOR_HPP__
10#define __IPCOMPOUNDVECTOR_HPP__
11
12#include "IpUtils.hpp"
13#include "IpVector.hpp"
14#include <vector>
15
16namespace Ipopt
17{
18
19 /* forward declarations */
20 class CompoundVectorSpace;
21
30 class CompoundVector : public Vector
31 {
32 public:
45 CompoundVector(const CompoundVectorSpace* owner_space, bool create_new);
46
48 virtual ~CompoundVector();
50
54 void SetComp(Index icomp, const Vector& vec);
55
59 void SetCompNonConst(Index icomp, Vector& vec);
60
62 inline Index NComps() const;
63
65 bool IsCompConst(Index i) const
66 {
67 DBG_ASSERT(i > 0 && i < NComps());
69 if (IsValid(const_comps_[i])) {
70 return true;
71 }
72 return false;
73 }
74
76 bool IsCompNull(Index i) const
77 {
78 DBG_ASSERT(i >= 0 && i < NComps());
79 if (IsValid(comps_[i]) || IsValid(const_comps_[i])) {
80 return false;
81 }
82 return true;
83 }
84
87 {
88 return ConstComp(i);
89 }
90
97 {
99 return Comp(i);
100 }
101
102 protected:
106 virtual void CopyImpl(const Vector& x);
107
109 virtual void ScalImpl(Number alpha);
110
112 virtual void AxpyImpl(Number alpha, const Vector &x);
113
115 virtual Number DotImpl(const Vector &x) const;
116
118 virtual Number Nrm2Impl() const;
119
121 virtual Number AsumImpl() const;
122
124 virtual Number AmaxImpl() const;
125
127 virtual void SetImpl(Number value);
128
130 virtual void ElementWiseDivideImpl(const Vector& x);
131
133 virtual void ElementWiseMultiplyImpl(const Vector& x);
134
136 virtual void ElementWiseMaxImpl(const Vector& x);
137
139 virtual void ElementWiseMinImpl(const Vector& x);
140
143
145 virtual void ElementWiseAbsImpl();
146
148 virtual void ElementWiseSqrtImpl();
149
151 virtual void ElementWiseSgnImpl();
152
154 virtual void AddScalarImpl(Number scalar);
155
157 virtual Number MaxImpl() const;
158
160 virtual Number MinImpl() const;
161
163 virtual Number SumImpl() const;
164
166 virtual Number SumLogsImpl() const;
167
172 void AddTwoVectorsImpl(Number a, const Vector& v1,
173 Number b, const Vector& v2, Number c);
175 Number FracToBoundImpl(const Vector& delta, Number tau) const;
177 void AddVectorQuotientImpl(Number a, const Vector& z, const Vector& s,
178 Number c);
180
183 virtual bool HasValidNumbersImpl() const;
184
187 /* Print the entire vector with padding */
188 virtual void PrintImpl(const Journalist& jnlst,
189 EJournalLevel level,
190 EJournalCategory category,
191 const std::string& name,
192 Index indent,
193 const std::string& prefix) const;
195
196 private:
208
211
215
219 std::vector< SmartPtr<Vector> > comps_;
220 std::vector< SmartPtr<const Vector> > const_comps_;
221
223
225
227
228 inline const Vector* ConstComp(Index i) const;
229
230 inline Vector* Comp(Index i);
231 };
232
240 {
241 public:
246 CompoundVectorSpace(Index ncomp_spaces, Index total_dim);
247
252
254 virtual void SetCompSpace(Index icomp ,
255 const VectorSpace& vec_space
256 );
257
260
263 {
264 return ncomp_spaces_;
265 }
266
268 virtual CompoundVector* MakeNewCompoundVector(bool create_new = true) const
269 {
270 return new CompoundVector(this, create_new);
271 }
272
275 virtual Vector* MakeNew() const
276 {
277 return MakeNewCompoundVector();
278 }
279
280 private:
291
294
298
301
303 std::vector< SmartPtr<const VectorSpace> > comp_spaces_;
304 };
305
306 /* inline methods */
307 inline
309 {
310 return owner_space_->NCompSpaces();
311 }
312
313 inline
315 {
316 DBG_ASSERT(i < NComps());
318 if (IsValid(comps_[i])) {
319 return GetRawPtr(comps_[i]);
320 }
321 else if (IsValid(const_comps_[i])) {
322 return GetRawPtr(const_comps_[i]);
323 }
324
325 DBG_ASSERT(false && "shouldn't be here");
326 return NULL;
327 }
328
329 inline
331 {
332 DBG_ASSERT(i < NComps());
334 return GetRawPtr(comps_[i]);
335 }
336
337} // namespace Ipopt
338
339#endif
#define DBG_ASSERT(test)
Definition IpDebug.hpp:38
Number * x
Input: Starting point Output: Optimal solution.
This vectors space is the vector space for CompoundVector.
CompoundVectorSpace(Index ncomp_spaces, Index total_dim)
Constructor, has to be given the number of components and the total dimension of all components combi...
SmartPtr< const VectorSpace > GetCompSpace(Index icomp) const
Method for obtaining an individual component VectorSpace.
CompoundVectorSpace(const CompoundVectorSpace &)
Copy Constructor.
virtual void SetCompSpace(Index icomp, const VectorSpace &vec_space)
Method for setting the individual component VectorSpaces.
CompoundVectorSpace()
Default constructor.
CompoundVectorSpace & operator=(const CompoundVectorSpace &)
Overloaded Equals Operator.
std::vector< SmartPtr< const VectorSpace > > comp_spaces_
std::vector of vector spaces for the components
virtual Vector * MakeNew() const
Overloaded MakeNew method for the VectorSpace base class.
Index NCompSpaces() const
Accessor method to obtain the number of components.
const Index ncomp_spaces_
Number of components.
virtual CompoundVector * MakeNewCompoundVector(bool create_new=true) const
Method for creating a new vector of this specific type.
Class of Vectors consisting of other vectors.
virtual Number Nrm2Impl() const
Computes the 2-norm of this vector (DNRM2)
virtual void AxpyImpl(Number alpha, const Vector &x)
Add the multiple alpha of vector x to this vector (DAXPY)
virtual ~CompoundVector()
Default destructor.
virtual Number MaxImpl() const
Max value in the vector.
void SetComp(Index icomp, const Vector &vec)
Method for setting the pointer for a component that is a const Vector.
SmartPtr< const Vector > GetComp(Index i) const
Return a particular component (const version)
std::vector< SmartPtr< const Vector > > const_comps_
virtual void ElementWiseMultiplyImpl(const Vector &x)
Element-wise multiplication .
virtual void PrintImpl(const Journalist &jnlst, EJournalLevel level, EJournalCategory category, const std::string &name, Index indent, const std::string &prefix) const
Print the entire vector.
virtual Number AsumImpl() const
Computes the 1-norm of this vector (DASUM)
virtual Number AmaxImpl() const
Computes the max-norm of this vector (based on IDAMAX)
void operator=(const CompoundVector &)
Overloaded Equals Operator.
CompoundVector()
Default Constructor.
virtual Number SumLogsImpl() const
Computes the sum of the logs of the elements of vector.
std::vector< SmartPtr< Vector > > comps_
Components of the compound vector.
virtual void ElementWiseSgnImpl()
Replaces entries with sgn of the entry.
Number FracToBoundImpl(const Vector &delta, Number tau) const
Fraction to the boundary parameter.
bool IsCompNull(Index i) const
Check if a particular component is null or not.
virtual void ElementWiseDivideImpl(const Vector &x)
Element-wise division .
virtual Number MinImpl() const
Min value in the vector.
virtual void ElementWiseMinImpl(const Vector &x)
Element-wise min against entries in x.
bool IsCompConst(Index i) const
Check if a particular component is const or not.
SmartPtr< Vector > GetCompNonConst(Index i)
Return a particular component (non-const version).
const CompoundVectorSpace * owner_space_
virtual void ScalImpl(Number alpha)
Scales the vector by scalar alpha (DSCAL)
virtual void ElementWiseMaxImpl(const Vector &x)
Element-wise max against entries in x.
virtual void SetImpl(Number value)
Set each element in the vector to the scalar alpha.
virtual void AddScalarImpl(Number scalar)
Add scalar to every component of the vector.
virtual void CopyImpl(const Vector &x)
Copy the data of the vector x into this vector (DCOPY).
virtual void ElementWiseReciprocalImpl()
Element-wise reciprocal.
virtual void ElementWiseAbsImpl()
Element-wise absolute values.
void AddVectorQuotientImpl(Number a, const Vector &z, const Vector &s, Number c)
Add the quotient of two vectors, y = a * z/s + c * y.
virtual Number DotImpl(const Vector &x) const
Computes inner product of vector x with this (DDOT)
void AddTwoVectorsImpl(Number a, const Vector &v1, Number b, const Vector &v2, Number c)
Add two vectors (a * v1 + b * v2).
CompoundVector(const CompoundVectorSpace *owner_space, bool create_new)
Constructor, given the corresponding CompoundVectorSpace.
virtual void ElementWiseSqrtImpl()
Element-wise square-root.
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
Index NComps() const
Number of components of this compound vector.
virtual Number SumImpl() const
Computes the sum of the lements of vector.
CompoundVector(const CompoundVector &)
Copy Constructor.
const Vector * ConstComp(Index i) const
void SetCompNonConst(Index icomp, Vector &vec)
Method for setting the pointer for a component that is a non-const Vector.
Class responsible for all message output.
Template class for Smart Pointers.
void ObjectChanged()
Objects derived from TaggedObject MUST call this method every time their internal state changes to up...
VectorSpace base class, corresponding to the Vector base class.
Definition IpVector.hpp:391
Vector Base Class.
Definition IpVector.hpp:48
bool IsValid(const SmartPtr< U > &smart_ptr)
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
EJournalCategory
Category Selection Enum.
int Index
Type of all indices of vectors, matrices etc.
Definition IpTypes.hpp:19
EJournalLevel
Print Level Enum.
double Number
Type of all numbers.
Definition IpTypes.hpp:17