Ipopt Documentation  
IpIteratesVector.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-06-06
6 
7 #ifndef __IPITERATESVECTOR_HPP__
8 #define __IPITERATESVECTOR_HPP__
9 
10 #include "IpCompoundVector.hpp"
11 
12 namespace Ipopt
13 {
14 /* forward declarations */
15 class IteratesVectorSpace;
16 
26 {
27 public:
31  const IteratesVectorSpace* owner_space,
32  bool create_new
33  );
34 
35  virtual ~IteratesVector();
37 
40 
46  bool create_new = true
47  ) const;
48 
53  {
54  SmartPtr<IteratesVector> ret = MakeNewIteratesVector(true);
55  ret->Copy(*this);
56  return ret;
57  }
58 
69 
72 
74  {
75  return GetIterateFromComp(0);
76  }
77 
82  {
83  return GetNonConstIterateFromComp(0);
84  }
85 
87  inline SmartPtr<Vector> create_new_x();
88 
93  {
94  SmartPtr<const Vector> curr_x = GetComp(0);
95  Set_x_NonConst(*curr_x->MakeNew());
96  x_NonConst()->Copy(*curr_x);
97  return x_NonConst();
98  }
99 
104  void Set_x(
105  const Vector& vec
106  )
107  {
108  SetComp(0, vec);
109  }
110 
116  Vector& vec
117  )
118  {
119  SetCompNonConst(0, vec);
120  }
121 
124  {
125  return GetIterateFromComp(1);
126  }
127 
133  {
134  return GetNonConstIterateFromComp(1);
135  }
136 
138  inline SmartPtr<Vector> create_new_s();
139 
143  {
144  SmartPtr<const Vector> curr_s = GetComp(1);
145  Set_s_NonConst(*curr_s->MakeNew());
146  s_NonConst()->Copy(*curr_s);
147  return s_NonConst();
148  }
149 
154  void Set_s(
155  const Vector& vec
156  )
157  {
158  SetComp(1, vec);
159  }
160 
166  Vector& vec
167  )
168  {
169  SetCompNonConst(1, vec);
170  }
171 
174  {
175  return GetIterateFromComp(2);
176  }
177 
183  {
184  return GetNonConstIterateFromComp(2);
185  }
186 
188  inline SmartPtr<Vector> create_new_y_c();
189 
194  {
195  SmartPtr<const Vector> curr_y_c = GetComp(2);
196  Set_y_c_NonConst(*curr_y_c->MakeNew());
197  y_c_NonConst()->Copy(*curr_y_c);
198  return y_c_NonConst();
199  }
200 
205  void Set_y_c(
206  const Vector& vec
207  )
208  {
209  SetComp(2, vec);
210  }
211 
217  Vector& vec
218  )
219  {
220  SetCompNonConst(2, vec);
221  }
222 
225  {
226  return GetIterateFromComp(3);
227  }
228 
233  {
234  return GetNonConstIterateFromComp(3);
235  }
236 
238  inline SmartPtr<Vector> create_new_y_d();
239 
244  {
245  SmartPtr<const Vector> curr_y_d = GetComp(3);
246  Set_y_d_NonConst(*curr_y_d->MakeNew());
247  y_d_NonConst()->Copy(*curr_y_d);
248  return y_d_NonConst();
249  }
250 
255  void Set_y_d(
256  const Vector& vec
257  )
258  {
259  SetComp(3, vec);
260  }
261 
267  Vector& vec
268  )
269  {
270  SetCompNonConst(3, vec);
271  }
272 
275  {
276  return GetIterateFromComp(4);
277  }
278 
284  {
285  return GetNonConstIterateFromComp(4);
286  }
287 
289  inline SmartPtr<Vector> create_new_z_L();
290 
294  {
295  SmartPtr<const Vector> curr_z_L = GetComp(4);
296  Set_z_L_NonConst(*curr_z_L->MakeNew());
297  z_L_NonConst()->Copy(*curr_z_L);
298  return z_L_NonConst();
299  }
300 
305  void Set_z_L(
306  const Vector& vec
307  )
308  {
309  SetComp(4, vec);
310  }
311 
317  Vector& vec
318  )
319  {
320  SetCompNonConst(4, vec);
321  }
322 
325  {
326  return GetIterateFromComp(5);
327  }
328 
333  {
334  return GetNonConstIterateFromComp(5);
335  }
336 
338  inline SmartPtr<Vector> create_new_z_U();
339 
344  {
345  SmartPtr<const Vector> curr_z_U = GetComp(5);
346  Set_z_U_NonConst(*curr_z_U->MakeNew());
347  z_U_NonConst()->Copy(*curr_z_U);
348  return z_U_NonConst();
349  }
350 
355  void Set_z_U(
356  const Vector& vec
357  )
358  {
359  SetComp(5, vec);
360  }
361 
367  Vector& vec
368  )
369  {
370  SetCompNonConst(5, vec);
371  }
372 
375  {
376  return GetIterateFromComp(6);
377  }
378 
384  {
385  return GetNonConstIterateFromComp(6);
386  }
387 
389  inline SmartPtr<Vector> create_new_v_L();
390 
395  {
396  SmartPtr<const Vector> curr_v_L = GetComp(6);
397  Set_v_L_NonConst(*curr_v_L->MakeNew());
398  v_L_NonConst()->Copy(*curr_v_L);
399  return v_L_NonConst();
400  }
401 
406  void Set_v_L(
407  const Vector& vec
408  )
409  {
410  SetComp(6, vec);
411  }
412 
417  Vector& vec
418  )
419  {
420  SetCompNonConst(6, vec);
421  }
422 
425  {
426  return GetIterateFromComp(7);
427  }
428 
434  {
435  return GetNonConstIterateFromComp(7);
436  }
437 
439  inline SmartPtr<Vector> create_new_v_U();
440 
445  {
446  SmartPtr<const Vector> curr_v_U = GetComp(7);
447  Set_v_U_NonConst(*curr_v_U->MakeNew());
448  v_U_NonConst()->Copy(*curr_v_U);
449  return v_U_NonConst();
450  }
451 
456  void Set_v_U(
457  const Vector& vec
458  )
459  {
460  SetComp(7, vec);
461  }
462 
468  Vector& vec
469  )
470  {
471  SetCompNonConst(7, vec);
472  }
473 
479  const Vector& x,
480  const Vector& s
481  )
482  {
483  SetComp(0, x);
484  SetComp(1, s);
485  }
487  Vector& x,
488  Vector& s
489  )
490  {
491  SetCompNonConst(0, x);
492  SetCompNonConst(1, s);
493  }
494 
500  const Vector& y_c,
501  const Vector& y_d
502  )
503  {
504  SetComp(2, y_c);
505  SetComp(3, y_d);
506  }
507 
513  Vector& y_c,
514  Vector& y_d
515  )
516  {
517  SetCompNonConst(2, y_c);
518  SetCompNonConst(3, y_d);
519  }
520 
526  const Vector& z_L,
527  const Vector& z_U,
528  const Vector& v_L,
529  const Vector& v_U
530  )
531  {
532  SetComp(4, z_L);
533  SetComp(5, z_U);
534  SetComp(6, v_L);
535  SetComp(7, v_U);
536  }
537 
543  Vector& z_L,
544  Vector& z_U,
545  Vector& v_L,
546  Vector& v_U
547  )
548  {
549  SetCompNonConst(4, z_L);
550  SetCompNonConst(5, z_U);
551  SetCompNonConst(6, v_L);
552  SetCompNonConst(7, v_U);
553  }
554 
563  {
564  TaggedObject::Tag tag = 0;
565 
566  if( IsValid(x()) )
567  {
568  tag += x()->GetTag();
569  }
570  if( IsValid(s()) )
571  {
572  tag += s()->GetTag();
573  }
574  if( IsValid(y_c()) )
575  {
576  tag += y_c()->GetTag();
577  }
578  if( IsValid(y_d()) )
579  {
580  tag += y_d()->GetTag();
581  }
582  if( IsValid(z_L()) )
583  {
584  tag += z_L()->GetTag();
585  }
586  if( IsValid(z_U()) )
587  {
588  tag += z_U()->GetTag();
589  }
590  if( IsValid(v_L()) )
591  {
592  tag += v_L()->GetTag();
593  }
594  if( IsValid(v_U()) )
595  {
596  tag += v_U()->GetTag();
597  }
598 
599  return tag;
600  }
602 
603 private:
613 
615 
618  const IteratesVector&
619  );
620 
622  void operator=(
623  const IteratesVector&
624  );
626 
628 
634  Index i
635  ) const
636  {
637  if( IsCompNull(i) )
638  {
639  return NULL;
640  }
641  return GetComp(i);
642  }
643 
649  Index i
650  )
651  {
652  if( IsCompNull(i) )
653  {
654  return NULL;
655  }
656  return GetCompNonConst(i);
657  }
658 
659 };
660 
666 {
667 public:
670 
675  const VectorSpace& x_space,
676  const VectorSpace& s_space,
677  const VectorSpace& y_c_space,
678  const VectorSpace& y_d_space,
679  const VectorSpace& z_L_space,
680  const VectorSpace& z_U_space,
681  const VectorSpace& v_L_space,
682  const VectorSpace& v_U_space
683  );
684 
687 
690 
697  bool create_new = true
698  ) const
699  {
700  return new IteratesVector(this, create_new);
701  }
702 
708  const Vector& x,
709  const Vector& s,
710  const Vector& y_c,
711  const Vector& y_d,
712  const Vector& z_L,
713  const Vector& z_U,
714  const Vector& v_L,
715  const Vector& v_U
716  )
717  {
718  SmartPtr<IteratesVector> newvec = MakeNewIteratesVector(false);
719  newvec->Set_x(x);
720  newvec->Set_s(s);
721  newvec->Set_y_c(y_c);
722  newvec->Set_y_d(y_d);
723  newvec->Set_z_L(z_L);
724  newvec->Set_z_U(z_U);
725  newvec->Set_v_L(v_L);
726  newvec->Set_v_U(v_U);
727  return ConstPtr(newvec);
728  }
729 
731  bool create_new = true
732  ) const
733  {
734  return MakeNewIteratesVector(create_new);
735  }
736 
744  virtual Vector* MakeNew() const
745  {
746  return MakeNewIteratesVector();
747  }
749 
754  virtual void SetCompSpace(
755  Index /*icomp*/,
756  const VectorSpace& /*vec_space*/
757  )
758  {
759  DBG_ASSERT(false && "This is an IteratesVectorSpace - a special compound vector for Ipopt iterates. The contained spaces should not be modified.");
760  }
761 
762 private:
772 
774 
777  const IteratesVectorSpace&
778  );
779 
782  const IteratesVectorSpace&
783  );
785 
795 };
796 
798 {
799  Set_x_NonConst(*owner_space_->GetCompSpace(0)->MakeNew());
800  return x_NonConst();
801 }
803 {
804  Set_s_NonConst(*owner_space_->GetCompSpace(1)->MakeNew());
805  return s_NonConst();
806 }
808 {
809  Set_y_c_NonConst(*owner_space_->GetCompSpace(2)->MakeNew());
810  return y_c_NonConst();
811 }
813 {
814  Set_y_d_NonConst(*owner_space_->GetCompSpace(3)->MakeNew());
815  return y_d_NonConst();
816 }
818 {
819  Set_z_L_NonConst(*owner_space_->GetCompSpace(4)->MakeNew());
820  return z_L_NonConst();
821 }
823 {
824  Set_z_U_NonConst(*owner_space_->GetCompSpace(5)->MakeNew());
825  return z_U_NonConst();
826 }
828 {
829  Set_v_L_NonConst(*owner_space_->GetCompSpace(6)->MakeNew());
830  return v_L_NonConst();
831 }
833 {
834  Set_v_U_NonConst(*owner_space_->GetCompSpace(7)->MakeNew());
835  return v_U_NonConst();
836 }
837 
838 } // namespace Ipopt
839 
840 #endif
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:27
This vectors space is the vector space for CompoundVector.
SmartPtr< const VectorSpace > GetCompSpace(Index icomp) const
Method for obtaining an individual component VectorSpace.
Class of Vectors consisting of other vectors.
Vector Space for the IteratesVector class.
const SmartPtr< const IteratesVector > MakeNewIteratesVector(const Vector &x, const Vector &s, const Vector &y_c, const Vector &y_d, const Vector &z_L, const Vector &z_U, const Vector &v_L, const Vector &v_U)
Use this method to create a new const IteratesVector.
SmartPtr< const VectorSpace > y_d_space_
virtual IteratesVector * MakeNewIteratesVector(bool create_new=true) const
Method for creating vectors .
SmartPtr< const VectorSpace > x_space_
Contained Spaces.
SmartPtr< const VectorSpace > y_c_space_
virtual CompoundVector * MakeNewCompoundVector(bool create_new=true) const
Method for creating a new vector of this specific type.
SmartPtr< const VectorSpace > z_L_space_
IteratesVectorSpace(const VectorSpace &x_space, const VectorSpace &s_space, const VectorSpace &y_c_space, const VectorSpace &y_d_space, const VectorSpace &z_L_space, const VectorSpace &z_U_space, const VectorSpace &v_L_space, const VectorSpace &v_U_space)
Constructor that takes the spaces for each of the iterates.
SmartPtr< const VectorSpace > v_U_space_
IteratesVectorSpace()
Default constructor.
IteratesVectorSpace & operator=(const IteratesVectorSpace &)
Default Assignment Operator.
virtual void SetCompSpace(Index, const VectorSpace &)
This method hides the CompoundVectorSpace::SetCompSpace method since the components of the Iterates a...
virtual Vector * MakeNew() const
This method creates a new vector (and allocates space in all the contained vectors.
SmartPtr< const VectorSpace > s_space_
SmartPtr< const VectorSpace > z_U_space_
SmartPtr< const VectorSpace > v_L_space_
IteratesVectorSpace(const IteratesVectorSpace &)
Copy Constructor.
Specialized CompoundVector class specifically for the algorithm iterates.
SmartPtr< Vector > x_NonConst()
Get the x iterate (non-const) - this can only be called if the vector was created internally,...
SmartPtr< const Vector > z_U() const
Get the z_U iterate (const)
SmartPtr< const Vector > x() const
Iterates Set/Get Methods.
SmartPtr< IteratesVector > MakeNewIteratesVectorCopy() const
Use this method to create a new iterates vector with a copy of all the data.
SmartPtr< Vector > create_new_v_L()
Create a new vector in the v_L entry.
SmartPtr< Vector > create_new_v_L_copy()
Create a new vector in the v_L entry and copy the current values into it.
SmartPtr< Vector > create_new_y_d()
Create a new vector in the y_d entry.
TaggedObject::Tag GetTagSum() const
Get a sum of the tags of the contained items.
SmartPtr< Vector > create_new_z_L()
Create a new vector in the z_L entry.
void Set_z_U_NonConst(Vector &vec)
Set the z_U iterate (non-const).
void Set_y_d(const Vector &vec)
Set the y_d iterate (const).
SmartPtr< Vector > create_new_y_c_copy()
Create a new vector in the y_c entry and copy the current values into it.
SmartPtr< const Vector > v_U() const
Get the v_U iterate (const)
SmartPtr< Vector > v_L_NonConst()
Get the v_L iterate (non-const) - this can only be called if the vector was created internally,...
SmartPtr< IteratesVector > MakeNewIteratesVector(bool create_new=true) const
Make New methods.
SmartPtr< Vector > create_new_z_U()
Create a new vector in the z_U entry.
SmartPtr< Vector > create_new_x()
Create a new vector in the x entry.
void Set_eq_mult(const Vector &y_c, const Vector &y_d)
Set the eq multipliers all in one shot.
void Set_y_c_NonConst(Vector &vec)
Set the y_c iterate (non-const).
void Set_x_NonConst(Vector &vec)
Set the x iterate (non-const).
SmartPtr< Vector > create_new_s_copy()
Create a new vector in the s entry and copy the current values into it.
SmartPtr< Vector > create_new_y_d_copy()
Create a new vector in the y_d entry and copy the current values into it.
void Set_bound_mult_NonConst(Vector &z_L, Vector &z_U, Vector &v_L, Vector &v_U)
Set the bound multipliers all in one shot.
SmartPtr< Vector > create_new_s()
Create a new vector in the s entry.
void Set_primal(const Vector &x, const Vector &s)
Set the primal variables all in one shot.
void Set_bound_mult(const Vector &z_L, const Vector &z_U, const Vector &v_L, const Vector &v_U)
Set the bound multipliers all in one shot.
SmartPtr< Vector > create_new_y_c()
Create a new vector in the y_c entry.
SmartPtr< const Vector > y_d() const
Get the y_d iterate (const)
SmartPtr< Vector > z_L_NonConst()
Get the z_L iterate (non-const) - this can only be called if the vector was created internally,...
IteratesVector(const IteratesVector &)
Copy Constructor.
void operator=(const IteratesVector &)
Default Assignment Operator.
void Set_primal_NonConst(Vector &x, Vector &s)
SmartPtr< Vector > create_new_z_U_copy()
Create a new vector in the z_U entry and copy the current values into it.
SmartPtr< Vector > create_new_v_U()
Create a new vector in the v_U entry.
SmartPtr< Vector > GetNonConstIterateFromComp(Index i)
private method to return the non-const element from the compound vector
SmartPtr< Vector > y_d_NonConst()
Get the y_d iterate (non-const) - this can only be called if the vector was created internally,...
void Set_y_c(const Vector &vec)
Set the y_c iterate (const).
void Set_s_NonConst(Vector &vec)
Set the s iterate (non-const).
void Set_x(const Vector &vec)
Set the x iterate (const).
void Set_v_U_NonConst(Vector &vec)
Set the v_U iterate (non-const).
SmartPtr< const Vector > z_L() const
Get the z_L iterate (const)
void Set_z_U(const Vector &vec)
Set the z_U iterate (const).
SmartPtr< const Vector > GetIterateFromComp(Index i) const
private method to return the const element from the compound vector
SmartPtr< const Vector > y_c() const
Get the y_c iterate (const)
SmartPtr< Vector > s_NonConst()
Get the s iterate (non-const) - this can only be called if the vector was created internally,...
SmartPtr< Vector > y_c_NonConst()
Get the y_c iterate (non-const) - this can only be called if the vector was created internally,...
void Set_z_L_NonConst(Vector &vec)
Set the z_L iterate (non-const).
SmartPtr< Vector > v_U_NonConst()
Get the v_U iterate (non-const) - this can only be called if the vector was created intenally,...
void Set_eq_mult_NonConst(Vector &y_c, Vector &y_d)
Set the eq multipliers all in one shot.
void Set_z_L(const Vector &vec)
Set the z_L iterate (const).
SmartPtr< Vector > create_new_x_copy()
Create a new vector in the x entry and copy the current values into it.
void Set_s(const Vector &vec)
Set the s iterate (const).
const IteratesVectorSpace * owner_space_
void Set_v_L(const Vector &vec)
Set the v_L iterate (const).
SmartPtr< Vector > create_new_v_U_copy()
Create a new vector in the v_U entry and copy the current values into it.
SmartPtr< const Vector > v_L() const
Get the v_L iterate (const)
IteratesVector(const IteratesVectorSpace *owner_space, bool create_new)
Constructors / Destructors.
SmartPtr< Vector > create_new_z_L_copy()
Create a new vector in the z_L entry and copy the current values into it.
SmartPtr< const Vector > s() const
Get the s iterate (const)
SmartPtr< Vector > z_U_NonConst()
Get the z_U iterate (non-const) - this can only be called if the vector was created internally,...
void Set_v_L_NonConst(Vector &vec)
Set the v_L iterate (non-const).
IteratesVector()
Default Constructor.
SmartPtr< IteratesVector > MakeNewContainer() const
Use this method to create a new iterates vector container.
void Set_y_d_NonConst(Vector &vec)
Set the y_d iterate (non-const).
void Set_v_U(const Vector &vec)
Set the v_U iterate (const).
Template class for Smart Pointers.
Definition: IpSmartPtr.hpp:172
unsigned int Tag
Type for the Tag values.
VectorSpace base class, corresponding to the Vector base class.
Definition: IpVector.hpp:459
Vector Base Class.
Definition: IpVector.hpp:48
#define IPOPTLIB_EXPORT
This file contains a base class for all exceptions and a set of macros to help with exceptions.
SmartPtr< const U > ConstPtr(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:665
bool IsValid(const SmartPtr< U > &smart_ptr)
Definition: IpSmartPtr.hpp:674
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:17