Ipopt  3.12.12
 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());
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  {
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 
211 
213  void operator=(const CompoundVector&);
215 
219  std::vector< SmartPtr<Vector> > comps_;
220  std::vector< SmartPtr<const Vector> > const_comps_;
221 
223 
225 
226  bool VectorsValid();
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 
250  {}
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
Index NCompSpaces() const
Accessor method to obtain the number of components.
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:579
std::vector< SmartPtr< const VectorSpace > > comp_spaces_
std::vector of vector spaces for the components
Number * x
Input: Starting point Output: Optimal solution.
void SetComp(Index icomp, const Vector &vec)
Method for setting the pointer for a component that is a const Vector.
virtual Vector * MakeNew() const
Overloaded MakeNew method for the VectorSpace base class.
virtual void AxpyImpl(Number alpha, const Vector &x)
Add the multiple alpha of vector x to this vector (DAXPY)
Index NComps() const
Number of components of this compound vector.
virtual Number MinImpl() const
Min value in the vector.
virtual void ElementWiseSqrtImpl()
Element-wise square-root.
virtual Number AmaxImpl() const
Computes the max-norm of this vector (based on IDAMAX)
virtual ~CompoundVector()
Default destructor.
const Index ncomp_spaces_
Number of components.
virtual void CopyImpl(const Vector &x)
Copy the data of the vector x into this vector (DCOPY).
virtual void ElementWiseMinImpl(const Vector &x)
Element-wise min against entries in x.
virtual void ElementWiseSgnImpl()
Replaces entries with sgn of the entry.
virtual Number Nrm2Impl() const
Computes the 2-norm of this vector (DNRM2)
double Number
Type of all numbers.
Definition: IpTypes.hpp:17
void AddVectorQuotientImpl(Number a, const Vector &z, const Vector &s, Number c)
Add the quotient of two vectors, y = a * z/s + c * y.
SmartPtr< Vector > GetCompNonConst(Index i)
Return a particular component (non-const version).
void ObjectChanged()
Objects derived from TaggedObject MUST call this method every time their internal state changes to up...
Number FracToBoundImpl(const Vector &delta, Number tau) const
Fraction to the boundary parameter.
Vector Base Class.
Definition: IpVector.hpp:47
virtual void SetImpl(Number value)
Set each element in the vector to the scalar alpha.
virtual void ElementWiseAbsImpl()
Element-wise absolute values.
virtual Number AsumImpl() const
Computes the 1-norm of this vector (DASUM)
EJournalLevel
Print Level Enum.
virtual Number MaxImpl() const
Max value in the vector.
void AddTwoVectorsImpl(Number a, const Vector &v1, Number b, const Vector &v2, Number c)
Add two vectors (a * v1 + b * v2).
Vector * Comp(Index i)
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
CompoundVectorSpace()
Default constructor.
VectorSpace base class, corresponding to the Vector base class.
Definition: IpVector.hpp:390
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:560
virtual void ElementWiseMaxImpl(const Vector &x)
Element-wise max against entries in x.
const Vector * ConstComp(Index i) const
virtual void AddScalarImpl(Number scalar)
Add scalar to every component of the vector.
SmartPtr< const VectorSpace > GetCompSpace(Index icomp) const
Method for obtaining an individual component VectorSpace.
virtual Number DotImpl(const Vector &x) const
Computes inner product of vector x with this (DDOT)
CompoundVector()
Default Constructor.
void operator=(const CompoundVector &)
Overloaded Equals Operator.
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
virtual void ScalImpl(Number alpha)
Scales the vector by scalar alpha (DSCAL)
bool IsCompConst(Index i) const
Check if a particular component is const or not.
std::vector< SmartPtr< const Vector > > const_comps_
void SetCompNonConst(Index icomp, Vector &vec)
Method for setting the pointer for a component that is a non-const Vector.
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:38
SmartPtr< const Vector > GetComp(Index i) const
Return a particular component (const version)
virtual Number SumLogsImpl() const
Computes the sum of the logs of the elements of vector.
const CompoundVectorSpace * owner_space_
Class responsible for all message output.
bool IsCompNull(Index i) const
Check if a particular component is null or not.
This vectors space is the vector space for CompoundVector.
virtual Number SumImpl() const
Computes the sum of the lements of vector.
virtual void ElementWiseDivideImpl(const Vector &x)
Element-wise division .
CompoundVectorSpace & operator=(const CompoundVectorSpace &)
Overloaded Equals Operator.
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
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 CompoundVector * MakeNewCompoundVector(bool create_new=true) const
Method for creating a new vector of this specific type.
EJournalCategory
Category Selection Enum.
virtual void SetCompSpace(Index icomp, const VectorSpace &vec_space)
Method for setting the individual component VectorSpaces.
Class of Vectors consisting of other vectors.
virtual void ElementWiseReciprocalImpl()
Element-wise reciprocal.
std::vector< SmartPtr< Vector > > comps_
Components of the compound vector.