00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __IPIPOPTCALCULATEDQUANTITIES_HPP__
00010 #define __IPIPOPTCALCULATEDQUANTITIES_HPP__
00011
00012 #include "IpIpoptNLP.hpp"
00013 #include "IpIpoptData.hpp"
00014
00015 namespace Ipopt
00016 {
00017
00019 enum ENormType {
00020 NORM_1=0,
00021 NORM_2,
00022 NORM_MAX
00023 };
00024
00030 class IpoptAdditionalCq : public ReferencedObject
00031 {
00032 public:
00036 IpoptAdditionalCq()
00037 {}
00038
00040 virtual ~IpoptAdditionalCq()
00041 {}
00043
00047 virtual bool Initialize(const Journalist& jnlst,
00048 const OptionsList& options,
00049 const std::string& prefix) = 0;
00050
00051 private:
00061 IpoptAdditionalCq(const IpoptAdditionalCq&);
00062
00064 void operator=(const IpoptAdditionalCq&);
00066 };
00067
00071 class IpoptCalculatedQuantities : public ReferencedObject
00072 {
00073 public:
00074
00078 IpoptCalculatedQuantities(const SmartPtr<IpoptNLP>& ip_nlp,
00079 const SmartPtr<IpoptData>& ip_data);
00081 virtual ~IpoptCalculatedQuantities();
00083
00086 void SetAddCq(SmartPtr<IpoptAdditionalCq> add_cq)
00087 {
00088 DBG_ASSERT(!HaveAddCq());
00089 add_cq_ = add_cq;
00090 }
00091
00094 bool HaveAddCq()
00095 {
00096 return IsValid(add_cq_);
00097 }
00098
00102 bool Initialize(const Journalist& jnlst,
00103 const OptionsList& options,
00104 const std::string& prefix);
00105
00109 SmartPtr<const Vector> curr_slack_x_L();
00111 SmartPtr<const Vector> curr_slack_x_U();
00113 SmartPtr<const Vector> curr_slack_s_L();
00115 SmartPtr<const Vector> curr_slack_s_U();
00117 SmartPtr<const Vector> trial_slack_x_L();
00119 SmartPtr<const Vector> trial_slack_x_U();
00121 SmartPtr<const Vector> trial_slack_s_L();
00123 SmartPtr<const Vector> trial_slack_s_U();
00125 Index AdjustedTrialSlacks();
00127 void ResetAdjustedTrialSlacks();
00129
00133 Number curr_f();
00135 Number unscaled_curr_f();
00137 Number trial_f();
00139 Number unscaled_trial_f();
00141 SmartPtr<const Vector> curr_grad_f();
00143 SmartPtr<const Vector> trial_grad_f();
00145
00151 Number curr_barrier_obj();
00155 Number trial_barrier_obj();
00156
00159 SmartPtr<const Vector> curr_grad_barrier_obj_x();
00162 SmartPtr<const Vector> curr_grad_barrier_obj_s();
00163
00166 SmartPtr<const Vector> grad_kappa_times_damping_x();
00169 SmartPtr<const Vector> grad_kappa_times_damping_s();
00171
00175 SmartPtr<const Vector> curr_c();
00177 SmartPtr<const Vector> unscaled_curr_c();
00179 SmartPtr<const Vector> trial_c();
00181 SmartPtr<const Vector> curr_d();
00183 SmartPtr<const Vector> unscaled_curr_d();
00185 SmartPtr<const Vector> trial_d();
00187 SmartPtr<const Vector> curr_d_minus_s();
00189 SmartPtr<const Vector> trial_d_minus_s();
00191 SmartPtr<const Matrix> curr_jac_c();
00193 SmartPtr<const Matrix> trial_jac_c();
00195 SmartPtr<const Matrix> curr_jac_d();
00197 SmartPtr<const Matrix> trial_jac_d();
00200 SmartPtr<const Vector> curr_jac_cT_times_vec(const Vector& vec);
00203 SmartPtr<const Vector> trial_jac_cT_times_vec(const Vector& vec);
00206 SmartPtr<const Vector> curr_jac_dT_times_vec(const Vector& vec);
00209 SmartPtr<const Vector> trial_jac_dT_times_vec(const Vector& vec);
00212 SmartPtr<const Vector> curr_jac_cT_times_curr_y_c();
00215 SmartPtr<const Vector> trial_jac_cT_times_trial_y_c();
00218 SmartPtr<const Vector> curr_jac_dT_times_curr_y_d();
00221 SmartPtr<const Vector> trial_jac_dT_times_trial_y_d();
00224 SmartPtr<const Vector> curr_jac_c_times_vec(const Vector& vec);
00227 SmartPtr<const Vector> curr_jac_d_times_vec(const Vector& vec);
00231 Number curr_constraint_violation();
00235 Number trial_constraint_violation();
00239 Number curr_nlp_constraint_violation(ENormType NormType);
00243 Number unscaled_curr_nlp_constraint_violation(ENormType NormType);
00245
00249 SmartPtr<const SymMatrix> curr_exact_hessian();
00251
00255 SmartPtr<const Vector> curr_grad_lag_x();
00257 SmartPtr<const Vector> trial_grad_lag_x();
00259 SmartPtr<const Vector> curr_grad_lag_s();
00261 SmartPtr<const Vector> trial_grad_lag_s();
00264 SmartPtr<const Vector> curr_grad_lag_with_damping_x();
00267 SmartPtr<const Vector> curr_grad_lag_with_damping_s();
00269 SmartPtr<const Vector> curr_compl_x_L();
00271 SmartPtr<const Vector> curr_compl_x_U();
00273 SmartPtr<const Vector> curr_compl_s_L();
00275 SmartPtr<const Vector> curr_compl_s_U();
00277 SmartPtr<const Vector> trial_compl_x_L();
00279 SmartPtr<const Vector> trial_compl_x_U();
00281 SmartPtr<const Vector> trial_compl_s_L();
00283 SmartPtr<const Vector> trial_compl_s_U();
00285 SmartPtr<const Vector> curr_relaxed_compl_x_L();
00287 SmartPtr<const Vector> curr_relaxed_compl_x_U();
00289 SmartPtr<const Vector> curr_relaxed_compl_s_L();
00291 SmartPtr<const Vector> curr_relaxed_compl_s_U();
00292
00294 Number curr_primal_infeasibility(ENormType NormType);
00296 Number trial_primal_infeasibility(ENormType NormType);
00297
00299 Number curr_dual_infeasibility(ENormType NormType);
00301 Number trial_dual_infeasibility(ENormType NormType);
00303 Number unscaled_curr_dual_infeasibility(ENormType NormType);
00304
00307 Number curr_complementarity(Number mu, ENormType NormType);
00310 Number trial_complementarity(Number mu, ENormType NormType);
00313 Number unscaled_curr_complementarity(Number mu, ENormType NormType);
00314
00316 Number CalcCentralityMeasure(const Vector& compl_x_L,
00317 const Vector& compl_x_U,
00318 const Vector& compl_s_L,
00319 const Vector& compl_s_U);
00321 Number curr_centrality_measure();
00322
00327 Number curr_nlp_error();
00332 Number unscaled_curr_nlp_error();
00333
00336 Number curr_barrier_error();
00337
00344 Number curr_primal_dual_system_error(Number mu);
00351 Number trial_primal_dual_system_error(Number mu);
00353
00358 Number primal_frac_to_the_bound(Number tau,
00359 const Vector& delta_x,
00360 const Vector& delta_s);
00363 Number curr_primal_frac_to_the_bound(Number tau);
00366 Number dual_frac_to_the_bound(Number tau,
00367 const Vector& delta_z_L,
00368 const Vector& delta_z_U,
00369 const Vector& delta_v_L,
00370 const Vector& delta_v_U);
00373 Number uncached_dual_frac_to_the_bound(Number tau,
00374 const Vector& delta_z_L,
00375 const Vector& delta_z_U,
00376 const Vector& delta_v_L,
00377 const Vector& delta_v_U);
00380 Number curr_dual_frac_to_the_bound(Number tau);
00388 Number uncached_slack_frac_to_the_bound(Number tau,
00389 const Vector& delta_x_L,
00390 const Vector& delta_x_U,
00391 const Vector& delta_s_L,
00392 const Vector& delta_s_U);
00394
00397 SmartPtr<const Vector> curr_sigma_x();
00398 SmartPtr<const Vector> curr_sigma_s();
00400
00402 Number curr_avrg_compl();
00404 Number trial_avrg_compl();
00405
00408 Number curr_gradBarrTDelta();
00409
00411 Number
00412 CalcNormOfType(ENormType NormType,
00413 std::vector<SmartPtr<const Vector> > vecs);
00414
00416 Number
00417 CalcNormOfType(ENormType NormType,
00418 const Vector& vec1, const Vector& vec2);
00419
00421 ENormType constr_viol_normtype() const
00422 {
00423 return constr_viol_normtype_;
00424 }
00425
00427 bool IsSquareProblem() const;
00428
00431 SmartPtr<IpoptNLP>& GetIpoptNLP()
00432 {
00433 return ip_nlp_;
00434 }
00435
00436 IpoptAdditionalCq& AdditionalCq()
00437 {
00438 DBG_ASSERT(IsValid(add_cq_));
00439 return *add_cq_;
00440 }
00441
00445 static void RegisterOptions(SmartPtr<RegisteredOptions> roptions);
00447
00448 private:
00458 IpoptCalculatedQuantities();
00459
00461 IpoptCalculatedQuantities(const IpoptCalculatedQuantities&);
00462
00464 void operator=(const IpoptCalculatedQuantities&);
00466
00470 SmartPtr<IpoptNLP> ip_nlp_;
00472 SmartPtr<IpoptData> ip_data_;
00474 SmartPtr<IpoptAdditionalCq> add_cq_;
00476
00483 Number s_max_;
00486 Number kappa_d_;
00488 Number slack_move_;
00490 ENormType constr_viol_normtype_;
00493 bool warm_start_same_structure_;
00495
00498 CachedResults< SmartPtr<Vector> > curr_slack_x_L_cache_;
00499 CachedResults< SmartPtr<Vector> > curr_slack_x_U_cache_;
00500 CachedResults< SmartPtr<Vector> > curr_slack_s_L_cache_;
00501 CachedResults< SmartPtr<Vector> > curr_slack_s_U_cache_;
00502 CachedResults< SmartPtr<Vector> > trial_slack_x_L_cache_;
00503 CachedResults< SmartPtr<Vector> > trial_slack_x_U_cache_;
00504 CachedResults< SmartPtr<Vector> > trial_slack_s_L_cache_;
00505 CachedResults< SmartPtr<Vector> > trial_slack_s_U_cache_;
00506 Index num_adjusted_slack_x_L_;
00507 Index num_adjusted_slack_x_U_;
00508 Index num_adjusted_slack_s_L_;
00509 Index num_adjusted_slack_s_U_;
00511
00514 CachedResults<Number> curr_f_cache_;
00515 CachedResults<Number> trial_f_cache_;
00516 CachedResults< SmartPtr<const Vector> > curr_grad_f_cache_;
00517 CachedResults< SmartPtr<const Vector> > trial_grad_f_cache_;
00519
00522 CachedResults<Number> curr_barrier_obj_cache_;
00523 CachedResults<Number> trial_barrier_obj_cache_;
00524 CachedResults< SmartPtr<const Vector> > curr_grad_barrier_obj_x_cache_;
00525 CachedResults< SmartPtr<const Vector> > curr_grad_barrier_obj_s_cache_;
00526 CachedResults< SmartPtr<const Vector> > grad_kappa_times_damping_x_cache_;
00527 CachedResults< SmartPtr<const Vector> > grad_kappa_times_damping_s_cache_;
00529
00532 CachedResults< SmartPtr<const Vector> > curr_c_cache_;
00533 CachedResults< SmartPtr<const Vector> > trial_c_cache_;
00534 CachedResults< SmartPtr<const Vector> > curr_d_cache_;
00535 CachedResults< SmartPtr<const Vector> > trial_d_cache_;
00536 CachedResults< SmartPtr<const Vector> > curr_d_minus_s_cache_;
00537 CachedResults< SmartPtr<const Vector> > trial_d_minus_s_cache_;
00538 CachedResults< SmartPtr<const Matrix> > curr_jac_c_cache_;
00539 CachedResults< SmartPtr<const Matrix> > trial_jac_c_cache_;
00540 CachedResults< SmartPtr<const Matrix> > curr_jac_d_cache_;
00541 CachedResults< SmartPtr<const Matrix> > trial_jac_d_cache_;
00542 CachedResults< SmartPtr<const Vector> > curr_jac_cT_times_vec_cache_;
00543 CachedResults< SmartPtr<const Vector> > trial_jac_cT_times_vec_cache_;
00544 CachedResults< SmartPtr<const Vector> > curr_jac_dT_times_vec_cache_;
00545 CachedResults< SmartPtr<const Vector> > trial_jac_dT_times_vec_cache_;
00546 CachedResults< SmartPtr<const Vector> > curr_jac_c_times_vec_cache_;
00547 CachedResults< SmartPtr<const Vector> > curr_jac_d_times_vec_cache_;
00548 CachedResults<Number> curr_constraint_violation_cache_;
00549 CachedResults<Number> trial_constraint_violation_cache_;
00550 CachedResults<Number> curr_nlp_constraint_violation_cache_;
00551 CachedResults<Number> unscaled_curr_nlp_constraint_violation_cache_;
00553
00555 CachedResults< SmartPtr<const SymMatrix> > curr_exact_hessian_cache_;
00556
00559 CachedResults< SmartPtr<const Vector> > curr_grad_lag_x_cache_;
00560 CachedResults< SmartPtr<const Vector> > trial_grad_lag_x_cache_;
00561 CachedResults< SmartPtr<const Vector> > curr_grad_lag_s_cache_;
00562 CachedResults< SmartPtr<const Vector> > trial_grad_lag_s_cache_;
00563 CachedResults< SmartPtr<const Vector> > curr_grad_lag_with_damping_x_cache_;
00564 CachedResults< SmartPtr<const Vector> > curr_grad_lag_with_damping_s_cache_;
00565 CachedResults< SmartPtr<const Vector> > curr_compl_x_L_cache_;
00566 CachedResults< SmartPtr<const Vector> > curr_compl_x_U_cache_;
00567 CachedResults< SmartPtr<const Vector> > curr_compl_s_L_cache_;
00568 CachedResults< SmartPtr<const Vector> > curr_compl_s_U_cache_;
00569 CachedResults< SmartPtr<const Vector> > trial_compl_x_L_cache_;
00570 CachedResults< SmartPtr<const Vector> > trial_compl_x_U_cache_;
00571 CachedResults< SmartPtr<const Vector> > trial_compl_s_L_cache_;
00572 CachedResults< SmartPtr<const Vector> > trial_compl_s_U_cache_;
00573 CachedResults< SmartPtr<const Vector> > curr_relaxed_compl_x_L_cache_;
00574 CachedResults< SmartPtr<const Vector> > curr_relaxed_compl_x_U_cache_;
00575 CachedResults< SmartPtr<const Vector> > curr_relaxed_compl_s_L_cache_;
00576 CachedResults< SmartPtr<const Vector> > curr_relaxed_compl_s_U_cache_;
00577 CachedResults<Number> curr_primal_infeasibility_cache_;
00578 CachedResults<Number> trial_primal_infeasibility_cache_;
00579 CachedResults<Number> curr_dual_infeasibility_cache_;
00580 CachedResults<Number> trial_dual_infeasibility_cache_;
00581 CachedResults<Number> unscaled_curr_dual_infeasibility_cache_;
00582 CachedResults<Number> curr_complementarity_cache_;
00583 CachedResults<Number> trial_complementarity_cache_;
00584 CachedResults<Number> curr_centrality_measure_cache_;
00585 CachedResults<Number> curr_nlp_error_cache_;
00586 CachedResults<Number> unscaled_curr_nlp_error_cache_;
00587 CachedResults<Number> curr_barrier_error_cache_;
00588 CachedResults<Number> curr_primal_dual_system_error_cache_;
00589 CachedResults<Number> trial_primal_dual_system_error_cache_;
00591
00594 CachedResults<Number> primal_frac_to_the_bound_cache_;
00595 CachedResults<Number> dual_frac_to_the_bound_cache_;
00597
00600 CachedResults< SmartPtr<const Vector> > curr_sigma_x_cache_;
00601 CachedResults< SmartPtr<const Vector> > curr_sigma_s_cache_;
00603
00605 CachedResults<Number> curr_avrg_compl_cache_;
00607 CachedResults<Number> trial_avrg_compl_cache_;
00608
00610 CachedResults<Number> curr_gradBarrTDelta_cache_;
00611
00617 SmartPtr<Vector> dampind_x_L_;
00620 SmartPtr<Vector> dampind_x_U_;
00623 SmartPtr<Vector> dampind_s_L_;
00626 SmartPtr<Vector> dampind_s_U_;
00628
00633 SmartPtr<Vector> tmp_x_;
00634 SmartPtr<Vector> tmp_s_;
00635 SmartPtr<Vector> tmp_c_;
00636 SmartPtr<Vector> tmp_d_;
00637 SmartPtr<Vector> tmp_x_L_;
00638 SmartPtr<Vector> tmp_x_U_;
00639 SmartPtr<Vector> tmp_s_L_;
00640 SmartPtr<Vector> tmp_s_U_;
00641
00643 Vector& Tmp_x();
00644 Vector& Tmp_s();
00645 Vector& Tmp_c();
00646 Vector& Tmp_d();
00647 Vector& Tmp_x_L();
00648 Vector& Tmp_x_U();
00649 Vector& Tmp_s_L();
00650 Vector& Tmp_s_U();
00652
00655 bool initialize_called_;
00656
00662 SmartPtr<Vector> CalcSlack_L(const Matrix& P,
00663 const Vector& x,
00664 const Vector& x_bound);
00668 SmartPtr<Vector> CalcSlack_U(const Matrix& P,
00669 const Vector& x,
00670 const Vector& x_bound);
00674 Number CalcBarrierTerm(Number mu,
00675 const Vector& slack_x_L,
00676 const Vector& slack_x_U,
00677 const Vector& slack_s_L,
00678 const Vector& slack_s_U);
00679
00681 SmartPtr<const Vector> CalcCompl(const Vector& slack,
00682 const Vector& mult);
00683
00685 Number CalcFracToBound(const Vector& slack_L,
00686 Vector& tmp_L,
00687 const Matrix& P_L,
00688 const Vector& slack_U,
00689 Vector& tmp_U,
00690 const Matrix& P_U,
00691 const Vector& delta,
00692 Number tau);
00693
00695 void ComputeOptimalityErrorScaling(const Vector& y_c, const Vector& y_d,
00696 const Vector& z_L, const Vector& z_U,
00697 const Vector& v_L, const Vector& v_U,
00698 Number s_max,
00699 Number& s_d, Number& s_c);
00700
00704 Index CalculateSafeSlack(SmartPtr<Vector>& slack,
00705 const SmartPtr<const Vector>& bound,
00706 const SmartPtr<const Vector>& curr_point,
00707 const SmartPtr<const Vector>& multiplier);
00708
00714 void ComputeDampingIndicators(SmartPtr<const Vector>& dampind_x_L,
00715 SmartPtr<const Vector>& dampind_x_U,
00716 SmartPtr<const Vector>& dampind_s_L,
00717 SmartPtr<const Vector>& dampind_s_U);
00718
00725 bool in_restoration_phase();
00726
00728 };
00729
00730 }
00731
00732 #endif