46 #include "MoochoPack_MoochoTrackerConsoleStd.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"
53 namespace MoochoPack {
59 using std::setprecision;
62 int MoochoTrackerConsoleStd::w_i2_ = 2;
63 char MoochoTrackerConsoleStd::ul_i2_[] =
"--";
64 int MoochoTrackerConsoleStd::w_i4_ = 4;
65 char MoochoTrackerConsoleStd::ul_i4_[] =
"----";
66 int MoochoTrackerConsoleStd::p2_ = 1;
67 int MoochoTrackerConsoleStd::w_p2_ = 8;
68 char MoochoTrackerConsoleStd::ul_p2_[] =
"--------";
69 int MoochoTrackerConsoleStd::p3_ = 2;
70 int MoochoTrackerConsoleStd::w_p3_ = 9;
71 char MoochoTrackerConsoleStd::ul_p3_[] =
"---------";
73 MoochoTrackerConsoleStd::MoochoTrackerConsoleStd(
74 const ostream_ptr_t& o
75 ,
const ostream_ptr_t& journal_out
77 :AlgorithmTracker(journal_out)
79 ,printed_lines_(NUM_PRINT_LINES)
101 const NLPAlgo &algo = rsqp_algo(p_algo);
103 const NLP &nlp = algo.nlp();
109 nb = nlp.num_bounded_x();
113 printed_lines_ = NUM_PRINT_LINES;
117 if(printed_lines_ == NUM_PRINT_LINES) {
127 ( quasi_newton_stats_.exists_in(s) && quasi_newton_stats_(s).updated_k(0)
128 ? &quasi_newton_stats_(s).get_k(0)
131 std::ostream& o = this->o();
134 o <<
" " << right << setw(w_i4_) << s.
k();
136 if( s.f().updated_k(0) )
137 o <<
" " << setprecision(p3_) << right << setw(w_p3_) << s.f().get_k(0);
139 o <<
" " << right << setw(w_p3_) <<
"-";
141 if( m && s.feas_kkt_err().updated_k(0) )
142 o <<
" " << setprecision(p3_) << right << setw(w_p3_) << s.feas_kkt_err().get_k(0);
144 o <<
" " << right << setw(w_p3_) <<
"-";
146 if( s.opt_kkt_err().updated_k(0) )
147 o <<
" " << setprecision(p3_) << right << setw(w_p3_) << s.opt_kkt_err().get_k(0);
149 o <<
" " << right << setw(w_p3_) <<
"-";
151 if( quasi_newt_stats ) {
152 o <<
" " << right << setw(w_i2_);
153 switch( quasi_newt_stats->
updated() ) {
154 case QuasiNewtonStats::UNKNOWN:
157 case QuasiNewtonStats:: REINITIALIZED:
160 case QuasiNewtonStats::DAMPENED_UPDATED:
163 case QuasiNewtonStats::UPDATED:
166 case QuasiNewtonStats::SKIPED:
169 case QuasiNewtonStats::INDEF_SKIPED:
177 o <<
" " << right << setw(w_i2_) <<
"-";
181 if( s.nu().updated_k(0) )
182 o <<
" " << right << setw(w_i4_) << s.nu().get_k(0).nz();
184 o <<
" " << right << setw(w_i4_) <<
"-";
187 if( m && s.Ypy().updated_k(0) )
188 o <<
" "<< setprecision(p2_) << right << setw(w_p2_) << s.Ypy().get_k(0).norm_2();
190 o <<
" " << right << setw(w_p2_) <<
"-";
192 if( s.Zpz().updated_k(0) )
193 o <<
" " << setprecision(p2_) << right << setw(w_p2_) << s.Zpz().get_k(0).norm_2();
195 o <<
" " << right << setw(w_p2_) <<
"-";
197 if( s.d().updated_k(0) )
198 o <<
" " << setprecision(p2_) << right << setw(w_p2_) << s.d().get_k(0).norm_inf();
200 o <<
" " << right << setw(w_p2_) <<
"-";
202 if( s.alpha().updated_k(0) )
203 o <<
" " << setprecision(p2_) << right << setw(w_p2_) << s.alpha().get_k(0);
205 o <<
" " << right << setw(w_p2_) <<
"-";
207 o <<
" " << setprecision(7) << right << setw(w_p3_) << timer_.
read();
215 , EAlgoReturn algo_return )
const
219 const NLPAlgo &algo = rsqp_algo(p_algo);
221 const NLPObjGrad &nlp =
dyn_cast<
const NLPObjGrad>(algo.nlp());
222 const NLPFirstOrder *nlp_foi =
dynamic_cast<const NLPFirstOrder*
>(&nlp);
228 nb = nlp.num_bounded_x();
230 std::ostream& o = this->o();
239 <<
" " << right << ul_i4_
240 <<
" " << right << ul_p3_
241 <<
" " << right << ul_p3_
242 <<
" " << right << ul_p3_
243 <<
" " << right << ul_i2_
246 o <<
" " << right << ul_i4_;
255 ( quasi_newton_stats_.exists_in(s) && quasi_newton_stats_(s).updated_k(0)
256 ? &quasi_newton_stats_(s).get_k(0)
260 o <<
" " << right << setw(w_i4_) << s.
k();
262 if( s.f().updated_k(0) )
263 o <<
" " << setprecision(p3_) << right << setw(w_p3_) << s.f().get_k(0);
265 o <<
" " << right << setw(w_p3_) <<
"-";
267 if( m && s.feas_kkt_err().updated_k(0) )
268 o <<
" " << setprecision(p3_) << right << setw(w_p3_) << s.feas_kkt_err().get_k(0);
270 o <<
" " << right << setw(w_p3_) <<
"-";
272 if( s.opt_kkt_err().updated_k(0) )
273 o <<
" " << setprecision(p3_) << right << setw(w_p3_) << s.opt_kkt_err().get_k(0);
275 o <<
" " << right << setw(w_p3_) <<
"-";
277 if( quasi_newt_stats ) {
278 o <<
" " << right << setw(w_i2_);
279 switch( quasi_newt_stats->
updated() ) {
280 case QuasiNewtonStats::UNKNOWN:
283 case QuasiNewtonStats:: REINITIALIZED:
286 case QuasiNewtonStats::DAMPENED_UPDATED:
289 case QuasiNewtonStats::UPDATED:
292 case QuasiNewtonStats::SKIPED:
295 case QuasiNewtonStats::INDEF_SKIPED:
303 o <<
" " << right << setw(w_i2_) <<
"-";
307 if( s.nu().updated_k(0) )
308 o <<
" " << right << setw(w_i4_) << s.nu().get_k(0).nz();
310 o <<
" " << right << setw(w_i4_) <<
"-";
313 if( m && s.Ypy().updated_k(0) )
314 o <<
" "<< setprecision(p2_) << right << setw(w_p2_) << s.Ypy().get_k(0).norm_2();
316 o <<
" " << right << setw(w_p2_) <<
"-";
318 if( s.Zpz().updated_k(0) )
319 o <<
" " << setprecision(p2_) << right << setw(w_p2_) << s.Zpz().get_k(0).norm_2();
321 o <<
" " << right << setw(w_p2_) <<
"-";
323 if( s.d().updated_k(0) )
324 o <<
" " << setprecision(p2_) << right << setw(w_p2_) << s.d().get_k(0).norm_inf();
326 o <<
" " << right << setw(w_p2_) <<
"-";
328 if( s.alpha().updated_k(0) )
329 o <<
" " << setprecision(p2_) << right << setw(w_p2_) << s.alpha().get_k(0);
331 o <<
" " << right << setw(w_p2_) <<
"-";
333 o <<
" " << setprecision(7) << right << setw(w_p3_) << timer_.
read();
338 o << setprecision(5) <<
"\nTotal time = " << timer_.
read() <<
" sec\n";
340 switch( algo_return ) {
341 case IterationPack::TERMINATE_TRUE:
342 o <<
"\nJackpot! You have found the solution!!!!!!\n";
344 case IterationPack::TERMINATE_FALSE:
345 o <<
"\nOops! Not the solution. Some error has occured!\n";
347 case IterationPack::MAX_ITER_EXCEEDED:
348 o <<
"\nOops! Not the solution. Maximum number of SQP iteration exceeded!\n";
350 case IterationPack::MAX_RUN_TIME_EXCEEDED:
351 o <<
"\nOops! Not the solution. Maximum runtime exceeded!\n";
353 case IterationPack::INTERRUPTED_TERMINATE_TRUE:
354 o <<
"\nJackpot? The user terminated the algorithm but said to return optimal!!!!!!\n";
356 case IterationPack::INTERRUPTED_TERMINATE_FALSE:
357 o <<
"\nOops! Not the solution. The user terminated the algorithm and said to return non-optimal!\n";
363 o <<
"\nNumber of function evaluations:\n"
364 <<
"-------------------------------\n"
365 <<
"f(x) : " << nlp.num_f_evals() << endl
366 <<
"c(x) : " << ( m ? nlp.num_c_evals() : 0 ) << endl
367 <<
"Gf(x) : " << nlp.num_Gf_evals() << endl
371 o << nlp_foi->num_Gc_evals();
384 std::ostream& o = this->o();
386 NLPAlgoState::space_c_ptr_t
387 space_c = s.get_space_c();
389 o <<
"\n\n********************************\n"
390 <<
"*** Start of rSQP Iterations ***\n"
391 <<
"n = " << s.space_x().dim()
392 <<
", m = " << ( space_c.get() ? space_c->dim() : 0 )
396 if( s.Gc().updated_k(0) )
397 o << s.Gc().get_k(0).nz() << endl;
405 catch(
const AlgorithmState::DoesNotExist& ) {
408 if( algo.nlp().scale_f() != 1.0 ) {
409 o <<
"f(x) is scaled by : " << algo.nlp().scale_f() << endl;
416 std::ostream& o = this->o();
418 const NLP &nlp = algo.nlp();
421 nb = nlp.num_bounded_x();
425 <<
" " << left << setw(w_i4_) <<
"k"
426 <<
" " << left << setw(w_p3_) <<
"f"
427 <<
" " << left << setw(w_p3_) <<
"||c||s"
428 <<
" " << left << setw(w_p3_) <<
"||rGL||s"
429 <<
" " << left << setw(w_i2_) <<
"QN";
431 o <<
" " << left << setw(w_i4_) <<
"#act";
433 <<
" " << left << setw(w_p2_) <<
"||Ypy||2"
434 <<
" " << left << setw(w_p2_) <<
"||Zpz||2"
435 <<
" " << left << setw(w_p2_) <<
"||d||inf"
436 <<
" " << left << setw(w_p2_) <<
"alpha"
437 <<
" " << left << setw(w_p3_) <<
"time(sec)"
439 <<
" " << right << ul_i4_
440 <<
" " << right << ul_p3_
441 <<
" " << right << ul_p3_
442 <<
" " << right << ul_p3_
443 <<
" " << right << ul_i2_;
445 o <<
" " << right << ul_i4_;
447 <<
" " << right << ul_p2_
448 <<
" " << right << ul_p2_
449 <<
" " << right << ul_p2_
450 <<
" " << right << ul_p2_
451 <<
" " << right << ul_p3_
void initialize()
Restarts the timer.
void output_iteration(const Algorithm &algo) const
Class for storing statistics about the Quasi-Newton updating.
void print_top_header(const NLPAlgoState &s, const NLPAlgo &algo) const
Print the top header to the output.
const ostream_ptr_t & get_output_stream() const
Get the output stream for console outputting.
T_To & dyn_cast(T_From &from)
rSQP Algorithm control class.
void print_header(const NLPAlgoState &s, const NLPAlgo &algo) const
Print the header to the output.
Reduced space SQP state encapsulation interface.
NLPAlgoState & rsqp_state()
<<std aggr>="">> members for algo_cntr
void set_output_stream(const ostream_ptr_t &o)
Set the output stream for console outputting.
void output_final(const Algorithm &algo, EAlgoReturn algo_return) const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)