48 #include "MoochoPack_CheckConvergenceIP_Strategy.hpp"
49 #include "MoochoPack_IpState.hpp"
50 #include "MoochoPack_moocho_algo_conversion.hpp"
51 #include "AbstractLinAlgPack_MatrixSymDiagStd.hpp"
52 #include "AbstractLinAlgPack_VectorAuxiliaryOps.hpp"
53 #include "AbstractLinAlgPack_VectorOut.hpp"
54 #include "IterationPack_print_algorithm_step.hpp"
55 #include "Teuchos_dyn_cast.hpp"
57 namespace MoochoPack {
59 CheckConvergenceIP_Strategy::CheckConvergenceIP_Strategy(
60 EOptErrorCheck opt_error_check
61 ,EScaleKKTErrorBy scale_opt_error_by
62 ,EScaleKKTErrorBy scale_feas_error_by
63 ,EScaleKKTErrorBy scale_comp_error_by
64 ,
bool scale_opt_error_by_Gf
67 CheckConvergenceStd_Strategy(
86 bool found_solution =
false;
92 NLPAlgo& algo = rsqp_algo(_algo);
93 NLP& nlp = algo.nlp();
95 EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
96 std::ostream& out = algo.track().journal_out();
99 const value_type &mu_km1 = s.barrier_parameter().get_k(-1);
100 const Vector& x_k = s.x().get_k(0);
101 const VectorMutable& Gf_k = s.Gf().get_k(0);
102 const Vector& rGL_k = s.rGL().get_k(0);
103 const Vector& c_k = s.c().get_k(0);
104 const Vector& vl_k = s.Vl().get_k(0).diag();
105 const Vector& vu_k = s.Vu().get_k(0).diag();
108 value_type& opt_err = s.opt_kkt_err().set_k(0);
109 value_type& feas_err = s.feas_kkt_err().set_k(0);
110 value_type& comp_err = s.comp_kkt_err().set_k(0);
111 value_type& comp_err_mu = s.comp_err_mu().set_k(0);
114 value_type scale_1 = 1 + x_k.norm_1()/x_k.dim();
117 temp->axpy(-1.0, vl_k);
118 temp->axpy(1.0, vu_k);
119 value_type scale_2 = temp->norm_1();
120 scale_2 += vl_k.norm_1() + vu_k.norm_1();
122 *temp = nlp.infinite_bound();
124 *temp = -nlp.infinite_bound();
126 scale_2 = 1 + scale_2/(1+nlp.m()+nlb+nub);
129 opt_err = rGL_k.norm_inf() / scale_2;
132 feas_err = c_k.norm_inf() / scale_1;
135 if( (
int)olevel >= (
int)PRINT_VECTORS )
137 out <<
"\nx =\n" << s.x().get_k(0);
138 out <<
"\nxl =\n" << nlp.xl();
139 out <<
"\nvl =\n" << s.Vl().get_k(0).diag();
140 out <<
"\nxu =\n" << nlp.xu();
141 out <<
"\nvu =\n" << s.Vu().get_k(0).diag();
145 0.0, nlp.infinite_bound(), s.x().get_k(0), nlp.xl(), nlp.xu()
146 ,s.Vl().get_k(0).diag(), s.Vu().get_k(0).diag());
149 mu_km1, nlp.infinite_bound(), s.x().get_k(0), nlp.xl(), nlp.xu()
150 ,s.Vl().get_k(0).diag(), s.Vu().get_k(0).diag());
152 comp_err = comp_err / scale_2;
153 comp_err_mu = comp_err_mu / scale_2;
157 const value_type opt_tol = algo.algo_cntr().opt_tol();
158 const value_type feas_tol = algo.algo_cntr().feas_tol();
159 const value_type comp_tol = algo.algo_cntr().comp_tol();
161 if (opt_err < opt_tol && feas_err < feas_tol && comp_err < comp_tol)
163 found_solution =
true;
166 if(
int(olevel) >=
int(PRINT_ALGORITHM_STEPS) || (
int(olevel) >=
int(PRINT_BASIC_ALGORITHM_INFO) && found_solution) )
169 <<
"\nopt_kkt_err_k = " << opt_err << ( opt_err < opt_tol ?
" < " :
" > " )
170 <<
"opt_tol = " << opt_tol
171 <<
"\nfeas_kkt_err_k = " << feas_err << ( feas_err < feas_tol ?
" < " :
" > " )
172 <<
"feas_tol = " << feas_tol
173 <<
"\ncomp_kkt_err_k = " << comp_err << ( comp_err < comp_tol ?
" < " :
" > " )
174 <<
"comp_tol = " << comp_tol
175 <<
"\ncomp_err_mu = " << comp_err_mu
176 <<
"\nbarrier_parameter_k (mu_km1) = " << mu_km1
177 <<
"comp_tol = " << comp_tol
181 return found_solution;
187 << L <<
"CheckConvergenceIP_Strategy\n"
188 << L <<
" IP_found_solution = CheckConvergedStd_Strategy::Converged(_algo, reportFinalSolution)\n";
193 << L <<
"*** recalculate comp_err\n"
194 << L <<
"comp_err_k = 0.0"
195 << L <<
"for all i = 1 to n\n"
196 << L <<
" comp_err_k = max( comp_err_k, vl_k(i)*(x_k(i)-xl_k(i))-mu_km1, vu_k(i)*(xu_k(i)-x_k(i))-mu_k )\n"
198 << L <<
"if IP_found_solution then\n"
199 << L <<
" IP_found_solution = false\n"
200 << L <<
" if (comp_err_k < comp_tol && mu_k < comp_tol) then\n"
201 << L <<
" IP_found_solution = true\n"
204 << L <<
"return IP_found_solution\n";
state_ptr_t & get_state()
value_type IP_comp_err_with_mu(const value_type mu, const value_type inf_bound, const Vector &x, const Vector &xl, const Vector &xu, const Vector &vl, const Vector &vu)
T_To & dyn_cast(T_From &from)
rSQP Algorithm control class.
virtual bool Converged(Algorithm &_algo)
virtual void print_step(const Algorithm &_algo, std::ostream &out, const std::string &L) const
virtual void print_step(const Algorithm &_algo, std::ostream &out, const std::string &L) const
size_type num_bounded(const Vector &xl, const Vector &xu, value_type inf_bound)