46 #include "MoochoPack_MoochoTrackerStatsStd.hpp"
47 #include "MoochoPack_NLPAlgoState.hpp"
48 #include "MoochoPack_moocho_algo_conversion.hpp"
49 #include "NLPInterfacePack_NLPFirstOrder.hpp"
50 #include "AbstractLinAlgPack_Vector.hpp"
51 #include "Teuchos_dyn_cast.hpp"
56 T my_max(
const T& v1,
const T& v2 ) {
return v1 > v2 ? v1 : v2; }
59 namespace MoochoPack {
65 using std::setprecision;
67 MoochoTrackerStatsStd::MoochoTrackerStatsStd(
68 const ostream_ptr_t& o,
const ostream_ptr_t& journal_out
70 :AlgorithmTracker(journal_out)
95 const NLPAlgo &algo = rsqp_algo(p_algo);
100 ( quasi_newton_stats_.exists_in(s) && quasi_newton_stats_(s).updated_k(0)
101 ? &quasi_newton_stats_(s).get_k(0)
103 if( quasi_newt_stats ) {
105 if( updated == QuasiNewtonStats::DAMPENED_UPDATED || updated == QuasiNewtonStats::UPDATED )
111 , EAlgoReturn algo_return )
const
115 const NLPAlgo &algo = rsqp_algo(p_algo);
117 const NLPObjGrad &nlp =
dyn_cast<
const NLPObjGrad>(algo.nlp());
118 const NLPFirstOrder *nlp_foi =
dynamic_cast<const NLPFirstOrder*
>(&nlp);
123 std::ostream& o = this->o();
136 ( quasi_newton_stats_.exists_in(s) && quasi_newton_stats_(s).updated_k(0)
137 ? &quasi_newton_stats_(s).get_k(0)
139 if( quasi_newt_stats ) {
141 if( updated == QuasiNewtonStats::DAMPENED_UPDATED || updated == QuasiNewtonStats::UPDATED )
146 o << left << setw(stat_w) <<
"status" <<
"= "
147 << right << setw(val_w);
148 switch( algo_return ) {
149 case IterationPack::TERMINATE_TRUE:
152 case IterationPack::TERMINATE_FALSE:
155 case IterationPack::MAX_ITER_EXCEEDED:
158 case IterationPack::MAX_RUN_TIME_EXCEEDED:
161 case IterationPack::INTERRUPTED_TERMINATE_TRUE:
162 o <<
"interrupted_solved";
164 case IterationPack::INTERRUPTED_TERMINATE_FALSE:
165 o <<
"interrupted_not_solved";
170 o <<
"; # solved, except, max_iter, max_run_time\n";
172 o << left << setw(stat_w) <<
"niter" <<
"= "
173 << right << setw(val_w) << s.
k()
174 <<
"; # Number of rSQP iterations (plus 1?)\n";
176 o << left << setw(stat_w) <<
"nfunc" <<
"= "
177 << right << setw(val_w) << my_max(nlp.num_f_evals(),(m? nlp.num_c_evals():0) )
178 <<
"; # max( number f(x) evals, number c(x) evals )\n";
180 o << left << setw(stat_w) <<
"ngrad" <<
"= "
181 << right << setw(val_w) << my_max(nlp.num_Gf_evals(),(m?(nlp_foi?nlp_foi->num_Gc_evals():s.
k()+1):0))
182 <<
"; # max( number Gf(x) evals, number Gc(x) evals )\n";
184 o << left << setw(stat_w) <<
"CPU" <<
"= "
185 << right << setw(val_w) << timer_.
read()
186 <<
"; # Number of CPU seconds total\n";
188 o << left << setw(stat_w) <<
"obj_func" <<
"= "
189 << right << setw(val_w);
190 if(s.f().updated_k(0))
194 o <<
"; # Objective function value f(x) at final point\n";
196 o << left << setw(stat_w) <<
"feas_kkt_err" <<
"= "
197 << right << setw(val_w);
198 if(s.feas_kkt_err().updated_k(0))
199 o << s.feas_kkt_err().get_k(0);
200 else if(s.c().updated_k(0))
201 o << s.c().get_k(0).norm_inf();
204 o <<
"; # Feasibility error at final point (scaled ||c(x)||inf, feas_err_k)\n";
206 o << left << setw(stat_w) <<
"opt_kkt_err" <<
"= "
207 << right << setw(val_w);
208 if(s.opt_kkt_err().updated_k(0))
209 o << s.opt_kkt_err().get_k(0);
210 else if(s.rGL().updated_k(0))
211 o << s.rGL().get_k(0).norm_inf();
212 else if(s.rGL().updated_k(-1))
213 o << s.rGL().get_k(-1).norm_inf();
216 o <<
"; # Optimality error at final point (scaled ||rGL||inf, opt_err_k)\n";
218 o << left << setw(stat_w) <<
"nact" <<
"= "
219 << right << setw(val_w);
220 if(s.nu().updated_k(0))
221 o << s.nu().get_k(0).nz();
222 else if(s.nu().updated_k(-1))
223 o << s.nu().get_k(-1).nz();
226 o <<
"; # Number of total active constraints at the final point\n";
228 const IterQuantityAccess<index_type> &num_basis = s.num_basis();
229 const int lu_k = num_basis.last_updated();
230 o << left << setw(stat_w) <<
"nbasis_change" <<
"= "
231 << right << setw(val_w) << ( lu_k != IterQuantity::NONE_UPDATED
232 ? num_basis.get_k(lu_k)
234 <<
"; # Number of basis changes\n";
236 o << left << setw(stat_w) <<
"nquasi_newton" <<
"= "
237 << right << setw(val_w) << num_QN_updates_
238 <<
"; # Number of quasi-newton updates\n";
const ostream_ptr_t & get_output_stream() const
Get the output stream for statistics outputting.
Class for storing statistics about the Quasi-Newton updating.
T_To & dyn_cast(T_From &from)
void initialize()
Restarts the timer.
rSQP Algorithm control class.
EUpdate
Set to this value if a statistic is not known.
void output_final(const Algorithm &algo, EAlgoReturn algo_return) const
Reduced space SQP state encapsulation interface.
void set_output_stream(const ostream_ptr_t &o)
void output_iteration(const Algorithm &algo) const
NLPAlgoState & rsqp_state()
<<std aggr>="">> members for algo_cntr
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)