- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/SVN-release/Ipopt-3.2.1/Ipopt/src/Algorithm/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 Common Public License.
    00004 //
    00005 // $Id: IpIteratesVector.hpp 759 2006-07-07 03:07:08Z andreasw $
    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     SmartPtr<Vector> create_new_x();
    00082
    00085     SmartPtr<Vector> create_new_x_copy()
    00086     {
    00087       SmartPtr<const Vector> curr_x = GetComp(0);
    00088       Set_x_NonConst(*curr_x->MakeNew());
    00089       x_NonConst()->Copy(*curr_x);
    00090       return x_NonConst();
    00091     }
    00092
    00095     void Set_x(const Vector& vec)
    00096     {
    00097       SetComp(0, vec);
    00098     }
    00099
    00102     void Set_x_NonConst(Vector& vec)
    00103     {
    00104       SetCompNonConst(0, vec);
    00105     }
    00106
    00108     SmartPtr<const Vector> s() const
    00109     {
    00110       return GetIterateFromComp(1);
    00111     }
    00112
    00116     SmartPtr<Vector> s_NonConst()
    00117     {
    00118       return GetNonConstIterateFromComp(1);
    00119     }
    00120
    00122     SmartPtr<Vector> create_new_s();
    00123
    00126     SmartPtr<Vector> create_new_s_copy()
    00127     {
    00128       SmartPtr<const Vector> curr_s = GetComp(1);
    00129       Set_s_NonConst(*curr_s->MakeNew());
    00130       s_NonConst()->Copy(*curr_s);
    00131       return s_NonConst();
    00132     }
    00133
    00136     void Set_s(const Vector& vec)
    00137     {
    00138       SetComp(1, vec);
    00139     }
    00140
    00143     void Set_s_NonConst(Vector& vec)
    00144     {
    00145       SetCompNonConst(1, vec);
    00146     }
    00147
    00149     SmartPtr<const Vector> y_c() const
    00150     {
    00151       return GetIterateFromComp(2);
    00152     }
    00153
    00157     SmartPtr<Vector> y_c_NonConst()
    00158     {
    00159       return GetNonConstIterateFromComp(2);
    00160     }
    00161
    00163     SmartPtr<Vector> create_new_y_c();
    00164
    00167     SmartPtr<Vector> create_new_y_c_copy()
    00168     {
    00169       SmartPtr<const Vector> curr_y_c = GetComp(2);
    00170       Set_y_c_NonConst(*curr_y_c->MakeNew());
    00171       y_c_NonConst()->Copy(*curr_y_c);
    00172       return y_c_NonConst();
    00173     }
    00174
    00177     void Set_y_c(const Vector& vec)
    00178     {
    00179       SetComp(2, vec);
    00180     }
    00181
    00184     void Set_y_c_NonConst(Vector& vec)
    00185     {
    00186       SetCompNonConst(2, vec);
    00187     }
    00188
    00190     SmartPtr<const Vector> y_d() const
    00191     {
    00192       return GetIterateFromComp(3);
    00193     }
    00194
    00198     SmartPtr<Vector> y_d_NonConst()
    00199     {
    00200       return GetNonConstIterateFromComp(3);
    00201     }
    00202
    00204     SmartPtr<Vector> create_new_y_d();
    00205
    00208     SmartPtr<Vector> create_new_y_d_copy()
    00209     {
    00210       SmartPtr<const Vector> curr_y_d = GetComp(3);
    00211       Set_y_d_NonConst(*curr_y_d->MakeNew());
    00212       y_d_NonConst()->Copy(*curr_y_d);
    00213       return y_d_NonConst();
    00214     }
    00215
    00218     void Set_y_d(const Vector& vec)
    00219     {
    00220       SetComp(3, vec);
    00221     }
    00222
    00225     void Set_y_d_NonConst(Vector& vec)
    00226     {
    00227       SetCompNonConst(3, vec);
    00228     }
    00229
    00231     SmartPtr<const Vector> z_L() const
    00232     {
    00233       return GetIterateFromComp(4);
    00234     }
    00235
    00239     SmartPtr<Vector> z_L_NonConst()
    00240     {
    00241       return GetNonConstIterateFromComp(4);
    00242     }
    00243
    00245     SmartPtr<Vector> create_new_z_L() ;
    00246
    00249     SmartPtr<Vector> create_new_z_L_copy()
    00250     {
    00251       SmartPtr<const Vector> curr_z_L = GetComp(4);
    00252       Set_z_L_NonConst(*curr_z_L->MakeNew());
    00253       z_L_NonConst()->Copy(*curr_z_L);
    00254       return z_L_NonConst();
    00255     }
    00256
    00259     void Set_z_L(const Vector& vec)
    00260     {
    00261       SetComp(4, vec);
    00262     }
    00263
    00266     void Set_z_L_NonConst(Vector& vec)
    00267     {
    00268       SetCompNonConst(4, vec);
    00269     }
    00270
    00272     SmartPtr<const Vector> z_U() const
    00273     {
    00274       return GetIterateFromComp(5);
    00275     }
    00276
    00280     SmartPtr<Vector> z_U_NonConst()
    00281     {
    00282       return GetNonConstIterateFromComp(5);
    00283     }
    00284
    00286     SmartPtr<Vector> create_new_z_U();
    00287
    00290     SmartPtr<Vector> create_new_z_U_copy()
    00291     {
    00292       SmartPtr<const Vector> curr_z_U = GetComp(5);
    00293       Set_z_U_NonConst(*curr_z_U->MakeNew());
    00294       z_U_NonConst()->Copy(*curr_z_U);
    00295       return z_U_NonConst();
    00296     }
    00297
    00300     void Set_z_U(const Vector& vec)
    00301     {
    00302       SetComp(5, vec);
    00303     }
    00304
    00307     void Set_z_U_NonConst(Vector& vec)
    00308     {
    00309       SetCompNonConst(5, vec);
    00310     }
    00311
    00313     SmartPtr<const Vector> v_L() const
    00314     {
    00315       return GetIterateFromComp(6);
    00316     }
    00317
    00321     SmartPtr<Vector> v_L_NonConst()
    00322     {
    00323       return GetNonConstIterateFromComp(6);
    00324     }
    00325
    00327     SmartPtr<Vector> create_new_v_L();
    00328
    00331     SmartPtr<Vector> create_new_v_L_copy()
    00332     {
    00333       SmartPtr<const Vector> curr_v_L = GetComp(6);
    00334       Set_v_L_NonConst(*curr_v_L->MakeNew());
    00335       v_L_NonConst()->Copy(*curr_v_L);
    00336       return v_L_NonConst();
    00337     }
    00338
    00341     void Set_v_L(const Vector& vec)
    00342     {
    00343       SetComp(6, vec);
    00344     }
    00345
    00348     void Set_v_L_NonConst(Vector& vec)
    00349     {
    00350       SetCompNonConst(6, vec);
    00351     }
    00352
    00354     SmartPtr<const Vector> v_U() const
    00355     {
    00356       return GetIterateFromComp(7);
    00357     }
    00358
    00362     SmartPtr<Vector> v_U_NonConst()
    00363     {
    00364       return GetNonConstIterateFromComp(7);
    00365     }
    00366
    00368     SmartPtr<Vector> create_new_v_U();
    00369
    00372     SmartPtr<Vector> create_new_v_U_copy()
    00373     {
    00374       SmartPtr<const Vector> curr_v_U = GetComp(7);
    00375       Set_v_U_NonConst(*curr_v_U->MakeNew());
    00376       v_U_NonConst()->Copy(*curr_v_U);
    00377       return v_U_NonConst();
    00378     }
    00379
    00382     void Set_v_U(const Vector& vec)
    00383     {
    00384       SetComp(7, vec);
    00385     }
    00386
    00389     void Set_v_U_NonConst(Vector& vec)
    00390     {
    00391       SetCompNonConst(7, vec);
    00392     }
    00393
    00396     void Set_primal(const Vector& x, const Vector& s)
    00397     {
    00398       SetComp(0, x);
    00399       SetComp(1, s);
    00400     }
    00401     void Set_primal_NonConst(Vector& x, Vector& s)
    00402     {
    00403       SetCompNonConst(0, x);
    00404       SetCompNonConst(1, s);
    00405     }
    00406
    00409     void Set_eq_mult(const Vector& y_c, const Vector& y_d)
    00410     {
    00411       SetComp(2, y_c);
    00412       SetComp(3, y_d);
    00413     }
    00414     void Set_eq_mult_NonConst(Vector& y_c, Vector& y_d)
    00415     {
    00416       SetCompNonConst(2, y_c);
    00417       SetCompNonConst(3, y_d);
    00418     }
    00419
    00422     void Set_bound_mult(const Vector& z_L, const Vector& z_U, const Vector& v_L, const Vector& v_U)
    00423     {
    00424       SetComp(4, z_L);
    00425       SetComp(5, z_U);
    00426       SetComp(6, v_L);
    00427       SetComp(7, v_U);
    00428     }
    00429     void Set_bound_mult_NonConst(Vector& z_L, Vector& z_U, Vector& v_L, Vector& v_U)
    00430     {
    00431       SetCompNonConst(4, z_L);
    00432       SetCompNonConst(5, z_U);
    00433       SetCompNonConst(6, v_L);
    00434       SetCompNonConst(7, v_U);
    00435     }
    00436
    00442     TaggedObject::Tag GetTagSum() const
    00443     {
    00444       TaggedObject::Tag tag = 0;
    00445
    00446       if (IsValid(x())) {
    00447         tag += x()->GetTag();
    00448       }
    00449       if (IsValid(s())) {
    00450         tag += s()->GetTag();
    00451       }
    00452       if (IsValid(y_c())) {
    00453         tag += y_c()->GetTag();
    00454       }
    00455       if (IsValid(y_d())) {
    00456         tag += y_d()->GetTag();
    00457       }
    00458       if (IsValid(z_L())) {
    00459         tag += z_L()->GetTag();
    00460       }
    00461       if (IsValid(z_U())) {
    00462         tag += z_U()->GetTag();
    00463       }
    00464       if (IsValid(v_L())) {
    00465         tag += v_L()->GetTag();
    00466       }
    00467       if (IsValid(v_U())) {
    00468         tag += v_U()->GetTag();
    00469       }
    00470
    00471       return tag;
    00472     }
    00474
    00475   private:
    00484     IteratesVector();
    00485
    00487     IteratesVector(const IteratesVector&);
    00488
    00490     void operator=(const IteratesVector&);
    00492
    00493     const IteratesVectorSpace* owner_space_;
    00494
    00499     SmartPtr<const Vector> GetIterateFromComp(Index i) const
    00500     {
    00501       if (IsCompNull(i)) {
    00502         return NULL;
    00503       }
    00504       return GetComp(i);
    00505     }
    00506
    00511     SmartPtr<Vector> GetNonConstIterateFromComp(Index i)
    00512     {
    00513       if (IsCompNull(i)) {
    00514         return NULL;
    00515       }
    00516       return GetCompNonConst(i);
    00517     }
    00518
    00519   };
    00520
    00524   class IteratesVectorSpace : public CompoundVectorSpace
    00525   {
    00526   public:
    00532     IteratesVectorSpace(const VectorSpace& x_space, const VectorSpace& s_space,
    00533                         const VectorSpace& y_c_space, const VectorSpace& y_d_space,
    00534                         const VectorSpace& z_L_space, const VectorSpace& z_U_space,
    00535                         const VectorSpace& v_L_space, const VectorSpace& v_U_space
    00536                        );
    00537
    00538     virtual ~IteratesVectorSpace();
    00540
    00547     virtual IteratesVector* MakeNewIteratesVector(bool create_new = true) const
    00548     {
    00549       return new IteratesVector(this, create_new);
    00550     }
    00551
    00555     const SmartPtr<const IteratesVector> MakeNewIteratesVector(const Vector& x, const Vector& s,
    00556         const Vector& y_c, const Vector& y_d,
    00557         const Vector& z_L, const Vector& z_U,
    00558         const Vector& v_L, const Vector& v_U)
    00559     {
    00560       SmartPtr<IteratesVector> newvec = MakeNewIteratesVector(false);
    00561       newvec->Set_x(x);
    00562       newvec->Set_s(s);
    00563       newvec->Set_y_c(y_c);
    00564       newvec->Set_y_d(y_d);
    00565       newvec->Set_z_L(z_L);
    00566       newvec->Set_z_U(z_U);
    00567       newvec->Set_v_L(v_L);
    00568       newvec->Set_v_U(v_U);
    00569       return ConstPtr(newvec);
    00570     }
    00571
    00572
    00577     virtual CompoundVector* MakeNewCompoundVector(bool create_new = true) const
    00578     {
    00579       return MakeNewIteratesVector(create_new);
    00580     }
    00581
    00587     virtual Vector* MakeNew() const
    00588     {
    00589       return MakeNewIteratesVector();
    00590     }
    00592
    00597     virtual void SetCompSpace(Index icomp, const VectorSpace& vec_space)
    00598     {
    00599       DBG_ASSERT(false && "This is an IteratesVectorSpace - a special compound vector for Ipopt iterates. The contained spaces should not be modified.");
    00600     }
    00601
    00602   private:
    00610     IteratesVectorSpace();
    00611
    00613     IteratesVectorSpace(const IteratesVectorSpace&);
    00614
    00616     IteratesVectorSpace& operator=(const IteratesVectorSpace&);
    00618
    00620     SmartPtr<const VectorSpace> x_space_;
    00621     SmartPtr<const VectorSpace> s_space_;
    00622     SmartPtr<const VectorSpace> y_c_space_;
    00623     SmartPtr<const VectorSpace> y_d_space_;
    00624     SmartPtr<const VectorSpace> z_L_space_;
    00625     SmartPtr<const VectorSpace> z_U_space_;
    00626     SmartPtr<const VectorSpace> v_L_space_;
    00627     SmartPtr<const VectorSpace> v_U_space_;
    00628   };
    00629
    00630
    00631   inline
    00632   SmartPtr<Vector> IteratesVector::create_new_x()
    00633   {
    00634     Set_x_NonConst(*owner_space_->GetCompSpace(0)->MakeNew());
    00635     return x_NonConst();
    00636   }
    00637   inline
    00638   SmartPtr<Vector> IteratesVector::create_new_s()
    00639   {
    00640     Set_s_NonConst(*owner_space_->GetCompSpace(1)->MakeNew());
    00641     return s_NonConst();
    00642   }
    00643   inline
    00644   SmartPtr<Vector> IteratesVector::create_new_y_c()
    00645   {
    00646     Set_y_c_NonConst(*owner_space_->GetCompSpace(2)->MakeNew());
    00647     return y_c_NonConst();
    00648   }
    00649   inline
    00650   SmartPtr<Vector> IteratesVector::create_new_y_d()
    00651   {
    00652     Set_y_d_NonConst(*owner_space_->GetCompSpace(3)->MakeNew());
    00653     return y_d_NonConst();
    00654   }
    00655   inline
    00656   SmartPtr<Vector> IteratesVector::create_new_z_L()
    00657   {
    00658     Set_z_L_NonConst(*owner_space_->GetCompSpace(4)->MakeNew());
    00659     return z_L_NonConst();
    00660   }
    00661   inline
    00662   SmartPtr<Vector> IteratesVector::create_new_z_U()
    00663   {
    00664     Set_z_U_NonConst(*owner_space_->GetCompSpace(5)->MakeNew());
    00665     return z_U_NonConst();
    00666   }
    00667   inline
    00668   SmartPtr<Vector> IteratesVector::create_new_v_L()
    00669   {
    00670     Set_v_L_NonConst(*owner_space_->GetCompSpace(6)->MakeNew());
    00671     return v_L_NonConst();
    00672   }
    00673   inline
    00674   SmartPtr<Vector> IteratesVector::create_new_v_U()
    00675   {
    00676     Set_v_U_NonConst(*owner_space_->GetCompSpace(7)->MakeNew());
    00677     return v_U_NonConst();
    00678   }
    00679 } // namespace Ipopt
    00680
    00681 #endif