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 
62  void SetCompNonConst(
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 
153  virtual void ElementWiseMultiplyImpl(
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 
165  virtual void ElementWiseReciprocalImpl();
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 
188  void AddTwoVectorsImpl(
189  Number a,
190  const Vector& v1,
191  Number b,
192  const Vector& v2,
193  Number c
194  );
195 
196  Number FracToBoundImpl(
197  const Vector& delta,
198  Number tau
199  ) const;
200 
201  void AddVectorQuotientImpl(
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:
235  CompoundVector();
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 
302  SmartPtr<const VectorSpace> GetCompSpace(
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 
343  CompoundVectorSpace& operator=(
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::IsCompNull
bool IsCompNull(Index i) const
Check if a particular component is null or not.
Definition: IpCompoundVector.hpp:85
Ipopt
This file contains a base class for all exceptions and a set of macros to help with exceptions.
Definition: IpInexactAlgBuilder.hpp:13
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::comps_
std::vector< SmartPtr< Vector > > comps_
Components of the compound vector.
Definition: IpCompoundVector.hpp:252
Ipopt::CompoundVector::vectors_valid_
bool vectors_valid_
Definition: IpCompoundVector.hpp:257
Ipopt::EJournalLevel
EJournalLevel
Print Level Enum.
Definition: IpJournalist.hpp:31
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::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::GetCompNonConst
SmartPtr< Vector > GetCompNonConst(Index i)
Return a particular component (non-const version).
Definition: IpCompoundVector.hpp:111
Ipopt::Index
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
Ipopt::GetRawPtr
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:651
Ipopt::SmartPtr
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:171
Ipopt::EJournalCategory
EJournalCategory
Category Selection Enum.
Definition: IpJournalist.hpp:51
Ipopt::CompoundVector::NComps
Index NComps() const
Number of components of this compound vector.
Definition: IpCompoundVector.hpp:356
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::Journalist
Class responsible for all message output.
Definition: IpJournalist.hpp:116
Ipopt::CompoundVector::ConstComp
const Vector * ConstComp(Index i) const
Definition: IpCompoundVector.hpp:361
Ipopt::CompoundVector::const_comps_
std::vector< SmartPtr< const Vector > > const_comps_
Definition: IpCompoundVector.hpp:253
Ipopt::VectorSpace
VectorSpace base class, corresponding to the Vector base class.
Definition: IpVector.hpp:458
IpVector.hpp
Ipopt::CompoundVector
Class of Vectors consisting of other vectors.
Definition: IpCompoundVector.hpp:30
Ipopt::IsValid
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:674
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
This vectors space is the vector space for CompoundVector.
Definition: IpCompoundVector.hpp:277
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::Vector
Vector Base Class.
Definition: IpVector.hpp:47