- Main Page
- Classes
- Files

- File List
- File Members

# 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 Eclipse Public License.
    00004 //
    00005 // $Id: IpIpoptData.hpp 2476 2014-04-08 09:41:07Z stefan $
    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     inline
    00115     SmartPtr<const IteratesVector> curr() const;
    00116
    00121     //    SmartPtr<IteratesVector> curr_container() const;
    00122
    00124     inline
    00125     SmartPtr<const IteratesVector> trial() const;
    00126
    00131     //SmartPtr<IteratesVector> trial_container() const;
    00132
    00137     inline
    00138     void set_trial(SmartPtr<IteratesVector>& trial);
    00139
    00143     void SetTrialPrimalVariablesFromStep(Number alpha,
    00144                                          const Vector& delta_x,
    00145                                          const Vector& delta_s);
    00150     void SetTrialEqMultipliersFromStep(Number alpha,
    00151                                        const Vector& delta_y_c,
    00152                                        const Vector& delta_y_d);
    00157     void SetTrialBoundMultipliersFromStep(Number alpha,
    00158                                           const Vector& delta_z_L,
    00159                                           const Vector& delta_z_U,
    00160                                           const Vector& delta_v_L,
    00161                                           const Vector& delta_v_U);
    00162
    00166     // void set_trial(const SmartPtr<IteratesVector>& trial_iterates);
    00167     // void set_trial(SmartPtr<const IteratesVector>& trial_iterates);
    00168
    00170     inline
    00171     SmartPtr<const IteratesVector> delta() const;
    00172
    00177     inline
    00178     void set_delta(SmartPtr<IteratesVector>& delta);
    00179
    00186     inline
    00187     void set_delta(SmartPtr<const IteratesVector>& delta);
    00188
    00190     inline
    00191     SmartPtr<const IteratesVector> delta_aff() const;
    00192
    00197     inline
    00198     void set_delta_aff(SmartPtr<IteratesVector>& delta_aff);
    00199
    00201     SmartPtr<const SymMatrix> W()
    00202     {
    00203       DBG_ASSERT(IsValid(W_));
    00204       return W_;
    00205     }
    00206
    00208     void Set_W(SmartPtr<const SymMatrix> W)
    00209     {
    00210       W_ = W;
    00211     }
    00212
    00219
    00227     bool HaveDeltas() const
    00228     {
    00229       return have_deltas_;
    00230     }
    00231
    00237     void SetHaveDeltas(bool have_deltas)
    00238     {
    00239       have_deltas_ = have_deltas;
    00240     }
    00242
    00249
    00257     bool HaveAffineDeltas() const
    00258     {
    00259       return have_affine_deltas_;
    00260     }
    00261
    00267     void SetHaveAffineDeltas(bool have_affine_deltas)
    00268     {
    00269       have_affine_deltas_ = have_affine_deltas;
    00270     }
    00272
    00276     inline
    00277     void CopyTrialToCurrent();
    00278
    00281     void AcceptTrialPoint();
    00283
    00286     Index iter_count() const
    00287     {
    00288       return iter_count_;
    00289     }
    00290     void Set_iter_count(Index iter_count)
    00291     {
    00292       iter_count_ = iter_count;
    00293     }
    00294
    00295     Number curr_mu() const
    00296     {
    00297       DBG_ASSERT(mu_initialized_);
    00298       return curr_mu_;
    00299     }
    00300     void Set_mu(Number mu)
    00301     {
    00302       curr_mu_ = mu;
    00303       mu_initialized_ = true;
    00304     }
    00305     bool MuInitialized() const
    00306     {
    00307       return mu_initialized_;
    00308     }
    00309
    00310     Number curr_tau() const
    00311     {
    00312       DBG_ASSERT(tau_initialized_);
    00313       return curr_tau_;
    00314     }
    00315     void Set_tau(Number tau)
    00316     {
    00317       curr_tau_ = tau;
    00318       tau_initialized_ = true;
    00319     }
    00320     bool TauInitialized() const
    00321     {
    00322       return tau_initialized_;
    00323     }
    00324
    00325     void SetFreeMuMode(bool free_mu_mode)
    00326     {
    00327       free_mu_mode_ = free_mu_mode;
    00328     }
    00329     bool FreeMuMode() const
    00330     {
    00331       return free_mu_mode_;
    00332     }
    00333
    00336     void Set_tiny_step_flag(bool flag)
    00337     {
    00338       tiny_step_flag_ = flag;
    00339     }
    00340     bool tiny_step_flag()
    00341     {
    00342       return tiny_step_flag_;
    00343     }
    00345
    00352     Number tol() const
    00353     {
    00354       DBG_ASSERT(initialize_called_);
    00355       return tol_;
    00356     }
    00364     void Set_tol(Number tol)
    00365     {
    00366       tol_ = tol;
    00367     }
    00369
    00373     Number cpu_time_start() const
    00374     {
    00375       return cpu_time_start_;
    00376     }
    00377
    00380     Number info_regu_x() const
    00381     {
    00382       return info_regu_x_;
    00383     }
    00384     void Set_info_regu_x(Number regu_x)
    00385     {
    00386       info_regu_x_ = regu_x;
    00387     }
    00388     Number info_alpha_primal() const
    00389     {
    00390       return info_alpha_primal_;
    00391     }
    00392     void Set_info_alpha_primal(Number alpha_primal)
    00393     {
    00394       info_alpha_primal_ = alpha_primal;
    00395     }
    00396     char info_alpha_primal_char() const
    00397     {
    00398       return info_alpha_primal_char_;
    00399     }
    00400     void Set_info_alpha_primal_char(char info_alpha_primal_char)
    00401     {
    00402       info_alpha_primal_char_ = info_alpha_primal_char;
    00403     }
    00404     Number info_alpha_dual() const
    00405     {
    00406       return info_alpha_dual_;
    00407     }
    00408     void Set_info_alpha_dual(Number alpha_dual)
    00409     {
    00410       info_alpha_dual_ = alpha_dual;
    00411     }
    00412     Index info_ls_count() const
    00413     {
    00414       return info_ls_count_;
    00415     }
    00416     void Set_info_ls_count(Index ls_count)
    00417     {
    00418       info_ls_count_ = ls_count;
    00419     }
    00420     bool info_skip_output() const
    00421     {
    00422       return info_skip_output_;
    00423     }
    00424     void Append_info_string(const std::string& add_str)
    00425     {
    00426       info_string_ += add_str;
    00427     }
    00428     const std::string& info_string() const
    00429     {
    00430       return info_string_;
    00431     }
    00434     void Set_info_skip_output(bool info_skip_output)
    00435     {
    00436       info_skip_output_ = info_skip_output;
    00437     }
    00438
    00440     Number info_last_output()
    00441     {
    00442        return info_last_output_;
    00443     }
    00445     void Set_info_last_output(Number info_last_output)
    00446     {
    00447        info_last_output_ = info_last_output;
    00448     }
    00449
    00452     int info_iters_since_header()
    00453     {
    00454        return info_iters_since_header_;
    00455     }
    00458     void Inc_info_iters_since_header()
    00459     {
    00460        info_iters_since_header_++;
    00461     }
    00464     void Set_info_iters_since_header(int info_iters_since_header)
    00465     {
    00466        info_iters_since_header_ = info_iters_since_header;
    00467     }
    00468
    00470     void ResetInfo()
    00471     {
    00472       info_regu_x_ = 0;
    00473       info_alpha_primal_ = 0;
    00474       info_alpha_dual_ = 0.;
    00475       info_alpha_primal_char_ = ' ';
    00476       info_skip_output_ = false;
    00477       info_string_.erase();
    00478     }
    00480
    00482     TimingStatistics& TimingStats()
    00483     {
    00484       return timing_statistics_;
    00485     }
    00486
    00488     bool HaveAddData()
    00489     {
    00490       return IsValid(add_data_);
    00491     }
    00492
    00494     IpoptAdditionalData& AdditionalData()
    00495     {
    00496       return *add_data_;
    00497     }
    00498
    00500     void SetAddData(SmartPtr<IpoptAdditionalData> add_data)
    00501     {
    00502       DBG_ASSERT(!HaveAddData());
    00503       add_data_ = add_data;
    00504     }
    00505
    00507     void setPDPert(Number pd_pert_x, Number pd_pert_s,
    00508                    Number pd_pert_c, Number pd_pert_d)
    00509     {
    00510       pd_pert_x_ = pd_pert_x;
    00511       pd_pert_s_ = pd_pert_s;
    00512       pd_pert_c_ = pd_pert_c;
    00513       pd_pert_d_ = pd_pert_d;
    00514     }
    00515
    00517     void getPDPert(Number& pd_pert_x, Number& pd_pert_s,
    00518                    Number& pd_pert_c, Number& pd_pert_d)
    00519     {
    00520       pd_pert_x = pd_pert_x_;
    00521       pd_pert_s = pd_pert_s_;
    00522       pd_pert_c = pd_pert_c_;
    00523       pd_pert_d = pd_pert_d_;
    00524     }
    00525
    00528     static void RegisterOptions(const SmartPtr<RegisteredOptions>& roptions);
    00530
    00531   private:
    00536     SmartPtr<const IteratesVector> curr_;
    00537
    00540     SmartPtr<const IteratesVector> trial_;
    00541
    00543     SmartPtr<const SymMatrix> W_;
    00544
    00547     SmartPtr<const IteratesVector> delta_;
    00555     bool have_deltas_;
    00557
    00563     SmartPtr<const IteratesVector> delta_aff_;
    00570     bool have_affine_deltas_;
    00572
    00574     Index iter_count_;
    00575
    00577     Number curr_mu_;
    00578     bool mu_initialized_;
    00579
    00581     Number curr_tau_;
    00582     bool tau_initialized_;
    00583
    00586     bool initialize_called_;
    00587
    00590     bool have_prototypes_;
    00591
    00598     Number tol_;
    00600
    00604     bool free_mu_mode_;
    00606     bool tiny_step_flag_;
    00608
    00612     Number info_regu_x_;
    00614     Number info_alpha_primal_;
    00616     char info_alpha_primal_char_;
    00618     Number info_alpha_dual_;
    00620     Index info_ls_count_;
    00623     bool info_skip_output_;
    00625     std::string info_string_;
    00627     Number info_last_output_;
    00630     int info_iters_since_header_;
    00632
    00634     SmartPtr<IteratesVectorSpace> iterates_space_;
    00635
    00638     TimingStatistics timing_statistics_;
    00639
    00641     Number cpu_time_start_;
    00642
    00645     SmartPtr<IpoptAdditionalData> add_data_;
    00646
    00650     Number pd_pert_x_;
    00651     Number pd_pert_s_;
    00652     Number pd_pert_c_;
    00653     Number pd_pert_d_;
    00655
    00665     IpoptData(const IpoptData&);
    00666
    00668     void operator=(const IpoptData&);
    00670
    00671 #if COIN_IPOPT_CHECKLEVEL > 0
    00672
    00676     TaggedObject::Tag debug_curr_tag_;
    00677     TaggedObject::Tag debug_trial_tag_;
    00678     TaggedObject::Tag debug_delta_tag_;
    00679     TaggedObject::Tag debug_delta_aff_tag_;
    00680     TaggedObject::Tag debug_curr_tag_sum_;
    00681     TaggedObject::Tag debug_trial_tag_sum_;
    00682     TaggedObject::Tag debug_delta_tag_sum_;
    00683     TaggedObject::Tag debug_delta_aff_tag_sum_;
    00685 #endif
    00686
    00687   };
    00688
    00689   inline
    00690   SmartPtr<const IteratesVector> IpoptData::curr() const
    00691   {
    00692     DBG_ASSERT(IsNull(curr_) || (curr_->GetTag() == debug_curr_tag_ && curr_->GetTagSum() == debug_curr_tag_sum_) );
    00693
    00694     return curr_;
    00695   }
    00696
    00697   inline
    00698   SmartPtr<const IteratesVector> IpoptData::trial() const
    00699   {
    00700     DBG_ASSERT(IsNull(trial_) || (trial_->GetTag() == debug_trial_tag_ && trial_->GetTagSum() == debug_trial_tag_sum_) );
    00701
    00702     return trial_;
    00703   }
    00704
    00705   inline
    00706   SmartPtr<const IteratesVector> IpoptData::delta() const
    00707   {
    00708     DBG_ASSERT(IsNull(delta_) || (delta_->GetTag() == debug_delta_tag_ && delta_->GetTagSum() == debug_delta_tag_sum_) );
    00709
    00710     return delta_;
    00711   }
    00712
    00713   inline
    00714   SmartPtr<const IteratesVector> IpoptData::delta_aff() const
    00715   {
    00716     DBG_ASSERT(IsNull(delta_aff_) || (delta_aff_->GetTag() == debug_delta_aff_tag_ && delta_aff_->GetTagSum() == debug_delta_aff_tag_sum_) );
    00717
    00718     return delta_aff_;
    00719   }
    00720
    00721   inline
    00722   void IpoptData::CopyTrialToCurrent()
    00723   {
    00724     curr_ = trial_;
    00725 #if COIN_IPOPT_CHECKLEVEL > 0
    00726
    00727     if (IsValid(curr_)) {
    00728       debug_curr_tag_ = curr_->GetTag();
    00729       debug_curr_tag_sum_ = curr_->GetTagSum();
    00730     }
    00731     else {
    00732       debug_curr_tag_ = 0;
    00733       debug_curr_tag_sum_ = 0;
    00734     }
    00735 #endif
    00736
    00737   }
    00738
    00739   inline
    00740   void IpoptData::set_trial(SmartPtr<IteratesVector>& trial)
    00741   {
    00742     trial_ = ConstPtr(trial);
    00743
    00744 #if COIN_IPOPT_CHECKLEVEL > 0
    00745     // verify the correct space
    00746     DBG_ASSERT(trial_->OwnerSpace() == (VectorSpace*)GetRawPtr(iterates_space_));
    00747     if (IsValid(trial)) {
    00748       debug_trial_tag_ = trial->GetTag();
    00749       debug_trial_tag_sum_ = trial->GetTagSum();
    00750     }
    00751     else {
    00752       debug_trial_tag_ = 0;
    00753       debug_trial_tag_sum_ = 0;
    00754     }
    00755 #endif
    00756
    00757     trial = NULL;
    00758   }
    00759
    00760   inline
    00761   void IpoptData::set_delta(SmartPtr<IteratesVector>& delta)
    00762   {
    00763     delta_ = ConstPtr(delta);
    00764 #if COIN_IPOPT_CHECKLEVEL > 0
    00765
    00766     if (IsValid(delta)) {
    00767       debug_delta_tag_ = delta->GetTag();
    00768       debug_delta_tag_sum_ = delta->GetTagSum();
    00769     }
    00770     else {
    00771       debug_delta_tag_ = 0;
    00772       debug_delta_tag_sum_ = 0;
    00773     }
    00774 #endif
    00775
    00776     delta = NULL;
    00777   }
    00778
    00779   inline
    00780   void IpoptData::set_delta(SmartPtr<const IteratesVector>& delta)
    00781   {
    00782     delta_ = delta;
    00783 #if COIN_IPOPT_CHECKLEVEL > 0
    00784
    00785     if (IsValid(delta)) {
    00786       debug_delta_tag_ = delta->GetTag();
    00787       debug_delta_tag_sum_ = delta->GetTagSum();
    00788     }
    00789     else {
    00790       debug_delta_tag_ = 0;
    00791       debug_delta_tag_sum_ = 0;
    00792     }
    00793 #endif
    00794
    00795     delta = NULL;
    00796   }
    00797
    00798   inline
    00799   void IpoptData::set_delta_aff(SmartPtr<IteratesVector>& delta_aff)
    00800   {
    00801     delta_aff_ = ConstPtr(delta_aff);
    00802 #if COIN_IPOPT_CHECKLEVEL > 0
    00803
    00804     if (IsValid(delta_aff)) {
    00805       debug_delta_aff_tag_ = delta_aff->GetTag();
    00806       debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
    00807     }
    00808     else {
    00809       debug_delta_aff_tag_ = 0;
    00810       debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
    00811     }
    00812 #endif
    00813
    00814     delta_aff = NULL;
    00815   }
    00816
    00817 } // namespace Ipopt
    00818
    00819 #endif

All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines