67 namespace MoochoPack {
70 const decomp_sys_handler_ptr_t &decomp_sys_handler
71 ,
const deriv_tester_ptr_t &deriv_tester
72 ,
const bounds_tester_ptr_t &bounds_tester
73 ,
const decomp_sys_tester_ptr_t &decomp_sys_tester
78 :decomp_sys_handler_(decomp_sys_handler)
79 ,deriv_tester_(deriv_tester)
80 ,bounds_tester_(bounds_tester)
81 ,decomp_sys_tester_(decomp_sys_tester)
82 ,fd_deriv_testing_(fd_deriv_testing)
83 ,decomp_sys_testing_(decomp_sys_testing)
84 ,decomp_sys_testing_print_level_(decomp_sys_testing_print_level)
100 NLPFirstOrder &nlp =
dyn_cast<NLPFirstOrder>(algo.nlp());
112 if(!nlp.is_initialized())
113 nlp.initialize(algo.algo_cntr().check_results());
120 nb = nlp.num_bounded_x(),
126 IterQuantityAccess<value_type>
128 IterQuantityAccess<VectorMutable>
130 *c_iq = m > 0 ? &s.c() : NULL,
132 IterQuantityAccess<MatrixOp>
133 *Gc_iq = m > 0 ? &s.Gc() : NULL,
138 IterQuantityAccess<MatrixOpNonsing>
141 MatrixOp::EMatNormType mat_nrm_inf = MatrixOp::MAT_NORM_INF;
142 const bool calc_matrix_norms = algo.algo_cntr().calc_matrix_norms();
143 const bool calc_matrix_info_null_space_only = algo.algo_cntr().calc_matrix_info_null_space_only();
145 if( x_iq.last_updated() == IterQuantity::NONE_UPDATED ) {
147 out <<
"\nx is not updated for any k so set x_k = nlp.xinit() ...\n";
149 x_iq.set_k(0) = nlp.xinit();
153 if( nb && algo.algo_cntr().check_results() ) {
155 x_iq.get_k(0),
"x_k", true
158 if( nlp.num_bounded_x() > 0 ) {
159 if(!bounds_tester().check_in_bounds(
165 ,x_iq.get_k(0),
"x_k"
170 ,
"EvalNewPointStd_Step::do_step(...) : Error, "
171 "the variables bounds xl <= x_k <= xu where violated!" );
176 Vector &x = x_iq.get_k(0);
178 Range1D var_dep(Range1D::INVALID), var_indep(Range1D::INVALID);
179 if( s.get_decomp_sys().get() ) {
183 var_dep = decomp_sys_vr->
var_dep();
187 s.var_indep(var_indep);
191 out <<
"\n||x_k||inf = " << x.norm_inf();
193 out <<
"\n||x(var_dep)_k||inf = " << x.sub_view(var_dep)->norm_inf();
194 if( var_indep.size() )
195 out <<
"\n||x(var_indep)_k||inf = " << x.sub_view(var_indep)->norm_inf();
198 if( static_cast<int>(olevel) >= static_cast<int>(
PRINT_VECTORS) ) {
199 out <<
"\nx_k = \n" << x;
201 out <<
"\nx(var_dep)_k = \n" << *x.sub_view(var_dep);
203 if( static_cast<int>(ns_olevel) >= static_cast<int>(
PRINT_VECTORS) ) {
204 if( var_indep.size() )
205 out <<
"\nx(var_indep)_k = \n" << *x.sub_view(var_indep);
209 const bool f_k_updated = f_iq.updated_k(0);
210 const bool Gf_k_updated = Gf_iq.updated_k(0);
211 const bool c_k_updated = m > 0 ? c_iq->updated_k(0) :
false;
212 const bool Gc_k_updated = m > 0 ? Gc_iq->updated_k(0) :
false;
213 nlp.unset_quantities();
214 if(!f_k_updated) nlp.set_f( &f_iq.set_k(0) );
215 if(!Gf_k_updated) nlp.set_Gf( &Gf_iq.set_k(0) );
217 if(!c_k_updated) nlp.set_c( &c_iq->set_k(0) );
218 if(!Gc_k_updated) nlp.set_Gc( &Gc_iq->set_k(0) );
222 bool new_point =
true;
224 if(!Gc_k_updated) nlp.calc_Gc( x, new_point );
231 bool new_decomp_selected =
false;
235 decomp_sys_handler().update_decomposition(
236 algo, s, nlp, decomp_sys_testing(), decomp_sys_testing_print_level()
237 ,&new_decomp_selected
240 r = s.equ_decomp().size();
242 Z_iq = ( n > m && r > 0 ) ? &s.Z() : NULL;
243 Y_iq = ( r > 0 ) ? &s.Y() : NULL;
244 Uz_iq = ( m > 0 && m > r ) ? &s.Uz() : NULL;
245 Uy_iq = ( m > 0 && m > r ) ? &s.Uy() : NULL;
246 R_iq = ( m > 0 ) ? &s.R() : NULL;
249 const DecompositionSystem::ERunTests
252 && algo.algo_cntr().check_results() ) )
253 ? DecompositionSystem::RUN_TESTS
254 : DecompositionSystem::NO_TESTS );
257 DecompositionSystem::EOutputLevel ds_olevel;
261 ds_olevel = DecompositionSystem::PRINT_NONE;
265 ds_olevel = DecompositionSystem::PRINT_BASIC_INFO;
271 ds_olevel = DecompositionSystem::PRINT_EVERY_THING;
278 if( ds_test_what == DecompositionSystem::RUN_TESTS ) {
280 if( decomp_sys_tester().print_tests() == DecompositionSystemTester::PRINT_NOT_SELECTED ) {
281 DecompositionSystemTester::EPrintTestLevel ds_olevel;
285 ds_olevel = DecompositionSystemTester::PRINT_NONE;
289 ds_olevel = DecompositionSystemTester::PRINT_BASIC;
292 ds_olevel = DecompositionSystemTester::PRINT_MORE;
295 ds_olevel = DecompositionSystemTester::PRINT_ALL;
300 decomp_sys_tester().print_tests(ds_olevel);
305 out <<
"\nTesting the range/null decompostion ...\n";
308 decomp_sys_passed = decomp_sys_tester().test_decomp_system(
311 ,Z_iq ? &Z_iq->get_k(0) : NULL
314 ,m > r ? &Uz_iq->get_k(0) : NULL
315 ,m > r ? &Uy_iq->get_k(0) : NULL
320 ,
"EvalNewPointStd_Step::do_step(...) : Error, "
321 "the tests of the decomposition system failed!" );
327 dyn_cast<MatrixSymIdent>(Z_iq->set_k(0)).initialize( nlp.space_x() );
328 s.equ_decomp(Range1D::Invalid);
329 s.equ_undecomp(Range1D::Invalid);
336 if(!Gf_k_updated) { nlp.calc_Gf( x, new_point ); new_point =
false; }
337 if( m && (!c_k_updated || new_decomp_selected ) ) {
338 if(c_k_updated) nlp.set_c( &c_iq->set_k(0) );
339 nlp.calc_c( x,
false);
342 nlp.calc_f( x,
false);
344 nlp.unset_quantities();
355 if( s.get_decomp_sys().get() ) {
359 var_dep = decomp_sys_vr->
var_dep();
365 out <<
"\nPrinting the updated iteration quantities ...\n";
369 out <<
"\nf_k = " << f_iq.get_k(0);
370 out <<
"\n||Gf_k||inf = " << Gf_iq.get_k(0).norm_inf();
372 out <<
"\n||Gf_k(var_dep)_k||inf = " << Gf_iq.get_k(0).sub_view(var_dep)->norm_inf();
373 if( var_indep.size() )
374 out <<
"\n||Gf_k(var_indep)_k||inf = " << Gf_iq.get_k(0).sub_view(var_indep)->norm_inf();
376 out <<
"\n||c_k||inf = " << c_iq->get_k(0).norm_inf();
377 if( calc_matrix_norms && !calc_matrix_info_null_space_only )
378 out <<
"\n||Gc_k||inf = " << Gc_iq->get_k(0).calc_norm(mat_nrm_inf).value;
379 if( n > r && calc_matrix_norms && !calc_matrix_info_null_space_only )
380 out <<
"\n||Z||inf = " << Z_iq->get_k(0).calc_norm(mat_nrm_inf).value;
381 if( r && calc_matrix_norms && !calc_matrix_info_null_space_only )
382 out <<
"\n||Y||inf = " << Y_iq->get_k(0).calc_norm(mat_nrm_inf).value;
383 if( r && calc_matrix_norms && !calc_matrix_info_null_space_only )
384 out <<
"\n||R||inf = " << R_iq->get_k(0).calc_norm(mat_nrm_inf).value;
385 if( algo.algo_cntr().calc_conditioning() && !calc_matrix_info_null_space_only ) {
386 out <<
"\ncond_inf(R) = " << R_iq->get_k(0).calc_cond_num(mat_nrm_inf).value;
388 if( m > r && calc_matrix_norms && !calc_matrix_info_null_space_only ) {
389 out <<
"\n||Uz_k||inf = " << Uz_iq->get_k(0).calc_norm(mat_nrm_inf).value;
390 out <<
"\n||Uy_k||inf = " << Uy_iq->get_k(0).calc_norm(mat_nrm_inf).value;
398 out <<
"\nGc_k =\n" << Gc_iq->get_k(0);
400 out <<
"\nZ_k =\n" << Z_iq->get_k(0);
402 out <<
"\nY_k =\n" << Y_iq->get_k(0);
403 out <<
"\nR_k =\n" << R_iq->get_k(0);
406 out <<
"\nUz_k =\n" << Uz_iq->get_k(0);
407 out <<
"\nUy_k =\n" << Uy_iq->get_k(0);
410 if( static_cast<int>(olevel) >= static_cast<int>(
PRINT_VECTORS) ) {
411 out <<
"\nGf_k =\n" << Gf_iq.get_k(0);
413 out <<
"\nGf(var_dep)_k =\n " << *Gf_iq.get_k(0).sub_view(var_dep);
415 if( static_cast<int>(ns_olevel) >= static_cast<int>(
PRINT_VECTORS) ) {
416 if( var_indep.size() )
417 out <<
"\nGf(var_indep)_k =\n" << *Gf_iq.get_k(0).sub_view(var_indep);
419 if( static_cast<int>(olevel) >= static_cast<int>(
PRINT_VECTORS) ) {
421 out <<
"\nc_k = \n" << c_iq->get_k(0);
425 if( fd_deriv_testing() ==
FD_TEST
426 || ( fd_deriv_testing() ==
FD_DEFAULT && algo.algo_cntr().check_results() ) )
430 out <<
"\n*** Checking derivatives by finite differences\n";
434 nlp_passed = deriv_tester().finite_diff_check(
437 ,nb ? &nlp.xl() : NULL
438 ,nb ? &nlp.xu() : NULL
439 ,m ? &Gc_iq->get_k(0) : NULL
446 ,
"EvalNewPointStd_Step::do_step(...) : Error, "
447 "the tests of the nlp derivatives failed!" );
455 ,
poss_type assoc_step_poss, std::ostream&
out,
const std::string& L
460 const NLP &nlp = algo.nlp();
464 << L <<
"*** Evaluate the new point and update the range/null decomposition\n"
465 << L <<
"if nlp is not initialized then initialize the nlp\n"
466 << L <<
"if x is not updated for any k then set x_k = xinit\n";
469 << L <<
"if Gc_k is not updated Gc_k = Gc(x_k) <: space_x|space_c\n"
470 << L <<
"For Gc_k = [ Gc_k(:,equ_decomp), Gc_k(:,equ_undecomp) ] where:\n"
471 << L <<
" Gc_k(:,equ_decomp) <: space_x|space_c(equ_decomp) has full column rank r\n"
473 << L <<
" Z_k <: space_x|space_null s.t. Gc_k(:,equ_decomp)' * Z_k = 0\n"
474 << L <<
" Y_k <: space_x|space_range s.t. [Z_k Y_k] is nonsigular \n"
475 << L <<
" R_k <: space_c(equ_decomp)|space_range\n"
476 << L <<
" s.t. R_k = Gc_k(:,equ_decomp)' * Y_k\n"
477 << L <<
" if m > r : Uz_k <: space_c(equ_undecomp)|space_null\n"
478 << L <<
" s.t. Uz_k = Gc_k(:,equ_undecomp)' * Z_k\n"
479 << L <<
" if m > r : Uy_k <: space_c(equ_undecomp)|space_range\n"
480 << L <<
" s.t. Uy_k = Gc_k(:,equ_undecomp)' * Y_k\n"
481 << L <<
"begin update decomposition (class \'" <<
typeName(decomp_sys_handler()) <<
"\')\n"
483 decomp_sys_handler().print_update_decomposition( algo, s, out, L +
" " );
485 << L <<
"end update decomposition\n"
486 << L <<
"if ( (decomp_sys_testing==DST_TEST)\n"
487 << L <<
" or (decomp_sys_testing==DST_DEFAULT and check_results==true)\n"
489 << L <<
" check properties for Z_k, Y_k, R_k, Uz_k and Uy_k\n"
495 << L <<
"Z_k = eye(space_x)\n";
502 << L <<
"Gf_k = Gf(x_k) <: space_x\n"
503 << L <<
"if m > 0 and c_k is not updated c_k = c(x_k) <: space_c\n"
504 << L <<
"if f_k is not updated f_k = f(x_k) <: REAL\n"
505 << L <<
"if ( (fd_deriv_testing==FD_TEST)\n"
506 << L <<
" or (fd_deriv_testing==FD_DEFAULT and check_results==true)\n"
508 << L <<
" check Gc_k (if m > 0) and Gf_k by finite differences.\n"
void print_step(const Algorithm &algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss, std::ostream &out, const std::string &leading_str) const
AbstractLinAlgPack::size_type size_type
std::string typeName(const T &t)
virtual Range1D var_dep() const =0
Thrown if a runtime test failed.
Teuchos::EVerbosityLevel convertToVerbLevel(const EJournalOutputLevel output_level)
Conver to Teuchos::EVerbosityLevel.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
rSQP Algorithm control class.
virtual Range1D var_indep() const =0
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual std::ostream & journal_out() const
Return a reference to a std::ostream to be used to output debug information and the like...
EJournalOutputLevel
enum for journal output.
T_To & dyn_cast(T_From &from)
bool do_step(Algorithm &algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss)
Reduced space SQP state encapsulation interface.
void print_algorithm_step(const Algorithm &algo, Algorithm::poss_type step_poss, EDoStepType type, Algorithm::poss_type assoc_step_poss, std::ostream &out)
Prints to 'out' the algorithm step.
AlgorithmTracker & track()
Specialization of DecompositionSystem for variable reduction decompositions.
NLP first order information interface class {abstract}.
bool assert_print_nan_inf(const value_type &val, const char name[], bool throw_excpt, std::ostream *out)
This function asserts if a value_type scalare is a NaN or Inf and optionally prints out these entires...
Acts as the central hub for an iterative algorithm.
NLPAlgoState & rsqp_state()
<<std aggr>="">> members for algo_cntr
RangePack::Range1D Range1D
NLPAlgo & rsqp_algo(Algorithm &algo)
Convert from a Algorithm to a NLPAlgo.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)