/home/coin/SVN-release/Ipopt-3.5.4/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 1327 2008-09-18 19:01:17Z 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     IpoptAdditionalData& AdditionalData()
00442     {
00443       return *add_data_;
00444     }
00445 
00447     void setPDPert(Number pd_pert_x, Number pd_pert_s,
00448                    Number pd_pert_c, Number pd_pert_d)
00449     {
00450       pd_pert_x_ = pd_pert_x;
00451       pd_pert_s_ = pd_pert_s;
00452       pd_pert_c_ = pd_pert_c;
00453       pd_pert_d_ = pd_pert_d;
00454     }
00455 
00457     void getPDPert(Number& pd_pert_x, Number& pd_pert_s,
00458                    Number& pd_pert_c, Number& pd_pert_d)
00459     {
00460       pd_pert_x = pd_pert_x_;
00461       pd_pert_s = pd_pert_s_;
00462       pd_pert_c = pd_pert_c_;
00463       pd_pert_d = pd_pert_d_;
00464     }
00465 
00468     static void RegisterOptions(const SmartPtr<RegisteredOptions>& roptions);
00470 
00471   private:
00476     SmartPtr<const IteratesVector> curr_;
00477 
00480     SmartPtr<const IteratesVector> trial_;
00481 
00483     SmartPtr<const SymMatrix> W_;
00484 
00487     SmartPtr<const IteratesVector> delta_;
00495     bool have_deltas_;
00497 
00503     SmartPtr<const IteratesVector> delta_aff_;
00510     bool have_affine_deltas_;
00512 
00514     Index iter_count_;
00515 
00517     Number curr_mu_;
00518     bool mu_initialized_;
00519 
00521     Number curr_tau_;
00522     bool tau_initialized_;
00523 
00526     bool initialize_called_;
00527 
00530     bool have_prototypes_;
00531 
00538     Number tol_;
00540 
00544     bool free_mu_mode_;
00546     bool tiny_step_flag_;
00548 
00552     Number info_regu_x_;
00554     Number info_alpha_primal_;
00556     char info_alpha_primal_char_;
00558     Number info_alpha_dual_;
00560     Index info_ls_count_;
00563     bool info_skip_output_;
00565     std::string info_string_;
00567 
00569     SmartPtr<IteratesVectorSpace> iterates_space_;
00570 
00573     TimingStatistics timing_statistics_;
00574 
00577     SmartPtr<IpoptAdditionalData> add_data_;
00578 
00582     Number pd_pert_x_;
00583     Number pd_pert_s_;
00584     Number pd_pert_c_;
00585     Number pd_pert_d_;
00587 
00597     IpoptData(const IpoptData&);
00598 
00600     void operator=(const IpoptData&);
00602 
00603 #if COIN_IPOPT_CHECKLEVEL > 0
00604 
00608     TaggedObject::Tag debug_curr_tag_;
00609     TaggedObject::Tag debug_trial_tag_;
00610     TaggedObject::Tag debug_delta_tag_;
00611     TaggedObject::Tag debug_delta_aff_tag_;
00612     TaggedObject::Tag debug_curr_tag_sum_;
00613     TaggedObject::Tag debug_trial_tag_sum_;
00614     TaggedObject::Tag debug_delta_tag_sum_;
00615     TaggedObject::Tag debug_delta_aff_tag_sum_;
00617 #endif
00618 
00619   };
00620 
00621   inline
00622   SmartPtr<const IteratesVector> IpoptData::curr() const
00623   {
00624     DBG_ASSERT(IsNull(curr_) || (curr_->GetTag() == debug_curr_tag_ && curr_->GetTagSum() == debug_curr_tag_sum_) );
00625 
00626     return curr_;
00627   }
00628 
00629   inline
00630   SmartPtr<const IteratesVector> IpoptData::trial() const
00631   {
00632     DBG_ASSERT(IsNull(trial_) || (trial_->GetTag() == debug_trial_tag_ && trial_->GetTagSum() == debug_trial_tag_sum_) );
00633 
00634     return trial_;
00635   }
00636 
00637   inline
00638   SmartPtr<const IteratesVector> IpoptData::delta() const
00639   {
00640     DBG_ASSERT(IsNull(delta_) || (delta_->GetTag() == debug_delta_tag_ && delta_->GetTagSum() == debug_delta_tag_sum_) );
00641 
00642     return delta_;
00643   }
00644 
00645   inline
00646   SmartPtr<const IteratesVector> IpoptData::delta_aff() const
00647   {
00648     DBG_ASSERT(IsNull(delta_aff_) || (delta_aff_->GetTag() == debug_delta_aff_tag_ && delta_aff_->GetTagSum() == debug_delta_aff_tag_sum_) );
00649 
00650     return delta_aff_;
00651   }
00652 
00653   inline
00654   void IpoptData::CopyTrialToCurrent()
00655   {
00656     curr_ = trial_;
00657 #if COIN_IPOPT_CHECKLEVEL > 0
00658 
00659     if (IsValid(curr_)) {
00660       debug_curr_tag_ = curr_->GetTag();
00661       debug_curr_tag_sum_ = curr_->GetTagSum();
00662     }
00663     else {
00664       debug_curr_tag_ = 0;
00665       debug_curr_tag_sum_ = 0;
00666     }
00667 #endif
00668 
00669   }
00670 
00671   inline
00672   void IpoptData::set_trial(SmartPtr<IteratesVector>& trial)
00673   {
00674     trial_ = ConstPtr(trial);
00675 
00676 #if COIN_IPOPT_CHECKLEVEL > 0
00677     // verify the correct space
00678     DBG_ASSERT(trial_->OwnerSpace() == (VectorSpace*)GetRawPtr(iterates_space_));
00679     if (IsValid(trial)) {
00680       debug_trial_tag_ = trial->GetTag();
00681       debug_trial_tag_sum_ = trial->GetTagSum();
00682     }
00683     else {
00684       debug_trial_tag_ = 0;
00685       debug_trial_tag_sum_ = 0;
00686     }
00687 #endif
00688 
00689     trial = NULL;
00690   }
00691 
00692   inline
00693   void IpoptData::set_delta(SmartPtr<IteratesVector>& delta)
00694   {
00695     delta_ = ConstPtr(delta);
00696 #if COIN_IPOPT_CHECKLEVEL > 0
00697 
00698     if (IsValid(delta)) {
00699       debug_delta_tag_ = delta->GetTag();
00700       debug_delta_tag_sum_ = delta->GetTagSum();
00701     }
00702     else {
00703       debug_delta_tag_ = 0;
00704       debug_delta_tag_sum_ = 0;
00705     }
00706 #endif
00707 
00708     delta = NULL;
00709   }
00710 
00711   inline
00712   void IpoptData::set_delta(SmartPtr<const IteratesVector>& delta)
00713   {
00714     delta_ = delta;
00715 #if COIN_IPOPT_CHECKLEVEL > 0
00716 
00717     if (IsValid(delta)) {
00718       debug_delta_tag_ = delta->GetTag();
00719       debug_delta_tag_sum_ = delta->GetTagSum();
00720     }
00721     else {
00722       debug_delta_tag_ = 0;
00723       debug_delta_tag_sum_ = 0;
00724     }
00725 #endif
00726 
00727     delta = NULL;
00728   }
00729 
00730   inline
00731   void IpoptData::set_delta_aff(SmartPtr<IteratesVector>& delta_aff)
00732   {
00733     delta_aff_ = ConstPtr(delta_aff);
00734 #if COIN_IPOPT_CHECKLEVEL > 0
00735 
00736     if (IsValid(delta_aff)) {
00737       debug_delta_aff_tag_ = delta_aff->GetTag();
00738       debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
00739     }
00740     else {
00741       debug_delta_aff_tag_ = 0;
00742       debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
00743     }
00744 #endif
00745 
00746     delta_aff = NULL;
00747   }
00748 
00749 } // namespace Ipopt
00750 
00751 #endif

Generated on Tue Sep 30 03:03:29 2008 by  doxygen 1.4.7