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
IpUtils.hpp
Ipopt::CompoundVector::SetImpl
virtual void SetImpl(Number value)
Set each element in the vector to the scalar alpha.
Ipopt::CompoundVector::SumLogsImpl
virtual Number SumLogsImpl() const
Sum of logs of entries in the vector.
Ipopt::CompoundVector::CompoundVector
CompoundVector(const CompoundVector &)
Copy Constructor.
Ipopt::CompoundVector::Nrm2Impl
virtual Number Nrm2Impl() const
Computes the 2-norm of this vector (DNRM2)
Ipopt::CompoundVectorSpace::CompoundVectorSpace
CompoundVectorSpace()
Default constructor.
Ipopt::CompoundVector::ElementWiseDivideImpl
virtual void ElementWiseDivideImpl(const Vector &x)
Element-wise division .
Ipopt::CompoundVectorSpace::GetCompSpace
SmartPtr< const VectorSpace > GetCompSpace(Index icomp) const
Method for obtaining an individual component VectorSpace.
Ipopt::CompoundVector::AmaxImpl
virtual Number AmaxImpl() const
Computes the max-norm of this vector (based on IDAMAX)
Ipopt::CompoundVector::ElementWiseReciprocalImpl
virtual void ElementWiseReciprocalImpl()
Reciprocates the elements of the vector.
Ipopt::CompoundVectorSpace::CompoundVectorSpace
CompoundVectorSpace(Index ncomp_spaces, Index total_dim)
Constructor, has to be given the number of components and the total dimension of all components combi...
Ipopt::CompoundVector::IsCompNull
bool IsCompNull(Index i) const
Check if a particular component is null or not.
Definition: IpCompoundVector.hpp:85
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
This file contains a base class for all exceptions and a set of macros to help with exceptions.
Definition: IpInexactAlgBuilder.hpp:14
Ipopt::Number
double Number
Type of all numbers.
Definition: IpTypes.hpp:15
Ipopt::CompoundVectorSpace::comp_spaces_
std::vector< SmartPtr< const VectorSpace > > comp_spaces_
std::vector of vector spaces for the components
Definition: IpCompoundVector.hpp:352
Ipopt::CompoundVectorSpace::NCompSpaces
Index NCompSpaces() const
Accessor method to obtain the number of components.
Definition: IpCompoundVector.hpp:307
Ipopt::CompoundVector::ElementWiseSqrtImpl
virtual void ElementWiseSqrtImpl()
Take elementwise square-root of the elements of the vector.
Ipopt::CompoundVector::comps_
std::vector< SmartPtr< Vector > > comps_
Components of the compound vector.
Definition: IpCompoundVector.hpp:252
Ipopt::CompoundVector::MinImpl
virtual Number MinImpl() const
Min number in the vector.
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::CompoundVector::AxpyImpl
virtual void AxpyImpl(Number alpha, const Vector &x)
Add the multiple alpha of vector x to this vector (DAXPY)
Ipopt::CompoundVector::vectors_valid_
bool vectors_valid_
Definition: IpCompoundVector.hpp:257
Ipopt::EJournalLevel
EJournalLevel
Print Level Enum.
Definition: IpJournalist.hpp:32
Ipopt::CompoundVector::GetComp
SmartPtr< const Vector > GetComp(Index i) const
Return a particular component (const version)
Definition: IpCompoundVector.hpp:98
Ipopt::CompoundVector::IsCompConst
bool IsCompConst(Index i) const
Check if a particular component is const or not.
Definition: IpCompoundVector.hpp:71
Ipopt::CompoundVector::CopyImpl
virtual void CopyImpl(const Vector &x)
Copy the data of the vector x into this vector (DCOPY).
Ipopt::CompoundVectorSpace::MakeNew
virtual Vector * MakeNew() const
Pure virtual method for creating a new Vector of the corresponding type.
Definition: IpCompoundVector.hpp:320
IPOPTLIB_EXPORT
#define IPOPTLIB_EXPORT
Definition: config_default.h:16
Ipopt::CompoundVector::ScalImpl
virtual void ScalImpl(Number alpha)
Scales the vector by scalar alpha (DSCAL)
Ipopt::CompoundVector::SetCompNonConst
void SetCompNonConst(Index icomp, Vector &vec)
Method for setting the pointer for a component that is a non-const Vector.
Ipopt::CompoundVector::~CompoundVector
virtual ~CompoundVector()
Default destructor.
Ipopt::CompoundVector::GetCompNonConst
SmartPtr< Vector > GetCompNonConst(Index i)
Return a particular component (non-const version).
Definition: IpCompoundVector.hpp:111
Ipopt::CompoundVector::FracToBoundImpl
Number FracToBoundImpl(const Vector &delta, Number tau) const
Fraction to boundary parameter.
Ipopt::Index
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
Ipopt::CompoundVector::HasValidNumbersImpl
virtual bool HasValidNumbersImpl() const
Method for determining if all stored numbers are valid (i.e., no Inf or Nan).
Ipopt::GetRawPtr
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:651
Ipopt::CompoundVector::VectorsValid
bool VectorsValid()
Ipopt::SmartPtr
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
Ipopt::CompoundVectorSpace::operator=
CompoundVectorSpace & operator=(const CompoundVectorSpace &)
Default Assignment Operator.
Ipopt::EJournalCategory
EJournalCategory
Category Selection Enum.
Definition: IpJournalist.hpp:52
Ipopt::CompoundVector::NComps
Index NComps() const
Number of components of this compound vector.
Definition: IpCompoundVector.hpp:356
Ipopt::CompoundVector::AddVectorQuotientImpl
void AddVectorQuotientImpl(Number a, const Vector &z, const Vector &s, Number c)
Add the quotient of two vectors.
Ipopt::CompoundVector::ElementWiseAbsImpl
virtual void ElementWiseAbsImpl()
Take elementwise absolute values of the elements of the vector.
Ipopt::CompoundVector::Comp
Vector * Comp(Index i)
Definition: IpCompoundVector.hpp:380
Ipopt::CompoundVectorSpace::ncomp_spaces_
const Index ncomp_spaces_
Number of components.
Definition: IpCompoundVector.hpp:349
Ipopt::CompoundVectorSpace::SetCompSpace
virtual void SetCompSpace(Index icomp, const VectorSpace &vec_space)
Method for setting the individual component VectorSpaces.
Ipopt::CompoundVector::CompoundVector
CompoundVector(const CompoundVectorSpace *owner_space, bool create_new)
Constructor, given the corresponding CompoundVectorSpace.
Ipopt::Journalist
Class responsible for all message output.
Definition: IpJournalist.hpp:117
Ipopt::CompoundVector::ConstComp
const Vector * ConstComp(Index i) const
Definition: IpCompoundVector.hpp:361
Ipopt::CompoundVector::AddScalarImpl
virtual void AddScalarImpl(Number scalar)
Add scalar to every component of vector.
Ipopt::CompoundVector::const_comps_
std::vector< SmartPtr< const Vector > > const_comps_
Definition: IpCompoundVector.hpp:253
Ipopt::CompoundVector::SumImpl
virtual Number SumImpl() const
Sum of entries in the vector.
Ipopt::VectorSpace
VectorSpace base class, corresponding to the Vector base class.
Definition: IpVector.hpp:459
Ipopt::CompoundVector::ElementWiseMaxImpl
virtual void ElementWiseMaxImpl(const Vector &x)
Element-wise max against entries in x.
Ipopt::CompoundVector::ElementWiseMultiplyImpl
virtual void ElementWiseMultiplyImpl(const Vector &x)
Element-wise multiplication .
IpVector.hpp
Ipopt::CompoundVector
Class of Vectors consisting of other vectors.
Definition: IpCompoundVector.hpp:31
Ipopt::CompoundVector::operator=
void operator=(const CompoundVector &)
Default Assignment Operator.
Ipopt::IsValid
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:674
Ipopt::CompoundVector::SetComp
void SetComp(Index icomp, const Vector &vec)
Method for setting the pointer for a component that is a const Vector.
Ipopt::CompoundVector::CompoundVector
CompoundVector()
Default Constructor.
Ipopt::CompoundVector::DotImpl
virtual Number DotImpl(const Vector &x) const
Computes inner product of vector x with this (DDOT)
DBG_ASSERT
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:28
Ipopt::CompoundVectorSpace::~CompoundVectorSpace
~CompoundVectorSpace()
Destructor.
Definition: IpCompoundVector.hpp:291
Ipopt::CompoundVector::owner_space_
const CompoundVectorSpace * owner_space_
Definition: IpCompoundVector.hpp:255
Ipopt::CompoundVectorSpace::CompoundVectorSpace
CompoundVectorSpace(const CompoundVectorSpace &)
Copy Constructor.
Ipopt::CompoundVector::MaxImpl
virtual Number MaxImpl() const
Max value in the vector.
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::CompoundVectorSpace
This vectors space is the vector space for CompoundVector.
Definition: IpCompoundVector.hpp:278
Ipopt::CompoundVectorSpace::MakeNewCompoundVector
virtual CompoundVector * MakeNewCompoundVector(bool create_new=true) const
Method for creating a new vector of this specific type.
Definition: IpCompoundVector.hpp:313
Ipopt::CompoundVector::AsumImpl
virtual Number AsumImpl() const
Computes the 1-norm of this vector (DASUM)
Ipopt::Vector
Vector Base Class.
Definition: IpVector.hpp:48