Ipopt  trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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$
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 = 0;
00453 
00454       if (IsValid(x())) {
00455         tag += x()->GetTag();
00456       }
00457       if (IsValid(s())) {
00458         tag += s()->GetTag();
00459       }
00460       if (IsValid(y_c())) {
00461         tag += y_c()->GetTag();
00462       }
00463       if (IsValid(y_d())) {
00464         tag += y_d()->GetTag();
00465       }
00466       if (IsValid(z_L())) {
00467         tag += z_L()->GetTag();
00468       }
00469       if (IsValid(z_U())) {
00470         tag += z_U()->GetTag();
00471       }
00472       if (IsValid(v_L())) {
00473         tag += v_L()->GetTag();
00474       }
00475       if (IsValid(v_U())) {
00476         tag += v_U()->GetTag();
00477       }
00478 
00479       return tag;
00480     }
00482 
00483   private:
00492     IteratesVector();
00493 
00495     IteratesVector(const IteratesVector&);
00496 
00498     void operator=(const IteratesVector&);
00500 
00501     const IteratesVectorSpace* owner_space_;
00502 
00507     SmartPtr<const Vector> GetIterateFromComp(Index i) const
00508     {
00509       if (IsCompNull(i)) {
00510         return NULL;
00511       }
00512       return GetComp(i);
00513     }
00514 
00519     SmartPtr<Vector> GetNonConstIterateFromComp(Index i)
00520     {
00521       if (IsCompNull(i)) {
00522         return NULL;
00523       }
00524       return GetCompNonConst(i);
00525     }
00526 
00527   };
00528 
00532   class IteratesVectorSpace : public CompoundVectorSpace
00533   {
00534   public:
00540     IteratesVectorSpace(const VectorSpace& x_space, const VectorSpace& s_space,
00541                         const VectorSpace& y_c_space, const VectorSpace& y_d_space,
00542                         const VectorSpace& z_L_space, const VectorSpace& z_U_space,
00543                         const VectorSpace& v_L_space, const VectorSpace& v_U_space
00544                        );
00545 
00546     virtual ~IteratesVectorSpace();
00548 
00555     virtual IteratesVector* MakeNewIteratesVector(bool create_new = true) const
00556     {
00557       return new IteratesVector(this, create_new);
00558     }
00559 
00563     const SmartPtr<const IteratesVector> MakeNewIteratesVector(const Vector& x, const Vector& s,
00564         const Vector& y_c, const Vector& y_d,
00565         const Vector& z_L, const Vector& z_U,
00566         const Vector& v_L, const Vector& v_U)
00567     {
00568       SmartPtr<IteratesVector> newvec = MakeNewIteratesVector(false);
00569       newvec->Set_x(x);
00570       newvec->Set_s(s);
00571       newvec->Set_y_c(y_c);
00572       newvec->Set_y_d(y_d);
00573       newvec->Set_z_L(z_L);
00574       newvec->Set_z_U(z_U);
00575       newvec->Set_v_L(v_L);
00576       newvec->Set_v_U(v_U);
00577       return ConstPtr(newvec);
00578     }
00579 
00580 
00585     virtual CompoundVector* MakeNewCompoundVector(bool create_new = true) const
00586     {
00587       return MakeNewIteratesVector(create_new);
00588     }
00589 
00595     virtual Vector* MakeNew() const
00596     {
00597       return MakeNewIteratesVector();
00598     }
00600 
00605     virtual void SetCompSpace(Index icomp, const VectorSpace& vec_space)
00606     {
00607       DBG_ASSERT(false && "This is an IteratesVectorSpace - a special compound vector for Ipopt iterates. The contained spaces should not be modified.");
00608     }
00609 
00610   private:
00618     IteratesVectorSpace();
00619 
00621     IteratesVectorSpace(const IteratesVectorSpace&);
00622 
00624     IteratesVectorSpace& operator=(const IteratesVectorSpace&);
00626 
00628     SmartPtr<const VectorSpace> x_space_;
00629     SmartPtr<const VectorSpace> s_space_;
00630     SmartPtr<const VectorSpace> y_c_space_;
00631     SmartPtr<const VectorSpace> y_d_space_;
00632     SmartPtr<const VectorSpace> z_L_space_;
00633     SmartPtr<const VectorSpace> z_U_space_;
00634     SmartPtr<const VectorSpace> v_L_space_;
00635     SmartPtr<const VectorSpace> v_U_space_;
00636   };
00637 
00638 
00639   inline
00640   SmartPtr<Vector> IteratesVector::create_new_x()
00641   {
00642     Set_x_NonConst(*owner_space_->GetCompSpace(0)->MakeNew());
00643     return x_NonConst();
00644   }
00645   inline
00646   SmartPtr<Vector> IteratesVector::create_new_s()
00647   {
00648     Set_s_NonConst(*owner_space_->GetCompSpace(1)->MakeNew());
00649     return s_NonConst();
00650   }
00651   inline
00652   SmartPtr<Vector> IteratesVector::create_new_y_c()
00653   {
00654     Set_y_c_NonConst(*owner_space_->GetCompSpace(2)->MakeNew());
00655     return y_c_NonConst();
00656   }
00657   inline
00658   SmartPtr<Vector> IteratesVector::create_new_y_d()
00659   {
00660     Set_y_d_NonConst(*owner_space_->GetCompSpace(3)->MakeNew());
00661     return y_d_NonConst();
00662   }
00663   inline
00664   SmartPtr<Vector> IteratesVector::create_new_z_L()
00665   {
00666     Set_z_L_NonConst(*owner_space_->GetCompSpace(4)->MakeNew());
00667     return z_L_NonConst();
00668   }
00669   inline
00670   SmartPtr<Vector> IteratesVector::create_new_z_U()
00671   {
00672     Set_z_U_NonConst(*owner_space_->GetCompSpace(5)->MakeNew());
00673     return z_U_NonConst();
00674   }
00675   inline
00676   SmartPtr<Vector> IteratesVector::create_new_v_L()
00677   {
00678     Set_v_L_NonConst(*owner_space_->GetCompSpace(6)->MakeNew());
00679     return v_L_NonConst();
00680   }
00681   inline
00682   SmartPtr<Vector> IteratesVector::create_new_v_U()
00683   {
00684     Set_v_U_NonConst(*owner_space_->GetCompSpace(7)->MakeNew());
00685     return v_U_NonConst();
00686   }
00687 } // namespace Ipopt
00688 
00689 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines