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

Go to the documentation of this file.
00001 // Copyright (C) 2004, 2009 International Business Machines and others.
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // $Id: IpIpoptData.hpp 1435 2009-04-24 17:09:05Z 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               Number cpu_time_start = -1.);
00091 
00093     virtual ~IpoptData();
00095 
00097     bool InitializeDataStructures(IpoptNLP& ip_nlp,
00098                                   bool want_x,
00099                                   bool want_y_c,
00100                                   bool want_y_d,
00101                                   bool want_z_L,
00102                                   bool want_z_U);
00103 
00107     bool Initialize(const Journalist& jnlst,
00108                     const OptionsList& options,
00109                     const std::string& prefix);
00110 
00114     SmartPtr<const IteratesVector> curr() const;
00115 
00120     //    SmartPtr<IteratesVector> curr_container() const;
00121 
00123     SmartPtr<const IteratesVector> trial() const;
00124 
00129     //SmartPtr<IteratesVector> trial_container() const;
00130 
00135     void set_trial(SmartPtr<IteratesVector>& trial);
00136 
00140     void SetTrialPrimalVariablesFromStep(Number alpha,
00141                                          const Vector& delta_x,
00142                                          const Vector& delta_s);
00147     void SetTrialEqMultipliersFromStep(Number alpha,
00148                                        const Vector& delta_y_c,
00149                                        const Vector& delta_y_d);
00154     void SetTrialBoundMultipliersFromStep(Number alpha,
00155                                           const Vector& delta_z_L,
00156                                           const Vector& delta_z_U,
00157                                           const Vector& delta_v_L,
00158                                           const Vector& delta_v_U);
00159 
00163     // void set_trial(const SmartPtr<IteratesVector>& trial_iterates);
00164     // void set_trial(SmartPtr<const IteratesVector>& trial_iterates);
00165 
00167     SmartPtr<const IteratesVector> delta() const;
00168 
00173     void set_delta(SmartPtr<IteratesVector>& delta);
00174 
00181     void set_delta(SmartPtr<const IteratesVector>& delta);
00182 
00184     SmartPtr<const IteratesVector> delta_aff() const;
00185 
00190     void set_delta_aff(SmartPtr<IteratesVector>& delta_aff);
00191 
00193     SmartPtr<const SymMatrix> W()
00194     {
00195       DBG_ASSERT(IsValid(W_));
00196       return W_;
00197     }
00198 
00200     void Set_W(SmartPtr<const SymMatrix> W)
00201     {
00202       W_ = W;
00203     }
00204 
00211 
00219     bool HaveDeltas() const
00220     {
00221       return have_deltas_;
00222     }
00223 
00229     void SetHaveDeltas(bool have_deltas)
00230     {
00231       have_deltas_ = have_deltas;
00232     }
00234 
00241 
00249     bool HaveAffineDeltas() const
00250     {
00251       return have_affine_deltas_;
00252     }
00253 
00259     void SetHaveAffineDeltas(bool have_affine_deltas)
00260     {
00261       have_affine_deltas_ = have_affine_deltas;
00262     }
00264 
00268     void CopyTrialToCurrent();
00269 
00272     void AcceptTrialPoint();
00274 
00277     Index iter_count() const
00278     {
00279       return iter_count_;
00280     }
00281     void Set_iter_count(Index iter_count)
00282     {
00283       iter_count_ = iter_count;
00284     }
00285 
00286     Number curr_mu() const
00287     {
00288       DBG_ASSERT(mu_initialized_);
00289       return curr_mu_;
00290     }
00291     void Set_mu(Number mu)
00292     {
00293       curr_mu_ = mu;
00294       mu_initialized_ = true;
00295     }
00296     bool MuInitialized() const
00297     {
00298       return mu_initialized_;
00299     }
00300 
00301     Number curr_tau() const
00302     {
00303       DBG_ASSERT(tau_initialized_);
00304       return curr_tau_;
00305     }
00306     void Set_tau(Number tau)
00307     {
00308       curr_tau_ = tau;
00309       tau_initialized_ = true;
00310     }
00311     bool TauInitialized() const
00312     {
00313       return tau_initialized_;
00314     }
00315 
00316     void SetFreeMuMode(bool free_mu_mode)
00317     {
00318       free_mu_mode_ = free_mu_mode;
00319     }
00320     bool FreeMuMode() const
00321     {
00322       return free_mu_mode_;
00323     }
00324 
00327     void Set_tiny_step_flag(bool flag)
00328     {
00329       tiny_step_flag_ = flag;
00330     }
00331     bool tiny_step_flag()
00332     {
00333       return tiny_step_flag_;
00334     }
00336 
00343     Number tol() const
00344     {
00345       DBG_ASSERT(initialize_called_);
00346       return tol_;
00347     }
00355     void Set_tol(Number tol)
00356     {
00357       tol_ = tol;
00358     }
00360 
00364     Number cpu_time_start() const
00365     {
00366       return cpu_time_start_;
00367     }
00368 
00371     Number info_regu_x() const
00372     {
00373       return info_regu_x_;
00374     }
00375     void Set_info_regu_x(Number regu_x)
00376     {
00377       info_regu_x_ = regu_x;
00378     }
00379     Number info_alpha_primal() const
00380     {
00381       return info_alpha_primal_;
00382     }
00383     void Set_info_alpha_primal(Number alpha_primal)
00384     {
00385       info_alpha_primal_ = alpha_primal;
00386     }
00387     char info_alpha_primal_char() const
00388     {
00389       return info_alpha_primal_char_;
00390     }
00391     void Set_info_alpha_primal_char(char info_alpha_primal_char)
00392     {
00393       info_alpha_primal_char_ = info_alpha_primal_char;
00394     }
00395     Number info_alpha_dual() const
00396     {
00397       return info_alpha_dual_;
00398     }
00399     void Set_info_alpha_dual(Number alpha_dual)
00400     {
00401       info_alpha_dual_ = alpha_dual;
00402     }
00403     Index info_ls_count() const
00404     {
00405       return info_ls_count_;
00406     }
00407     void Set_info_ls_count(Index ls_count)
00408     {
00409       info_ls_count_ = ls_count;
00410     }
00411     bool info_skip_output() const
00412     {
00413       return info_skip_output_;
00414     }
00415     void Append_info_string(const std::string& add_str)
00416     {
00417       info_string_ += add_str;
00418     }
00419     const std::string& info_string() const
00420     {
00421       return info_string_;
00422     }
00425     void Set_info_skip_output(bool info_skip_output)
00426     {
00427       info_skip_output_ = info_skip_output;
00428     }
00429 
00431     void ResetInfo()
00432     {
00433       info_regu_x_ = 0;
00434       info_alpha_primal_ = 0;
00435       info_alpha_dual_ = 0.;
00436       info_alpha_primal_char_ = ' ';
00437       info_ls_count_ = 0;
00438       info_skip_output_ = false;
00439       info_string_.erase();
00440     }
00442 
00444     TimingStatistics& TimingStats()
00445     {
00446       return timing_statistics_;
00447     }
00448 
00450     bool HaveAddData()
00451     {
00452       return IsValid(add_data_);
00453     }
00454 
00456     IpoptAdditionalData& AdditionalData()
00457     {
00458       return *add_data_;
00459     }
00460 
00462     void SetAddData(SmartPtr<IpoptAdditionalData> add_data)
00463     {
00464       DBG_ASSERT(!HaveAddData());
00465       add_data_ = add_data;
00466     }
00467 
00469     void setPDPert(Number pd_pert_x, Number pd_pert_s,
00470                    Number pd_pert_c, Number pd_pert_d)
00471     {
00472       pd_pert_x_ = pd_pert_x;
00473       pd_pert_s_ = pd_pert_s;
00474       pd_pert_c_ = pd_pert_c;
00475       pd_pert_d_ = pd_pert_d;
00476     }
00477 
00479     void getPDPert(Number& pd_pert_x, Number& pd_pert_s,
00480                    Number& pd_pert_c, Number& pd_pert_d)
00481     {
00482       pd_pert_x = pd_pert_x_;
00483       pd_pert_s = pd_pert_s_;
00484       pd_pert_c = pd_pert_c_;
00485       pd_pert_d = pd_pert_d_;
00486     }
00487 
00490     static void RegisterOptions(const SmartPtr<RegisteredOptions>& roptions);
00492 
00493   private:
00498     SmartPtr<const IteratesVector> curr_;
00499 
00502     SmartPtr<const IteratesVector> trial_;
00503 
00505     SmartPtr<const SymMatrix> W_;
00506 
00509     SmartPtr<const IteratesVector> delta_;
00517     bool have_deltas_;
00519 
00525     SmartPtr<const IteratesVector> delta_aff_;
00532     bool have_affine_deltas_;
00534 
00536     Index iter_count_;
00537 
00539     Number curr_mu_;
00540     bool mu_initialized_;
00541 
00543     Number curr_tau_;
00544     bool tau_initialized_;
00545 
00548     bool initialize_called_;
00549 
00552     bool have_prototypes_;
00553 
00560     Number tol_;
00562 
00566     bool free_mu_mode_;
00568     bool tiny_step_flag_;
00570 
00574     Number info_regu_x_;
00576     Number info_alpha_primal_;
00578     char info_alpha_primal_char_;
00580     Number info_alpha_dual_;
00582     Index info_ls_count_;
00585     bool info_skip_output_;
00587     std::string info_string_;
00589 
00591     SmartPtr<IteratesVectorSpace> iterates_space_;
00592 
00595     TimingStatistics timing_statistics_;
00596 
00598     Number cpu_time_start_;
00599 
00602     SmartPtr<IpoptAdditionalData> add_data_;
00603 
00607     Number pd_pert_x_;
00608     Number pd_pert_s_;
00609     Number pd_pert_c_;
00610     Number pd_pert_d_;
00612 
00622     IpoptData(const IpoptData&);
00623 
00625     void operator=(const IpoptData&);
00627 
00628 #if COIN_IPOPT_CHECKLEVEL > 0
00629 
00633     TaggedObject::Tag debug_curr_tag_;
00634     TaggedObject::Tag debug_trial_tag_;
00635     TaggedObject::Tag debug_delta_tag_;
00636     TaggedObject::Tag debug_delta_aff_tag_;
00637     TaggedObject::Tag debug_curr_tag_sum_;
00638     TaggedObject::Tag debug_trial_tag_sum_;
00639     TaggedObject::Tag debug_delta_tag_sum_;
00640     TaggedObject::Tag debug_delta_aff_tag_sum_;
00642 #endif
00643 
00644   };
00645 
00646   inline
00647   SmartPtr<const IteratesVector> IpoptData::curr() const
00648   {
00649     DBG_ASSERT(IsNull(curr_) || (curr_->GetTag() == debug_curr_tag_ && curr_->GetTagSum() == debug_curr_tag_sum_) );
00650 
00651     return curr_;
00652   }
00653 
00654   inline
00655   SmartPtr<const IteratesVector> IpoptData::trial() const
00656   {
00657     DBG_ASSERT(IsNull(trial_) || (trial_->GetTag() == debug_trial_tag_ && trial_->GetTagSum() == debug_trial_tag_sum_) );
00658 
00659     return trial_;
00660   }
00661 
00662   inline
00663   SmartPtr<const IteratesVector> IpoptData::delta() const
00664   {
00665     DBG_ASSERT(IsNull(delta_) || (delta_->GetTag() == debug_delta_tag_ && delta_->GetTagSum() == debug_delta_tag_sum_) );
00666 
00667     return delta_;
00668   }
00669 
00670   inline
00671   SmartPtr<const IteratesVector> IpoptData::delta_aff() const
00672   {
00673     DBG_ASSERT(IsNull(delta_aff_) || (delta_aff_->GetTag() == debug_delta_aff_tag_ && delta_aff_->GetTagSum() == debug_delta_aff_tag_sum_) );
00674 
00675     return delta_aff_;
00676   }
00677 
00678   inline
00679   void IpoptData::CopyTrialToCurrent()
00680   {
00681     curr_ = trial_;
00682 #if COIN_IPOPT_CHECKLEVEL > 0
00683 
00684     if (IsValid(curr_)) {
00685       debug_curr_tag_ = curr_->GetTag();
00686       debug_curr_tag_sum_ = curr_->GetTagSum();
00687     }
00688     else {
00689       debug_curr_tag_ = 0;
00690       debug_curr_tag_sum_ = 0;
00691     }
00692 #endif
00693 
00694   }
00695 
00696   inline
00697   void IpoptData::set_trial(SmartPtr<IteratesVector>& trial)
00698   {
00699     trial_ = ConstPtr(trial);
00700 
00701 #if COIN_IPOPT_CHECKLEVEL > 0
00702     // verify the correct space
00703     DBG_ASSERT(trial_->OwnerSpace() == (VectorSpace*)GetRawPtr(iterates_space_));
00704     if (IsValid(trial)) {
00705       debug_trial_tag_ = trial->GetTag();
00706       debug_trial_tag_sum_ = trial->GetTagSum();
00707     }
00708     else {
00709       debug_trial_tag_ = 0;
00710       debug_trial_tag_sum_ = 0;
00711     }
00712 #endif
00713 
00714     trial = NULL;
00715   }
00716 
00717   inline
00718   void IpoptData::set_delta(SmartPtr<IteratesVector>& delta)
00719   {
00720     delta_ = ConstPtr(delta);
00721 #if COIN_IPOPT_CHECKLEVEL > 0
00722 
00723     if (IsValid(delta)) {
00724       debug_delta_tag_ = delta->GetTag();
00725       debug_delta_tag_sum_ = delta->GetTagSum();
00726     }
00727     else {
00728       debug_delta_tag_ = 0;
00729       debug_delta_tag_sum_ = 0;
00730     }
00731 #endif
00732 
00733     delta = NULL;
00734   }
00735 
00736   inline
00737   void IpoptData::set_delta(SmartPtr<const IteratesVector>& delta)
00738   {
00739     delta_ = delta;
00740 #if COIN_IPOPT_CHECKLEVEL > 0
00741 
00742     if (IsValid(delta)) {
00743       debug_delta_tag_ = delta->GetTag();
00744       debug_delta_tag_sum_ = delta->GetTagSum();
00745     }
00746     else {
00747       debug_delta_tag_ = 0;
00748       debug_delta_tag_sum_ = 0;
00749     }
00750 #endif
00751 
00752     delta = NULL;
00753   }
00754 
00755   inline
00756   void IpoptData::set_delta_aff(SmartPtr<IteratesVector>& delta_aff)
00757   {
00758     delta_aff_ = ConstPtr(delta_aff);
00759 #if COIN_IPOPT_CHECKLEVEL > 0
00760 
00761     if (IsValid(delta_aff)) {
00762       debug_delta_aff_tag_ = delta_aff->GetTag();
00763       debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
00764     }
00765     else {
00766       debug_delta_aff_tag_ = 0;
00767       debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
00768     }
00769 #endif
00770 
00771     delta_aff = NULL;
00772   }
00773 
00774 } // namespace Ipopt
00775 
00776 #endif

Generated on Sat May 2 03:04:12 2009 by  doxygen 1.4.7