IpIteratesVector.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2004, 2006 International Business Machines and others.
00002 // All Rights Reserved.
00003 // This code is published under the Eclipse Public License.
00004 //
00005 // $Id: IpIteratesVector.hpp 2276 2013-05-05 12:33:44Z stefan $
00006 //
00007 // Authors:  Carl Laird, Andreas Waechter     IBM    2004-06-06
00008 
00009 #ifndef __IPITERATESVECTOR_HPP__
00010 #define __IPITERATESVECTOR_HPP__
00011 
00012 #include "IpCompoundVector.hpp"
00013 
00014 namespace Ipopt
00015 {
00016   /* forward declarations */
00017   class IteratesVectorSpace;
00018 
00027   class IteratesVector : public CompoundVector
00028   {
00029   public:
00032     IteratesVector(const IteratesVectorSpace* owner_space, bool create_new);
00033 
00034     virtual ~IteratesVector();
00036 
00043     SmartPtr<IteratesVector> MakeNewIteratesVector(bool create_new = true) const;
00044 
00048     SmartPtr<IteratesVector> MakeNewIteratesVectorCopy() const
00049     {
00050       SmartPtr<IteratesVector> ret = MakeNewIteratesVector(true);
00051       ret->Copy(*this);
00052       return ret;
00053     }
00054 
00061     SmartPtr<IteratesVector> MakeNewContainer() const;
00063 
00067     SmartPtr<const Vector> x() const
00068     {
00069       return GetIterateFromComp(0);
00070     }
00071 
00075     SmartPtr<Vector> x_NonConst()
00076     {
00077       return GetNonConstIterateFromComp(0);
00078     }
00079 
00081     inline
00082     SmartPtr<Vector> create_new_x();
00083 
00086     SmartPtr<Vector> create_new_x_copy()
00087     {
00088       SmartPtr<const Vector> curr_x = GetComp(0);
00089       Set_x_NonConst(*curr_x->MakeNew());
00090       x_NonConst()->Copy(*curr_x);
00091       return x_NonConst();
00092     }
00093 
00096     void Set_x(const Vector& vec)
00097     {
00098       SetComp(0, vec);
00099     }
00100 
00103     void Set_x_NonConst(Vector& vec)
00104     {
00105       SetCompNonConst(0, vec);
00106     }
00107 
00109     SmartPtr<const Vector> s() const
00110     {
00111       return GetIterateFromComp(1);
00112     }
00113 
00117     SmartPtr<Vector> s_NonConst()
00118     {
00119       return GetNonConstIterateFromComp(1);
00120     }
00121 
00123     inline
00124     SmartPtr<Vector> create_new_s();
00125 
00128     SmartPtr<Vector> create_new_s_copy()
00129     {
00130       SmartPtr<const Vector> curr_s = GetComp(1);
00131       Set_s_NonConst(*curr_s->MakeNew());
00132       s_NonConst()->Copy(*curr_s);
00133       return s_NonConst();
00134     }
00135 
00138     void Set_s(const Vector& vec)
00139     {
00140       SetComp(1, vec);
00141     }
00142 
00145     void Set_s_NonConst(Vector& vec)
00146     {
00147       SetCompNonConst(1, vec);
00148     }
00149 
00151     SmartPtr<const Vector> y_c() const
00152     {
00153       return GetIterateFromComp(2);
00154     }
00155 
00159     SmartPtr<Vector> y_c_NonConst()
00160     {
00161       return GetNonConstIterateFromComp(2);
00162     }
00163 
00165     inline
00166     SmartPtr<Vector> create_new_y_c();
00167 
00170     SmartPtr<Vector> create_new_y_c_copy()
00171     {
00172       SmartPtr<const Vector> curr_y_c = GetComp(2);
00173       Set_y_c_NonConst(*curr_y_c->MakeNew());
00174       y_c_NonConst()->Copy(*curr_y_c);
00175       return y_c_NonConst();
00176     }
00177 
00180     void Set_y_c(const Vector& vec)
00181     {
00182       SetComp(2, vec);
00183     }
00184 
00187     void Set_y_c_NonConst(Vector& vec)
00188     {
00189       SetCompNonConst(2, vec);
00190     }
00191 
00193     SmartPtr<const Vector> y_d() const
00194     {
00195       return GetIterateFromComp(3);
00196     }
00197 
00201     SmartPtr<Vector> y_d_NonConst()
00202     {
00203       return GetNonConstIterateFromComp(3);
00204     }
00205 
00207     inline
00208     SmartPtr<Vector> create_new_y_d();
00209 
00212     SmartPtr<Vector> create_new_y_d_copy()
00213     {
00214       SmartPtr<const Vector> curr_y_d = GetComp(3);
00215       Set_y_d_NonConst(*curr_y_d->MakeNew());
00216       y_d_NonConst()->Copy(*curr_y_d);
00217       return y_d_NonConst();
00218     }
00219 
00222     void Set_y_d(const Vector& vec)
00223     {
00224       SetComp(3, vec);
00225     }
00226 
00229     void Set_y_d_NonConst(Vector& vec)
00230     {
00231       SetCompNonConst(3, vec);
00232     }
00233 
00235     SmartPtr<const Vector> z_L() const
00236     {
00237       return GetIterateFromComp(4);
00238     }
00239 
00243     SmartPtr<Vector> z_L_NonConst()
00244     {
00245       return GetNonConstIterateFromComp(4);
00246     }
00247 
00249     inline
00250     SmartPtr<Vector> create_new_z_L();
00251 
00254     SmartPtr<Vector> create_new_z_L_copy()
00255     {
00256       SmartPtr<const Vector> curr_z_L = GetComp(4);
00257       Set_z_L_NonConst(*curr_z_L->MakeNew());
00258       z_L_NonConst()->Copy(*curr_z_L);
00259       return z_L_NonConst();
00260     }
00261 
00264     void Set_z_L(const Vector& vec)
00265     {
00266       SetComp(4, vec);
00267     }
00268 
00271     void Set_z_L_NonConst(Vector& vec)
00272     {
00273       SetCompNonConst(4, vec);
00274     }
00275 
00277     SmartPtr<const Vector> z_U() const
00278     {
00279       return GetIterateFromComp(5);
00280     }
00281 
00285     SmartPtr<Vector> z_U_NonConst()
00286     {
00287       return GetNonConstIterateFromComp(5);
00288     }
00289 
00291     inline
00292     SmartPtr<Vector> create_new_z_U();
00293 
00296     SmartPtr<Vector> create_new_z_U_copy()
00297     {
00298       SmartPtr<const Vector> curr_z_U = GetComp(5);
00299       Set_z_U_NonConst(*curr_z_U->MakeNew());
00300       z_U_NonConst()->Copy(*curr_z_U);
00301       return z_U_NonConst();
00302     }
00303 
00306     void Set_z_U(const Vector& vec)
00307     {
00308       SetComp(5, vec);
00309     }
00310 
00313     void Set_z_U_NonConst(Vector& vec)
00314     {
00315       SetCompNonConst(5, vec);
00316     }
00317 
00319     SmartPtr<const Vector> v_L() const
00320     {
00321       return GetIterateFromComp(6);
00322     }
00323 
00327     SmartPtr<Vector> v_L_NonConst()
00328     {
00329       return GetNonConstIterateFromComp(6);
00330     }
00331 
00333     inline
00334     SmartPtr<Vector> create_new_v_L();
00335 
00338     SmartPtr<Vector> create_new_v_L_copy()
00339     {
00340       SmartPtr<const Vector> curr_v_L = GetComp(6);
00341       Set_v_L_NonConst(*curr_v_L->MakeNew());
00342       v_L_NonConst()->Copy(*curr_v_L);
00343       return v_L_NonConst();
00344     }
00345 
00348     void Set_v_L(const Vector& vec)
00349     {
00350       SetComp(6, vec);
00351     }
00352 
00355     void Set_v_L_NonConst(Vector& vec)
00356     {
00357       SetCompNonConst(6, vec);
00358     }
00359 
00361     SmartPtr<const Vector> v_U() const
00362     {
00363       return GetIterateFromComp(7);
00364     }
00365 
00369     SmartPtr<Vector> v_U_NonConst()
00370     {
00371       return GetNonConstIterateFromComp(7);
00372     }
00373 
00375     inline
00376     SmartPtr<Vector> create_new_v_U();
00377 
00380     SmartPtr<Vector> create_new_v_U_copy()
00381     {
00382       SmartPtr<const Vector> curr_v_U = GetComp(7);
00383       Set_v_U_NonConst(*curr_v_U->MakeNew());
00384       v_U_NonConst()->Copy(*curr_v_U);
00385       return v_U_NonConst();
00386     }
00387 
00390     void Set_v_U(const Vector& vec)
00391     {
00392       SetComp(7, vec);
00393     }
00394 
00397     void Set_v_U_NonConst(Vector& vec)
00398     {
00399       SetCompNonConst(7, vec);
00400     }
00401 
00404     void Set_primal(const Vector& x, const Vector& s)
00405     {
00406       SetComp(0, x);
00407       SetComp(1, s);
00408     }
00409     void Set_primal_NonConst(Vector& x, Vector& s)
00410     {
00411       SetCompNonConst(0, x);
00412       SetCompNonConst(1, s);
00413     }
00414 
00417     void Set_eq_mult(const Vector& y_c, const Vector& y_d)
00418     {
00419       SetComp(2, y_c);
00420       SetComp(3, y_d);
00421     }
00422     void Set_eq_mult_NonConst(Vector& y_c, Vector& y_d)
00423     {
00424       SetCompNonConst(2, y_c);
00425       SetCompNonConst(3, y_d);
00426     }
00427 
00430     void Set_bound_mult(const Vector& z_L, const Vector& z_U, const Vector& v_L, const Vector& v_U)
00431     {
00432       SetComp(4, z_L);
00433       SetComp(5, z_U);
00434       SetComp(6, v_L);
00435       SetComp(7, v_U);
00436     }
00437     void Set_bound_mult_NonConst(Vector& z_L, Vector& z_U, Vector& v_L, Vector& v_U)
00438     {
00439       SetCompNonConst(4, z_L);
00440       SetCompNonConst(5, z_U);
00441       SetCompNonConst(6, v_L);
00442       SetCompNonConst(7, v_U);
00443     }
00444 
00450     TaggedObject::Tag GetTagSum() const
00451     {
00452       TaggedObject::Tag tag;
00453 
00454       if (IsValid(x()))
00455         tag = x()->GetTag() + tag;
00456 
00457       if (IsValid(s()))
00458         tag = s()->GetTag() + tag;
00459 
00460       if (IsValid(y_c()))
00461         tag = y_c()->GetTag() + tag;
00462 
00463       if (IsValid(y_d()))
00464         tag = y_d()->GetTag() + tag;
00465 
00466       if (IsValid(z_L()))
00467         tag = z_L()->GetTag() + tag;
00468 
00469       if (IsValid(z_U()))
00470         tag = z_U()->GetTag() + tag;
00471 
00472       if (IsValid(v_L()))
00473         tag = v_L()->GetTag() + tag;
00474 
00475       if (IsValid(v_U()))
00476         tag = v_U()->GetTag() + tag;
00477 
00478       return tag;
00479     }
00481 
00482   private:
00491     IteratesVector();
00492 
00494     IteratesVector(const IteratesVector&);
00495 
00497     void operator=(const IteratesVector&);
00499 
00500     const IteratesVectorSpace* owner_space_;
00501 
00506     SmartPtr<const Vector> GetIterateFromComp(Index i) const
00507     {
00508       if (IsCompNull(i)) {
00509         return NULL;
00510       }
00511       return GetComp(i);
00512     }
00513 
00518     SmartPtr<Vector> GetNonConstIterateFromComp(Index i)
00519     {
00520       if (IsCompNull(i)) {
00521         return NULL;
00522       }
00523       return GetCompNonConst(i);
00524     }
00525 
00526   };
00527 
00531   class IteratesVectorSpace : public CompoundVectorSpace
00532   {
00533   public:
00539     IteratesVectorSpace(const VectorSpace& x_space, const VectorSpace& s_space,
00540                         const VectorSpace& y_c_space, const VectorSpace& y_d_space,
00541                         const VectorSpace& z_L_space, const VectorSpace& z_U_space,
00542                         const VectorSpace& v_L_space, const VectorSpace& v_U_space
00543                        );
00544 
00545     virtual ~IteratesVectorSpace();
00547 
00554     virtual IteratesVector* MakeNewIteratesVector(bool create_new = true) const
00555     {
00556       return new IteratesVector(this, create_new);
00557     }
00558 
00562     const SmartPtr<const IteratesVector> MakeNewIteratesVector(const Vector& x, const Vector& s,
00563         const Vector& y_c, const Vector& y_d,
00564         const Vector& z_L, const Vector& z_U,
00565         const Vector& v_L, const Vector& v_U)
00566     {
00567       SmartPtr<IteratesVector> newvec = MakeNewIteratesVector(false);
00568       newvec->Set_x(x);
00569       newvec->Set_s(s);
00570       newvec->Set_y_c(y_c);
00571       newvec->Set_y_d(y_d);
00572       newvec->Set_z_L(z_L);
00573       newvec->Set_z_U(z_U);
00574       newvec->Set_v_L(v_L);
00575       newvec->Set_v_U(v_U);
00576       return ConstPtr(newvec);
00577     }
00578 
00579 
00584     virtual CompoundVector* MakeNewCompoundVector(bool create_new = true) const
00585     {
00586       return MakeNewIteratesVector(create_new);
00587     }
00588 
00594     virtual Vector* MakeNew() const
00595     {
00596       return MakeNewIteratesVector();
00597     }
00599 
00604     virtual void SetCompSpace(Index icomp, const VectorSpace& vec_space)
00605     {
00606       DBG_ASSERT(false && "This is an IteratesVectorSpace - a special compound vector for Ipopt iterates. The contained spaces should not be modified.");
00607     }
00608 
00609   private:
00617     IteratesVectorSpace();
00618 
00620     IteratesVectorSpace(const IteratesVectorSpace&);
00621 
00623     IteratesVectorSpace& operator=(const IteratesVectorSpace&);
00625 
00627     SmartPtr<const VectorSpace> x_space_;
00628     SmartPtr<const VectorSpace> s_space_;
00629     SmartPtr<const VectorSpace> y_c_space_;
00630     SmartPtr<const VectorSpace> y_d_space_;
00631     SmartPtr<const VectorSpace> z_L_space_;
00632     SmartPtr<const VectorSpace> z_U_space_;
00633     SmartPtr<const VectorSpace> v_L_space_;
00634     SmartPtr<const VectorSpace> v_U_space_;
00635   };
00636 
00637 
00638   inline
00639   SmartPtr<Vector> IteratesVector::create_new_x()
00640   {
00641     Set_x_NonConst(*owner_space_->GetCompSpace(0)->MakeNew());
00642     return x_NonConst();
00643   }
00644   inline
00645   SmartPtr<Vector> IteratesVector::create_new_s()
00646   {
00647     Set_s_NonConst(*owner_space_->GetCompSpace(1)->MakeNew());
00648     return s_NonConst();
00649   }
00650   inline
00651   SmartPtr<Vector> IteratesVector::create_new_y_c()
00652   {
00653     Set_y_c_NonConst(*owner_space_->GetCompSpace(2)->MakeNew());
00654     return y_c_NonConst();
00655   }
00656   inline
00657   SmartPtr<Vector> IteratesVector::create_new_y_d()
00658   {
00659     Set_y_d_NonConst(*owner_space_->GetCompSpace(3)->MakeNew());
00660     return y_d_NonConst();
00661   }
00662   inline
00663   SmartPtr<Vector> IteratesVector::create_new_z_L()
00664   {
00665     Set_z_L_NonConst(*owner_space_->GetCompSpace(4)->MakeNew());
00666     return z_L_NonConst();
00667   }
00668   inline
00669   SmartPtr<Vector> IteratesVector::create_new_z_U()
00670   {
00671     Set_z_U_NonConst(*owner_space_->GetCompSpace(5)->MakeNew());
00672     return z_U_NonConst();
00673   }
00674   inline
00675   SmartPtr<Vector> IteratesVector::create_new_v_L()
00676   {
00677     Set_v_L_NonConst(*owner_space_->GetCompSpace(6)->MakeNew());
00678     return v_L_NonConst();
00679   }
00680   inline
00681   SmartPtr<Vector> IteratesVector::create_new_v_U()
00682   {
00683     Set_v_U_NonConst(*owner_space_->GetCompSpace(7)->MakeNew());
00684     return v_U_NonConst();
00685   }
00686 } // namespace Ipopt
00687 
00688 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 9 Aug 2013 for Ipopt by  doxygen 1.6.1