00001
00002
00003
00004
00005
00006
00007
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
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
00122
00124 inline
00125 SmartPtr<const IteratesVector> trial() const;
00126
00131
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
00167
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 void ResetInfo()
00441 {
00442 info_regu_x_ = 0;
00443 info_alpha_primal_ = 0;
00444 info_alpha_dual_ = 0.;
00445 info_alpha_primal_char_ = ' ';
00446 info_skip_output_ = false;
00447 info_string_.erase();
00448 }
00450
00452 TimingStatistics& TimingStats()
00453 {
00454 return timing_statistics_;
00455 }
00456
00458 bool HaveAddData()
00459 {
00460 return IsValid(add_data_);
00461 }
00462
00464 IpoptAdditionalData& AdditionalData()
00465 {
00466 return *add_data_;
00467 }
00468
00470 void SetAddData(SmartPtr<IpoptAdditionalData> add_data)
00471 {
00472 DBG_ASSERT(!HaveAddData());
00473 add_data_ = add_data;
00474 }
00475
00477 void setPDPert(Number pd_pert_x, Number pd_pert_s,
00478 Number pd_pert_c, Number pd_pert_d)
00479 {
00480 pd_pert_x_ = pd_pert_x;
00481 pd_pert_s_ = pd_pert_s;
00482 pd_pert_c_ = pd_pert_c;
00483 pd_pert_d_ = pd_pert_d;
00484 }
00485
00487 void getPDPert(Number& pd_pert_x, Number& pd_pert_s,
00488 Number& pd_pert_c, Number& pd_pert_d)
00489 {
00490 pd_pert_x = pd_pert_x_;
00491 pd_pert_s = pd_pert_s_;
00492 pd_pert_c = pd_pert_c_;
00493 pd_pert_d = pd_pert_d_;
00494 }
00495
00498 static void RegisterOptions(const SmartPtr<RegisteredOptions>& roptions);
00500
00501 private:
00506 SmartPtr<const IteratesVector> curr_;
00507
00510 SmartPtr<const IteratesVector> trial_;
00511
00513 SmartPtr<const SymMatrix> W_;
00514
00517 SmartPtr<const IteratesVector> delta_;
00525 bool have_deltas_;
00527
00533 SmartPtr<const IteratesVector> delta_aff_;
00540 bool have_affine_deltas_;
00542
00544 Index iter_count_;
00545
00547 Number curr_mu_;
00548 bool mu_initialized_;
00549
00551 Number curr_tau_;
00552 bool tau_initialized_;
00553
00556 bool initialize_called_;
00557
00560 bool have_prototypes_;
00561
00568 Number tol_;
00570
00574 bool free_mu_mode_;
00576 bool tiny_step_flag_;
00578
00582 Number info_regu_x_;
00584 Number info_alpha_primal_;
00586 char info_alpha_primal_char_;
00588 Number info_alpha_dual_;
00590 Index info_ls_count_;
00593 bool info_skip_output_;
00595 std::string info_string_;
00597
00599 SmartPtr<IteratesVectorSpace> iterates_space_;
00600
00603 TimingStatistics timing_statistics_;
00604
00606 Number cpu_time_start_;
00607
00610 SmartPtr<IpoptAdditionalData> add_data_;
00611
00615 Number pd_pert_x_;
00616 Number pd_pert_s_;
00617 Number pd_pert_c_;
00618 Number pd_pert_d_;
00620
00630 IpoptData(const IpoptData&);
00631
00633 void operator=(const IpoptData&);
00635
00636 #if COIN_IPOPT_CHECKLEVEL > 0
00637
00641 TaggedObject::Tag debug_curr_tag_;
00642 TaggedObject::Tag debug_trial_tag_;
00643 TaggedObject::Tag debug_delta_tag_;
00644 TaggedObject::Tag debug_delta_aff_tag_;
00645 TaggedObject::Tag debug_curr_tag_sum_;
00646 TaggedObject::Tag debug_trial_tag_sum_;
00647 TaggedObject::Tag debug_delta_tag_sum_;
00648 TaggedObject::Tag debug_delta_aff_tag_sum_;
00650 #endif
00651
00652 };
00653
00654 inline
00655 SmartPtr<const IteratesVector> IpoptData::curr() const
00656 {
00657 DBG_ASSERT(IsNull(curr_) || (curr_->GetTag() == debug_curr_tag_ && curr_->GetTagSum() == debug_curr_tag_sum_) );
00658
00659 return curr_;
00660 }
00661
00662 inline
00663 SmartPtr<const IteratesVector> IpoptData::trial() const
00664 {
00665 DBG_ASSERT(IsNull(trial_) || (trial_->GetTag() == debug_trial_tag_ && trial_->GetTagSum() == debug_trial_tag_sum_) );
00666
00667 return trial_;
00668 }
00669
00670 inline
00671 SmartPtr<const IteratesVector> IpoptData::delta() const
00672 {
00673 DBG_ASSERT(IsNull(delta_) || (delta_->GetTag() == debug_delta_tag_ && delta_->GetTagSum() == debug_delta_tag_sum_) );
00674
00675 return delta_;
00676 }
00677
00678 inline
00679 SmartPtr<const IteratesVector> IpoptData::delta_aff() const
00680 {
00681 DBG_ASSERT(IsNull(delta_aff_) || (delta_aff_->GetTag() == debug_delta_aff_tag_ && delta_aff_->GetTagSum() == debug_delta_aff_tag_sum_) );
00682
00683 return delta_aff_;
00684 }
00685
00686 inline
00687 void IpoptData::CopyTrialToCurrent()
00688 {
00689 curr_ = trial_;
00690 #if COIN_IPOPT_CHECKLEVEL > 0
00691
00692 if (IsValid(curr_)) {
00693 debug_curr_tag_ = curr_->GetTag();
00694 debug_curr_tag_sum_ = curr_->GetTagSum();
00695 }
00696 else {
00697 debug_curr_tag_ = 0;
00698 debug_curr_tag_sum_ = 0;
00699 }
00700 #endif
00701
00702 }
00703
00704 inline
00705 void IpoptData::set_trial(SmartPtr<IteratesVector>& trial)
00706 {
00707 trial_ = ConstPtr(trial);
00708
00709 #if COIN_IPOPT_CHECKLEVEL > 0
00710
00711 DBG_ASSERT(trial_->OwnerSpace() == (VectorSpace*)GetRawPtr(iterates_space_));
00712 if (IsValid(trial)) {
00713 debug_trial_tag_ = trial->GetTag();
00714 debug_trial_tag_sum_ = trial->GetTagSum();
00715 }
00716 else {
00717 debug_trial_tag_ = 0;
00718 debug_trial_tag_sum_ = 0;
00719 }
00720 #endif
00721
00722 trial = NULL;
00723 }
00724
00725 inline
00726 void IpoptData::set_delta(SmartPtr<IteratesVector>& delta)
00727 {
00728 delta_ = ConstPtr(delta);
00729 #if COIN_IPOPT_CHECKLEVEL > 0
00730
00731 if (IsValid(delta)) {
00732 debug_delta_tag_ = delta->GetTag();
00733 debug_delta_tag_sum_ = delta->GetTagSum();
00734 }
00735 else {
00736 debug_delta_tag_ = 0;
00737 debug_delta_tag_sum_ = 0;
00738 }
00739 #endif
00740
00741 delta = NULL;
00742 }
00743
00744 inline
00745 void IpoptData::set_delta(SmartPtr<const IteratesVector>& delta)
00746 {
00747 delta_ = delta;
00748 #if COIN_IPOPT_CHECKLEVEL > 0
00749
00750 if (IsValid(delta)) {
00751 debug_delta_tag_ = delta->GetTag();
00752 debug_delta_tag_sum_ = delta->GetTagSum();
00753 }
00754 else {
00755 debug_delta_tag_ = 0;
00756 debug_delta_tag_sum_ = 0;
00757 }
00758 #endif
00759
00760 delta = NULL;
00761 }
00762
00763 inline
00764 void IpoptData::set_delta_aff(SmartPtr<IteratesVector>& delta_aff)
00765 {
00766 delta_aff_ = ConstPtr(delta_aff);
00767 #if COIN_IPOPT_CHECKLEVEL > 0
00768
00769 if (IsValid(delta_aff)) {
00770 debug_delta_aff_tag_ = delta_aff->GetTag();
00771 debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
00772 }
00773 else {
00774 debug_delta_aff_tag_ = 0;
00775 debug_delta_aff_tag_sum_ = delta_aff->GetTagSum();
00776 }
00777 #endif
00778
00779 delta_aff = NULL;
00780 }
00781
00782 }
00783
00784 #endif