Ipopt Documentation  
 
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// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
6
7#ifndef __IPCOMPOUNDVECTOR_HPP__
8#define __IPCOMPOUNDVECTOR_HPP__
9
10#include "IpUtils.hpp"
11#include "IpVector.hpp"
12#include <vector>
13
14namespace Ipopt
15{
16
17/* forward declarations */
18class CompoundVectorSpace;
19
31{
32public:
35
48 bool create_new
49 );
50
52 virtual ~CompoundVector() { }
54
56 void SetComp(
58 const Vector& vec
59 );
60
64 Vector& vec
65 );
66
68 inline Index NComps() const;
69
72 Index i
73 ) const
74 {
75 DBG_ASSERT(i > 0 && i < NComps());
76 DBG_ASSERT(IsValid(comps_[i]) || IsValid(const_comps_[i]));
77 if( IsValid(const_comps_[i]) )
78 {
79 return true;
80 }
81 return false;
82 }
83
86 Index i
87 ) const
88 {
89 DBG_ASSERT(i >= 0 && i < NComps());
90 if( IsValid(comps_[i]) || IsValid(const_comps_[i]) )
91 {
92 return false;
93 }
94 return true;
95 }
96
99 Index i
100 ) const
101 {
102 return ConstComp(i);
103 }
104
112 Index i
113 )
114 {
115 ObjectChanged();
116 return Comp(i);
117 }
118
119protected:
122 virtual void CopyImpl(
123 const Vector& x
124 );
125
126 virtual void ScalImpl(
128 );
129
130 virtual void AxpyImpl(
132 const Vector& x
133 );
134
136 const Vector& x
137 ) const;
138
139 virtual Number Nrm2Impl() const;
140
141 virtual Number AsumImpl() const;
142
143 virtual Number AmaxImpl() const;
144
145 virtual void SetImpl(
147 );
148
150 const Vector& x
151 );
152
154 const Vector& x
155 );
156
158 const Vector& x
159 );
160
161 virtual void ElementWiseMaxImpl(
162 const Vector& x
163 );
164
165 virtual void ElementWiseMinImpl(
166 const Vector& x
167 );
168
170
171 virtual void ElementWiseAbsImpl();
172
173 virtual void ElementWiseSqrtImpl();
174
175 virtual void ElementWiseSgnImpl();
176
177 virtual void AddScalarImpl(
179 );
180
181 virtual Number MaxImpl() const;
182
183 virtual Number MinImpl() const;
184
185 virtual Number SumImpl() const;
186
187 virtual Number SumLogsImpl() const;
189
193 Number a,
194 const Vector& v1,
195 Number b,
196 const Vector& v2,
197 Number c
198 );
199
201 const Vector& delta,
202 Number tau
203 ) const;
204
206 Number a,
207 const Vector& z,
208 const Vector& s,
209 Number c
210 );
212
214 virtual bool HasValidNumbersImpl() const;
215
218 virtual void PrintImpl(
219 const Journalist& jnlst,
222 const std::string& name,
224 const std::string& prefix
225 ) const;
227
228private:
238
240
243 const CompoundVector&
244 );
245
248 const CompoundVector&
249 );
251
256 std::vector<SmartPtr<Vector> > comps_;
257 std::vector<SmartPtr<const Vector> > const_comps_;
258
260
262
264
265 inline const Vector* ConstComp(
266 Index i
267 ) const;
268
269 inline Vector* Comp(
270 Index i
271 );
272};
273
282{
283public:
286
292 );
293
298
300 virtual void SetCompSpace(
301 Index icomp,
302 const VectorSpace& vec_space
303 );
304
308 ) const;
309
312 {
313 return ncomp_spaces_;
314 }
315
318 bool create_new = true
319 ) const
320 {
321 return new CompoundVector(this, create_new);
322 }
323
324 virtual Vector* MakeNew() const
325 {
326 return MakeNewCompoundVector();
327 }
328
329private:
338
340
344 );
345
349 );
351
354
356 std::vector<SmartPtr<const VectorSpace> > comp_spaces_;
357};
358
359/* inline methods */
361{
362 return owner_space_->NCompSpaces();
363}
364
366 Index i
367) const
368{
369 DBG_ASSERT(i < NComps());
371 if( IsValid(comps_[i]) )
372 {
373 return GetRawPtr(comps_[i]);
374 }
375 else if( IsValid(const_comps_[i]) )
376 {
377 return GetRawPtr(const_comps_[i]);
378 }
379
380 DBG_ASSERT(false && "shouldn't be here");
381 return NULL;
382}
383
385 Index i
386)
387{
388 DBG_ASSERT(i < NComps());
390 return GetRawPtr(comps_[i]);
391}
392
393} // namespace Ipopt
394
395#endif
#define DBG_ASSERT(test)
Definition IpDebug.hpp:27
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.
std::vector< SmartPtr< const VectorSpace > > comp_spaces_
std::vector of vector spaces for the components
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 &)
Default Assignment Operator.
virtual Vector * MakeNew() const
Pure virtual method for creating a new Vector of the corresponding type.
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 ElementWiseSelectImpl(const Vector &x)
Element-wise selection .
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)
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.
std::vector< SmartPtr< Vector > > comps_
Components of the compound 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 &)
Default Assignment Operator.
CompoundVector()
Default Constructor.
virtual Number SumLogsImpl() const
Sum of logs of entries in the vector.
virtual void ElementWiseSgnImpl()
Replaces entries with sgn of the entry.
Number FracToBoundImpl(const Vector &delta, Number tau) const
Fraction to 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 number 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 vector.
virtual void CopyImpl(const Vector &x)
Copy the data of the vector x into this vector (DCOPY).
virtual void ElementWiseReciprocalImpl()
Reciprocates the elements of the vector.
std::vector< SmartPtr< const Vector > > const_comps_
virtual void ElementWiseAbsImpl()
Take elementwise absolute values of the elements of the vector.
void AddVectorQuotientImpl(Number a, const Vector &z, const Vector &s, Number c)
Add the quotient of two vectors.
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()
Take elementwise square-root of the elements of the vector.
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
Sum of entries in the 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.
Templated class which stores one entry for the CachedResult class.
Class responsible for all message output.
VectorSpace base class, corresponding to the Vector base class.
Definition IpVector.hpp:473
Vector Base Class.
Definition IpVector.hpp:48
#define IPOPTLIB_EXPORT
This file contains a base class for all exceptions and a set of macros to help with exceptions.
bool IsValid(const SmartPtr< U > &smart_ptr)
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
ipindex Index
Type of all indices of vectors, matrices etc.
Definition IpTypes.hpp:20
EJournalCategory
Category Selection Enum.
EJournalLevel
Print Level Enum.
ipnumber Number
Type of all numbers.
Definition IpTypes.hpp:17