/home/coin/SVN-release/Ipopt-3.5.5/Ipopt/src/Algorithm/IpIpoptData.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2004, 2008 International Business Machines and others.
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // $Id: IpIpoptData.hpp 1391 2009-01-06 21:47:19Z andreasw $
00006 //
00007 // Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13
00008 
00009 #ifndef __IPIPOPTDATA_HPP__
00010 #define __IPIPOPTDATA_HPP__
00011 
00012 #include "IpSymMatrix.hpp"
00013 #include "IpOptionsList.hpp"
00014 #include "IpIteratesVector.hpp"
00015 #include "IpRegOptions.hpp"
00016 #include "IpTimingStatistics.hpp"
00017 
00018 namespace Ipopt
00019 {
00020 
00021   /* Forward declaration */
00022   class IpoptNLP;
00023 
00028   class IpoptAdditionalData : public ReferencedObject
00029   {
00030   public:
00034     IpoptAdditionalData()
00035     {}
00036 
00038     virtual ~IpoptAdditionalData()
00039     {}
00041 
00045     virtual bool Initialize(const Journalist& jnlst,
00046                             const OptionsList& options,
00047                             const std::string& prefix) = 0;
00048 
00050     virtual bool InitializeDataStructures() = 0;
00051 
00055     virtual void AcceptTrialPoint() = 0;
00056 
00057   private:
00067     IpoptAdditionalData(const IpoptAdditionalData&);
00068 
00070     void operator=(const IpoptAdditionalData&);
00072   };
00073 
00083   class IpoptData : public ReferencedObject
00084   {
00085   public:
00089     IpoptData(SmartPtr<IpoptAdditionalData> add_data = NULL);
00090 
00092     virtual ~IpoptData();
00094 
00096     bool InitializeDataStructures(IpoptNLP& ip_nlp,
00097                                   bool want_x,
00098                                   bool want_y_c,
00099                                   bool want_y_d,
00100                                   bool want_z_L,
00101                                   bool want_z_U);
00102 
00106     bool Initialize(const Journalist& jnlst,
00107                     const OptionsList& options,
00108                     const std::string& prefix);
00109 
00113     SmartPtr<const IteratesVector> curr() const;
00114 
00119     //    SmartPtr<IteratesVector> curr_container() const;
00120 
00122     SmartPtr<const IteratesVector> trial() const;
00123 
00128     //SmartPtr<IteratesVector> trial_container() const;
00129 
00134     void set_trial(SmartPtr<IteratesVector>& trial);
00135 
00139     void SetTrialPrimalVariablesFromStep(Number alpha,
00140                                          const Vector& delta_x,
00141                                          const Vector& delta_s);
00146     void SetTrialEqMultipliersFromStep(Number alpha,
00147                                        const Vector& delta_y_c,
00148                                        const Vector& delta_y_d);
00153     void SetTrialBoundMultipliersFromStep(Number alpha,
00154                                           const Vector& delta_z_L,
00155                                           const Vector& delta_z_U,
00156                                           const Vector& delta_v_L,
00157                                           const Vector& delta_v_U);
00158 
00162     // void set_trial(const SmartPtr<IteratesVector>& trial_iterates);
00163     // void set_trial(SmartPtr<const IteratesVector>& trial_iterates);
00164 
00166     SmartPtr<const IteratesVector> delta() const;
00167 
00172     void set_delta(SmartPtr<IteratesVector>& delta);
00173 
00180     void set_delta(SmartPtr<const IteratesVector>& delta);
00181 
00183     SmartPtr<const IteratesVector> delta_aff() const;
00184 
00189     void set_delta_aff(SmartPtr<IteratesVector>& delta_aff);
00190 
00192     SmartPtr<const SymMatrix> W()
00193     {
00194       DBG_ASSERT(IsValid(W_));
00195       return W_;
00196     }
00197 
00199     void Set_W(SmartPtr<const SymMatrix> W)
00200     {
00201       W_ = W;
00202     }
00203 
00210 
00218     bool HaveDeltas() const
00219     {
00220       return have_deltas_;
00221     }
00222 
00228     void SetHaveDeltas(bool have_deltas)
00229     {
00230       have_deltas_ = have_deltas;
00231     }
00233 
00240 
00248     bool HaveAffineDeltas() const
00249     {
00250       return have_affine_deltas_;
00251     }
00252 
00258     void SetHaveAffineDeltas(bool have_affine_deltas)
00259     {
00260       have_affine_deltas_ = have_affine_deltas;
00261     }
00263 
00267     void CopyTrialToCurrent();
00268 
00271     void AcceptTrialPoint();
00273 
00276     Index iter_count() const
00277     {
00278       return iter_count_;
00279     }
00280     void Set_iter_count(Index iter_count)
00281     {
00282       iter_count_ = iter_count;
00283     }
00284 
00285     Number curr_mu() const
00286     {
00287       DBG_ASSERT(mu_initialized_);
00288       return curr_mu_;
00289     }
00290     void Set_mu(Number mu)
00291     {
00292       curr_mu_ = mu;
00293       mu_initialized_ = true;
00294     }
00295     bool MuInitialized() const
00296     {
00297       return mu_initialized_;
00298     }
00299 
00300     Number curr_tau() const
00301     {
00302       DBG_ASSERT(tau_initialized_);
00303       return curr_tau_;
00304     }
00305     void Set_tau(Number tau)
00306     {
00307       curr_tau_ = tau;
00308       tau_initialized_ = true;
00309     }
00310     bool TauInitialized() const
00311     {
00312       return tau_initialized_;
00313     }
00314 
00315     void SetFreeMuMode(bool free_mu_mode)
00316     {
00317       free_mu_mode_ = free_mu_mode;
00318     }
00319     bool FreeMuMode() const
00320     {
00321       return free_mu_mode_;
00322     }
00323 
00326     void Set_tiny_step_flag(bool flag)
00327     {
00328       tiny_step_flag_ = flag;
00329     }
00330     bool tiny_step_flag()
00331     {
00332       return tiny_step_flag_;
00333     }
00335 
00342     Number tol() const
00343     {
00344       DBG_ASSERT(initialize_called_);
00345       return tol_;
00346     }
00354     void Set_tol(Number tol)
00355     {
00356       tol_ = tol;
00357     }
00359 
00362     Number info_regu_x() const
00363     {
00364       return info_regu_x_;
00365     }
00366     void Set_info_regu_x(Number regu_x)
00367     {
00368       info_regu_x_ = regu_x;
00369     }
00370     Number info_alpha_primal() const
00371     {
00372       return info_alpha_primal_;
00373     }
00374     void Set_info_alpha_primal(Number alpha_primal)
00375     {
00376       info_alpha_primal_ = alpha_primal;
00377     }
00378     char info_alpha_primal_char() const
00379     {
00380       return info_alpha_primal_char_;
00381     }
00382     void Set_info_alpha_primal_char(char info_alpha_primal_char)
00383     {
00384       info_alpha_primal_char_ = info_alpha_primal_char;
00385     }
00386     Number info_alpha_dual() const
00387     {
00388       return info_alpha_dual_;
00389     }
00390     void Set_info_alpha_dual(Number alpha_dual)
00391     {
00392       info_alpha_dual_ = alpha_dual;
00393     }
00394     Index info_ls_count() const
00395     {
00396       return info_ls_count_;
00397     }
00398     void Set_info_ls_count(Index ls_count)
00399     {
00400       info_ls_count_ = ls_count;
00401     }
00402     bool info_skip_output() const
00403     {
00404       return info_skip_output_;
00405     }
00406     void Append_info_string(const std::string& add_str)
00407     {
00408       info_string_ += add_str;
00409     }
00410     const std::string& info_string() const
00411     {
00412       return info_string_;
00413     }
00416     void Set_info_skip_output(bool info_skip_output)
00417     {
00418       info_skip_output_ = info_skip_output;
00419     }
00420 
00422     void ResetInfo()
00423     {
00424       info_regu_x_ = 0;
00425       info_alpha_primal_ = 0;
00426       info_alpha_dual_ = 0.;
00427       info_alpha_primal_char_ = ' ';
00428       info_ls_count_ = 0;
00429       info_skip_output_ = false;
00430       info_string_.erase();
00431     }
00433 
00435     TimingStatistics& TimingStats()
00436     {
00437       return timing_statistics_;
00438     }
00439 
00441     bool HaveAddData()
00442     {
00443       return IsValid(add_data_);
00444     }
00445 
00447     IpoptAdditionalData& AdditionalData()
00448     {
00449       return *add_data_;
00450     }
00451 
00453     void SetAddData(SmartPtr<IpoptAdditionalData> add_data)
00454     {
00455       DBG_ASSERT(!HaveAddData());
00456       add_data_ = add_data;
00457     }
00458 
00460     void setPDPert(Number pd_pert_x, Number pd_pert_s,
00461                    Number pd_pert_c, Number pd_pert_d)
00462     {
00463       pd_pert_x_ = pd_pert_x;
00464       pd_pert_s_ = pd_pert_s;
00465       pd_pert_c_ = pd_pert_c;
00466       pd_pert_d_ = pd_pert_d;
00467     }
00468 
00470     void getPDPert(Number& pd_pert_x, Number& pd_pert_s,
00471                    Number& pd_pert_c, Number& pd_pert_d)
00472     {
00473       pd_pert_x = pd_pert_x_;
00474       pd_pert_s = pd_pert_s_;
00475       pd_pert_c = pd_pert_c_;
00476       pd_pert_d = pd_pert_d_;
00477     }
00478 
00481     static void RegisterOptions(const SmartPtr<RegisteredOptions>& roptions);
00483 
00484   private:
00489     SmartPtr<const IteratesVector> curr_;
00490 
00493     SmartPtr<const IteratesVector> trial_;
00494 
00496     SmartPtr<const SymMatrix> W_;
00497 
00500     SmartPtr<const IteratesVector> delta_;
00508     bool have_deltas_;
00510 
00516     SmartPtr<const IteratesVector> delta_aff_;
00523     bool have_affine_deltas_;
00525 
00527     Index iter_count_;
00528 
00530     Number curr_mu_;
00531     bool mu_initialized_;
00532 
00534     Number curr_tau_;
00535     bool tau_initialized_;
00536 
00539     bool initialize_called_;
00540 
00543     bool have_prototypes_;
00544 
00551     Number tol_;
00553 
00557     bool free_mu_mode_;
00559     bool tiny_step_flag_;
00561 
00565     Number info_regu_x_;
00567     Number info_alpha_primal_;
00569     char info_alpha_primal_char_;
00571     Number info_alpha_dual_;
00573     Index info_ls_count_;
00576     bool info_skip_output_;
00578     std::string info_string_;
00580 
00582     SmartPtr<IteratesVectorSpace> iterates_space_;
00583 
00586     TimingStatistics timing_statistics_;
00587 
00590     SmartPtr<IpoptAdditionalData> add_data_;
00591 
00595     Number pd_pert_x_;
00596     Number pd_pert_s_;
00597     Number pd_pert_c_;
00598     Number pd_pert_d_;
00600 
00610     IpoptData(const IpoptData&);
00611 
00613     void operator=(const IpoptData&);
00615 
00616 #if COIN_IPOPT_CHECKLEVEL > 0
00617 
00621     TaggedObject::Tag debug_curr_tag_;
00622     TaggedObject::Tag debug_trial_tag_;
00623     TaggedObject::Tag debug_delta_tag_;
00624     TaggedObject::Tag debug_delta_aff_tag_;
00625     TaggedObject::Tag debug_curr_tag_sum_;
00626     TaggedObject::Tag debug_trial_tag_sum_;
00627     TaggedObject::Tag debug_delta_tag_sum_;
00628     TaggedObject::Tag debug_delta_aff_tag_sum_;
00630 #endif
00631 
00632   };
00633 
00634   inline
00635   SmartPtr<const IteratesVector> IpoptData::curr() const
00636   {
00637     DBG_ASSERT(IsNull(curr_) || (curr_->GetTag() == debug_curr_tag_ && curr_->GetTagSum() == debug_curr_tag_sum_) );
00638 
00639     return curr_;
00640   }
00641 
00642   inline
00643   SmartPtr<const IteratesVector> IpoptData::trial() const
00644   {
00645     DBG_ASSERT(IsNull(trial_) || (trial_->GetTag() == debug_trial_tag_ && trial_->GetTagSum() == debug_trial_tag_sum_) );
00646 
00647     return trial_;
00648   }
00649 
00650   inline
00651   SmartPtr<const IteratesVector> IpoptData::delta() const
00652   {
00653     DBG_ASSERT(IsNull(delta_) || (delta_->GetTag() == debug_delta_tag_ && delta_->GetTagSum() == debug_delta_tag_sum_) );
00654 
00655     return delta_;
00656   }
00657 
00658   inline
00659   SmartPtr<const IteratesVector> IpoptData::delta_aff() const
00660   {
00661     DBG_ASSERT(IsNull(delta_aff_) || (delta_aff_->GetTag() == debug_delta_aff_tag_ && delta_aff_->GetTagSum() == debug_delta_aff_tag_sum_) );
00662 
00663     return delta_aff_;
00664   }
00665 
00666   inline
00667   void IpoptData::CopyTrialToCurrent()
00668   {
00669     curr_ = trial_;
00670 #if COIN_IPOPT_CHECKLEVEL > 0
00671 
00672     if (IsValid(curr_)) {
00673       debug_curr_tag_ = curr_->GetTag();
00674       debug_curr_tag_sum_ = curr_->GetTagSum();
00675     }
00676     else {
00677       debug_curr_tag_ = 0;
00678       debug_curr_tag_sum_ = 0;
00679     }
00680 #endif
00681 
00682   }
00683 
00684   inline
00685   void IpoptData::set_trial(SmartPtr<IteratesVector>& trial)
00686   {
00687     trial_ = ConstPtr(trial);
00688 
00689 #if COIN_IPOPT_CHECKLEVEL > 0
00690     // verify the correct space
00691     DBG_ASSERT(trial_->OwnerSpace() == (VectorSpace*)GetRawPtr(iterates_space_));
00692     if (IsValid(trial)) {
00693       debug_trial_tag_ = trial->GetTag();
00694       debug_trial_tag_sum_ = trial->GetTagSum();
00695     }
00696     else {
00697       debug_trial_tag_ = 0;
00698       debug_trial_tag_sum_ = 0;
00699     }
00700 #endif
00701 
00702     trial = NULL;
00703   }
00704 
00705   inline
00706   void IpoptData::set_delta(SmartPtr<IteratesVector>& delta)
00707   {
00708     delta_ = ConstPtr(delta);
00709 #if COIN_IPOPT_CHECKLEVEL > 0
00710 
00711     if (IsValid(delta)) {
00712       debug_delta_tag_ = delta->GetTag();
00713       debug_delta_tag_sum_ = delta->GetTagSum();
00714     }
00715     else {
00716       debug_delta_tag_ = 0;
00717       debug_delta_tag_sum_ = 0;
00718     }
00719 #endif
00720 
00721     delta = NULL;
00722   }
00723 
00724   inline
00725   void IpoptData::set_delta(SmartPtr<const IteratesVector>& delta)
00726   {
00727     delta_ = delta;
00728 #if COIN_IPOPT_CHECKLEVEL > 0
00729 
00730     if (IsValid(delta)) {
00731       debug_delta_tag_ = delta->GetTag();
00732       debug_delta_tag_sum_ = delta->GetTagSum();
00733     }
00734     else {
00735       debug_delta_tag_ = 0;
00736       debug_delta_tag_sum_ = 0;
00737     }
00738 #endif
00739 
00740     delta = NULL;
00741   }
00742 
00743   inline
00744   void IpoptData::set_delta_aff(SmartPtr<IteratesVector>& delta_aff)
00745   {
00746     delta_aff_ = ConstPtr(delta_aff);
00747 #if COIN_IPOPT_CHECKLEVEL > 0
00748 
00749     if (IsValid(delta_aff)) {
00750       debug_delta_aff_tag_ = delta_aff->GetTag();
00751       debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
00752     }
00753     else {
00754       debug_delta_aff_tag_ = 0;
00755       debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
00756     }
00757 #endif
00758 
00759     delta_aff = NULL;
00760   }
00761 
00762 } // namespace Ipopt
00763 
00764 #endif

Generated on Wed Jan 14 03:00:32 2009 by  doxygen 1.4.7