Ipopt  3.11.8
 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 1861 2010-12-21 21:34:47Z andreasw $
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