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:
34 
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:
121  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 
187  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 
213  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:
233 
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:
281 
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:
333 
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
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:674
const Index ncomp_spaces_
Number of components.
std::vector< SmartPtr< Vector > > comps_
Components of the compound vector.
double Number
Type of all numbers.
Definition: IpTypes.hpp:15
SmartPtr< Vector > GetCompNonConst(Index i)
Return a particular component (non-const version).
Vector Base Class.
Definition: IpVector.hpp:47
virtual CompoundVector * MakeNewCompoundVector(bool create_new=true) const
Method for creating a new vector of this specific type.
EJournalLevel
Print Level Enum.
This file contains a base class for all exceptions and a set of macros to help with exceptions...
Vector * Comp(Index i)
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:171
VectorSpace base class, corresponding to the Vector base class.
Definition: IpVector.hpp:458
bool IsCompNull(Index i) const
Check if a particular component is null or not.
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:651
SmartPtr< const Vector > GetComp(Index i) const
Return a particular component (const version)
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17
bool IsCompConst(Index i) const
Check if a particular component is const or not.
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:27
#define IPOPTLIB_EXPORT
const CompoundVectorSpace * owner_space_
Index NComps() const
Number of components of this compound vector.
Class responsible for all message output.
std::vector< SmartPtr< const VectorSpace > > comp_spaces_
std::vector of vector spaces for the components
Index NCompSpaces() const
Accessor method to obtain the number of components.
virtual Vector * MakeNew() const
Pure virtual method for creating a new Vector of the corresponding type.
This vectors space is the vector space for CompoundVector.
EJournalCategory
Category Selection Enum.
const Vector * ConstComp(Index i) const
Class of Vectors consisting of other vectors.
std::vector< SmartPtr< const Vector > > const_comps_