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 ElementWiseSelectImpl(
158  const Vector& x
159  );
160 
161  virtual void ElementWiseMaxImpl(
162  const Vector& x
163  );
164 
165  virtual void ElementWiseMinImpl(
166  const Vector& x
167  );
168 
169  virtual void ElementWiseReciprocalImpl();
170 
171  virtual void ElementWiseAbsImpl();
172 
173  virtual void ElementWiseSqrtImpl();
174 
175  virtual void ElementWiseSgnImpl();
176 
177  virtual void AddScalarImpl(
178  Number scalar
179  );
180 
181  virtual Number MaxImpl() const;
182 
183  virtual Number MinImpl() const;
184 
185  virtual Number SumImpl() const;
186 
187  virtual Number SumLogsImpl() const;
189 
191  void AddTwoVectorsImpl(
193  Number a,
194  const Vector& v1,
195  Number b,
196  const Vector& v2,
197  Number c
198  );
199 
200  Number FracToBoundImpl(
201  const Vector& delta,
202  Number tau
203  ) const;
204 
205  void AddVectorQuotientImpl(
206  Number a,
207  const Vector& z,
208  const Vector& s,
209  Number c
210  );
212 
214  virtual bool HasValidNumbersImpl() const;
215 
217  virtual void PrintImpl(
219  const Journalist& jnlst,
220  EJournalLevel level,
221  EJournalCategory category,
222  const std::string& name,
223  Index indent,
224  const std::string& prefix
225  ) const;
227 
228 private:
237 
239  CompoundVector();
240 
243  const CompoundVector&
244  );
245 
247  void operator=(
248  const CompoundVector&
249  );
251 
256  std::vector<SmartPtr<Vector> > comps_;
257  std::vector<SmartPtr<const Vector> > const_comps_;
258 
260 
262 
263  bool VectorsValid();
264 
265  inline const Vector* ConstComp(
266  Index i
267  ) const;
268 
269  inline Vector* Comp(
270  Index i
271  );
272 };
273 
282 {
283 public:
285 
290  Index ncomp_spaces,
291  Index total_dim
292  );
293 
296  { }
298 
300  virtual void SetCompSpace(
301  Index icomp,
302  const VectorSpace& vec_space
303  );
304 
306  SmartPtr<const VectorSpace> GetCompSpace(
307  Index icomp
308  ) const;
309 
312  {
313  return ncomp_spaces_;
314  }
315 
318  bool create_new = true
319  ) const
320  {
321  return new CompoundVector(this, create_new);
322  }
323 
324  virtual Vector* MakeNew() const
325  {
326  return MakeNewCompoundVector();
327  }
328 
329 private:
337 
340 
343  const CompoundVectorSpace&
344  );
345 
347  CompoundVectorSpace& operator=(
348  const CompoundVectorSpace&
349  );
351 
354 
356  std::vector<SmartPtr<const VectorSpace> > comp_spaces_;
357 };
358 
359 /* inline methods */
361 {
362  return owner_space_->NCompSpaces();
363 }
364 
366  Index i
367 ) const
368 {
369  DBG_ASSERT(i < NComps());
371  if( IsValid(comps_[i]) )
372  {
373  return GetRawPtr(comps_[i]);
374  }
375  else if( IsValid(const_comps_[i]) )
376  {
377  return GetRawPtr(const_comps_[i]);
378  }
379 
380  DBG_ASSERT(false && "shouldn't be here");
381  return NULL;
382 }
383 
385  Index i
386 )
387 {
388  DBG_ASSERT(i < NComps());
390  return GetRawPtr(comps_[i]);
391 }
392 
393 } // namespace Ipopt
394 
395 #endif
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:672
virtual ~CompoundVector()
Default destructor.
const Index ncomp_spaces_
Number of components.
std::vector< SmartPtr< Vector > > comps_
Components of the compound vector.
#define IPOPTLIB_EXPORT
Definition: config.h:94
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.
ipindex Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:20
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:164
VectorSpace base class, corresponding to the Vector base class.
Definition: IpVector.hpp:472
bool IsCompNull(Index i) const
Check if a particular component is null or not.
U * GetRawPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:649
SmartPtr< const Vector > GetComp(Index i) const
Return a particular component (const version)
ipnumber Number
Type of all numbers.
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
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_