Ipopt Documentation  
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 
14 namespace Ipopt
15 {
16 
17 /* forward declarations */
18 class CompoundVectorSpace;
19 
31 {
32 public:
47  const CompoundVectorSpace* owner_space,
48  bool create_new
49  );
50 
52  virtual ~CompoundVector();
54 
56  void SetComp(
57  Index icomp,
58  const Vector& vec
59  );
60 
63  Index icomp,
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 
85  bool IsCompNull(
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 
119 protected:
122  virtual void CopyImpl(
123  const Vector& x
124  );
125 
126  virtual void ScalImpl(
127  Number alpha
128  );
129 
130  virtual void AxpyImpl(
131  Number alpha,
132  const Vector& x
133  );
134 
135  virtual Number DotImpl(
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(
146  Number value
147  );
148 
149  virtual void ElementWiseDivideImpl(
150  const Vector& x
151  );
152 
154  const Vector& x
155  );
156 
157  virtual void ElementWiseMaxImpl(
158  const Vector& x
159  );
160 
161  virtual void ElementWiseMinImpl(
162  const Vector& x
163  );
164 
166 
167  virtual void ElementWiseAbsImpl();
168 
169  virtual void ElementWiseSqrtImpl();
170 
171  virtual void ElementWiseSgnImpl();
172 
173  virtual void AddScalarImpl(
174  Number scalar
175  );
176 
177  virtual Number MaxImpl() const;
178 
179  virtual Number MinImpl() const;
180 
181  virtual Number SumImpl() const;
182 
183  virtual Number SumLogsImpl() const;
185 
189  Number a,
190  const Vector& v1,
191  Number b,
192  const Vector& v2,
193  Number c
194  );
195 
197  const Vector& delta,
198  Number tau
199  ) const;
200 
202  Number a,
203  const Vector& z,
204  const Vector& s,
205  Number c
206  );
208 
210  virtual bool HasValidNumbersImpl() const;
211 
214  virtual void PrintImpl(
215  const Journalist& jnlst,
216  EJournalLevel level,
217  EJournalCategory category,
218  const std::string& name,
219  Index indent,
220  const std::string& prefix
221  ) const;
223 
224 private:
236 
239  const CompoundVector&
240  );
241 
243  void operator=(
244  const CompoundVector&
245  );
247 
252  std::vector<SmartPtr<Vector> > comps_;
253  std::vector<SmartPtr<const Vector> > const_comps_;
254 
256 
258 
259  bool VectorsValid();
260 
261  inline const Vector* ConstComp(
262  Index i
263  ) const;
264 
265  inline Vector* Comp(
266  Index i
267  );
268 };
269 
278 {
279 public:
286  Index ncomp_spaces,
287  Index total_dim
288  );
289 
292  { }
294 
296  virtual void SetCompSpace(
297  Index icomp,
298  const VectorSpace& vec_space
299  );
300 
303  Index icomp
304  ) const;
305 
308  {
309  return ncomp_spaces_;
310  }
311 
314  bool create_new = true
315  ) const
316  {
317  return new CompoundVector(this, create_new);
318  }
319 
320  virtual Vector* MakeNew() const
321  {
322  return MakeNewCompoundVector();
323  }
324 
325 private:
336 
339  const CompoundVectorSpace&
340  );
341 
344  const CompoundVectorSpace&
345  );
347 
350 
352  std::vector<SmartPtr<const VectorSpace> > comp_spaces_;
353 };
354 
355 /* inline methods */
357 {
358  return owner_space_->NCompSpaces();
359 }
360 
362  Index i
363 ) const
364 {
365  DBG_ASSERT(i < NComps());
367  if( IsValid(comps_[i]) )
368  {
369  return GetRawPtr(comps_[i]);
370  }
371  else if( IsValid(const_comps_[i]) )
372  {
373  return GetRawPtr(const_comps_[i]);
374  }
375 
376  DBG_ASSERT(false && "shouldn't be here");
377  return NULL;
378 }
379 
381  Index i
382 )
383 {
384  DBG_ASSERT(i < NComps());
386  return GetRawPtr(comps_[i]);
387 }
388 
389 } // namespace Ipopt
390 
391 #endif
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:28
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 Vector * MakeNew() const
Pure virtual method for creating a new Vector of the corresponding type.
virtual void SetCompSpace(Index icomp, const VectorSpace &vec_space)
Method for setting the individual component VectorSpaces.
CompoundVectorSpace()
Default constructor.
virtual CompoundVector * MakeNewCompoundVector(bool create_new=true) const
Method for creating a new vector of this specific type.
CompoundVectorSpace & operator=(const CompoundVectorSpace &)
Default Assignment Operator.
Index NCompSpaces() const
Accessor method to obtain the number of components.
const Index ncomp_spaces_
Number of components.
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.
Vector * Comp(Index i)
void SetComp(Index icomp, const Vector &vec)
Method for setting the pointer for a component that is a const Vector.
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.
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.
SmartPtr< Vector > GetCompNonConst(Index i)
Return a particular component (non-const version).
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_
SmartPtr< const Vector > GetComp(Index i) const
Return a particular component (const version)
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.
Class responsible for all message output.
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
VectorSpace base class, corresponding to the Vector base class.
Definition: IpVector.hpp:459
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)
Definition: IpSmartPtr.hpp:674
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:651
EJournalCategory
Category Selection Enum.
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
EJournalLevel
Print Level Enum.
double Number
Type of all numbers.
Definition: IpTypes.hpp:15