Ipopt 3.12.10

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 2269 2013-05-05 11:32:40Z stefan $
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
16 namespace 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());
68 DBG_ASSERT(IsValid(comps_[i]) || IsValid(const_comps_[i]));
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
86 SmartPtr<const Vector> GetComp(Index i) const
87 {
88 return ConstComp(i);
89 }
90
96 SmartPtr<Vector> GetCompNonConst(Index i)
97 {
98 ObjectChanged();
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
142 virtual void ElementWiseReciprocalImpl();
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:
207 CompoundVector();
208
210 CompoundVector(const CompoundVector&);
211
213 void operator=(const CompoundVector&);
215
219 std::vector< SmartPtr<Vector> > comps_;
220 std::vector< SmartPtr<const Vector> > const_comps_;
221
222 const CompoundVectorSpace* owner_space_;
223
224 bool vectors_valid_;
225
226 bool VectorsValid();
227
228 inline const Vector* ConstComp(Index i) const;
229
230 inline Vector* Comp(Index i);
231 };
232
239 class CompoundVectorSpace : public VectorSpace
240 {
241 public:
246 CompoundVectorSpace(Index ncomp_spaces, Index total_dim);
247
249 ~CompoundVectorSpace()
250 {}
252
254 virtual void SetCompSpace(Index icomp ,
255 const VectorSpace& vec_space
256 );
257
259 SmartPtr<const VectorSpace> GetCompSpace(Index icomp) const;
260
262 Index NCompSpaces() const
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:
290 CompoundVectorSpace();
291
293 CompoundVectorSpace(const CompoundVectorSpace&);
294
296 CompoundVectorSpace& operator=(const CompoundVectorSpace&);
298
300 const Index ncomp_spaces_;
301
303 std::vector< SmartPtr<const VectorSpace> > comp_spaces_;
304 };
305
306 /* inline methods */
307 inline
308 Index CompoundVector::NComps() const
309 {
310 return owner_space_->NCompSpaces();
311 }
312
313 inline
314 const Vector* CompoundVector::ConstComp(Index i) const
315 {
316 DBG_ASSERT(i < NComps());
317 DBG_ASSERT(IsValid(comps_[i]) || IsValid(const_comps_[i]));
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
330 Vector* CompoundVector::Comp(Index i)
331 {
332 DBG_ASSERT(i < NComps());
333 DBG_ASSERT(IsValid(comps_[i]));
334 return GetRawPtr(comps_[i]);
335 }
336
337 } // namespace Ipopt
338
339 #endif
Ipopt::CompoundVectorSpace::NCompSpaces
Index NCompSpaces() const
Accessor method to obtain the number of components.
Definition: IpCompoundVector.hpp:262
Ipopt::IsValid
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:579
Ipopt::CompoundVectorSpace::comp_spaces_
std::vector< SmartPtr< const VectorSpace > > comp_spaces_
std::vector of vector spaces for the components
Definition: IpCompoundVector.hpp:303
x
Number * x
Input: Starting point Output: Optimal solution.
Definition: IpStdCInterface.h:238
Ipopt::CompoundVector::SetComp
void SetComp(Index icomp, const Vector &vec)
Method for setting the pointer for a component that is a const Vector.
Ipopt::CompoundVectorSpace::MakeNew
virtual Vector * MakeNew() const
Overloaded MakeNew method for the VectorSpace base class.
Definition: IpCompoundVector.hpp:275
Ipopt::CompoundVector::AxpyImpl
virtual void AxpyImpl(Number alpha, const Vector &x)
Add the multiple alpha of vector x to this vector (DAXPY)
Ipopt::CompoundVector::NComps
Index NComps() const
Number of components of this compound vector.
Definition: IpCompoundVector.hpp:308
Ipopt::CompoundVector::MinImpl
virtual Number MinImpl() const
Min value in the vector.
IpUtils.hpp
Ipopt::CompoundVector::ElementWiseSqrtImpl
virtual void ElementWiseSqrtImpl()
Element-wise square-root.
IpVector.hpp
Ipopt::CompoundVector::AmaxImpl
virtual Number AmaxImpl() const
Computes the max-norm of this vector (based on IDAMAX)
Ipopt::CompoundVector::~CompoundVector
virtual ~CompoundVector()
Default destructor.
Ipopt::CompoundVectorSpace::ncomp_spaces_
const Index ncomp_spaces_
Number of components.
Definition: IpCompoundVector.hpp:300
Ipopt::CompoundVector::CopyImpl
virtual void CopyImpl(const Vector &x)
Copy the data of the vector x into this vector (DCOPY).
Ipopt::CompoundVector::ElementWiseMinImpl
virtual void ElementWiseMinImpl(const Vector &x)
Element-wise min against entries in x.
Ipopt::CompoundVector::ElementWiseSgnImpl
virtual void ElementWiseSgnImpl()
Replaces entries with sgn of the entry.
Ipopt::CompoundVector::vectors_valid_
bool vectors_valid_
Definition: IpCompoundVector.hpp:224
Ipopt::CompoundVector::Nrm2Impl
virtual Number Nrm2Impl() const
Computes the 2-norm of this vector (DNRM2)
Ipopt::Number
double Number
Type of all numbers.
Definition: IpTypes.hpp:17
Ipopt::CompoundVector::AddVectorQuotientImpl
void AddVectorQuotientImpl(Number a, const Vector &z, const Vector &s, Number c)
Add the quotient of two vectors, y = a * z/s + c * y.
Ipopt::CompoundVector::GetCompNonConst
SmartPtr< Vector > GetCompNonConst(Index i)
Return a particular component (non-const version).
Definition: IpCompoundVector.hpp:96
Ipopt::TaggedObject::ObjectChanged
void ObjectChanged()
Objects derived from TaggedObject MUST call this method every time their internal state changes to up...
Definition: IpTaggedObject.hpp:117
Ipopt::CompoundVector::FracToBoundImpl
Number FracToBoundImpl(const Vector &delta, Number tau) const
Fraction to the boundary parameter.
Ipopt::Vector
Vector Base Class.
Definition: IpVector.hpp:47
Ipopt::CompoundVector::SetImpl
virtual void SetImpl(Number value)
Set each element in the vector to the scalar alpha.
Ipopt::CompoundVector::ElementWiseAbsImpl
virtual void ElementWiseAbsImpl()
Element-wise absolute values.
Ipopt::CompoundVector::AsumImpl
virtual Number AsumImpl() const
Computes the 1-norm of this vector (DASUM)
Ipopt::CompoundVector::VectorsValid
bool VectorsValid()
Ipopt::EJournalLevel
EJournalLevel
Print Level Enum.
Definition: IpJournalist.hpp:51
Ipopt::CompoundVector::MaxImpl
virtual Number MaxImpl() const
Max value in the vector.
Ipopt::CompoundVector::AddTwoVectorsImpl
void AddTwoVectorsImpl(Number a, const Vector &v1, Number b, const Vector &v2, Number c)
Add two vectors (a * v1 + b * v2).
Ipopt::CompoundVector::Comp
Vector * Comp(Index i)
Definition: IpCompoundVector.hpp:330
Ipopt::SmartPtr
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
Ipopt::CompoundVectorSpace::CompoundVectorSpace
CompoundVectorSpace()
Default constructor.
Ipopt::VectorSpace
VectorSpace base class, corresponding to the Vector base class.
Definition: IpVector.hpp:390
Ipopt::GetRawPtr
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:560
Ipopt::CompoundVector::ElementWiseMaxImpl
virtual void ElementWiseMaxImpl(const Vector &x)
Element-wise max against entries in x.
Ipopt::CompoundVector::ConstComp
const Vector * ConstComp(Index i) const
Definition: IpCompoundVector.hpp:314
Ipopt::CompoundVectorSpace::~CompoundVectorSpace
~CompoundVectorSpace()
Destructor.
Definition: IpCompoundVector.hpp:249
Ipopt::CompoundVector::AddScalarImpl
virtual void AddScalarImpl(Number scalar)
Add scalar to every component of the vector.
Ipopt::CompoundVectorSpace::GetCompSpace
SmartPtr< const VectorSpace > GetCompSpace(Index icomp) const
Method for obtaining an individual component VectorSpace.
Ipopt::CompoundVector::DotImpl
virtual Number DotImpl(const Vector &x) const
Computes inner product of vector x with this (DDOT)
Ipopt::CompoundVector::CompoundVector
CompoundVector()
Default Constructor.
Ipopt::CompoundVector::operator=
void operator=(const CompoundVector &)
Overloaded Equals Operator.
Ipopt::Index
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
Ipopt::CompoundVector::ScalImpl
virtual void ScalImpl(Number alpha)
Scales the vector by scalar alpha (DSCAL)
Ipopt::CompoundVector::IsCompConst
bool IsCompConst(Index i) const
Check if a particular component is const or not.
Definition: IpCompoundVector.hpp:65
Ipopt::CompoundVector::const_comps_
std::vector< SmartPtr< const Vector > > const_comps_
Definition: IpCompoundVector.hpp:220
Ipopt::CompoundVector::SetCompNonConst
void SetCompNonConst(Index icomp, Vector &vec)
Method for setting the pointer for a component that is a non-const Vector.
DBG_ASSERT
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:38
Ipopt::CompoundVector::GetComp
SmartPtr< const Vector > GetComp(Index i) const
Return a particular component (const version)
Definition: IpCompoundVector.hpp:86
Ipopt::CompoundVector::SumLogsImpl
virtual Number SumLogsImpl() const
Computes the sum of the logs of the elements of vector.
Ipopt::CompoundVector::owner_space_
const CompoundVectorSpace * owner_space_
Definition: IpCompoundVector.hpp:222
Ipopt::Journalist
Class responsible for all message output.
Definition: IpJournalist.hpp:134
Ipopt::CompoundVector::IsCompNull
bool IsCompNull(Index i) const
Check if a particular component is null or not.
Definition: IpCompoundVector.hpp:76
Ipopt::CompoundVectorSpace
This vectors space is the vector space for CompoundVector.
Definition: IpCompoundVector.hpp:239
Ipopt::CompoundVector::SumImpl
virtual Number SumImpl() const
Computes the sum of the lements of vector.
Ipopt::CompoundVector::ElementWiseDivideImpl
virtual void ElementWiseDivideImpl(const Vector &x)
Element-wise division .
Ipopt::CompoundVectorSpace::operator=
CompoundVectorSpace & operator=(const CompoundVectorSpace &)
Overloaded Equals Operator.
Ipopt::CompoundVector::HasValidNumbersImpl
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
Ipopt::CompoundVector::ElementWiseMultiplyImpl
virtual void ElementWiseMultiplyImpl(const Vector &x)
Element-wise multiplication .
Ipopt::CompoundVector::PrintImpl
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.
Ipopt::CompoundVectorSpace::MakeNewCompoundVector
virtual CompoundVector * MakeNewCompoundVector(bool create_new=true) const
Method for creating a new vector of this specific type.
Definition: IpCompoundVector.hpp:268
Ipopt::EJournalCategory
EJournalCategory
Category Selection Enum.
Definition: IpJournalist.hpp:70
Ipopt::CompoundVectorSpace::SetCompSpace
virtual void SetCompSpace(Index icomp, const VectorSpace &vec_space)
Method for setting the individual component VectorSpaces.
Ipopt::CompoundVector
Class of Vectors consisting of other vectors.
Definition: IpCompoundVector.hpp:30
Ipopt::CompoundVector::ElementWiseReciprocalImpl
virtual void ElementWiseReciprocalImpl()
Element-wise reciprocal.
Ipopt::CompoundVector::comps_
std::vector< SmartPtr< Vector > > comps_
Components of the compound vector.
Definition: IpCompoundVector.hpp:219