46 #include "MoochoPack/src/std/CheckBasisFromCPy_Step.h" 47 #include "MoochoPack_moocho_algo_conversion.hpp" 48 #include "IterationPack_print_algorithm_step.hpp" 49 #include "ConstrainedOptPack_DecompositionSystemVarReduct.hpp" 50 #include "ConstrainedOptPack/src/VectorWithNorms.h" 51 #include "AbstractLinAlgPack/src/AbstractLinAlgPack_MatrixOp.hpp" 52 #include "DenseLinAlgPack_DVectorClass.hpp" 53 #include "DenseLinAlgPack_DVectorOp.hpp" 54 #include "DenseLinAlgPack_LinAlgOpPack.hpp" 55 #include "Midynamic_cast_verbose.h" 56 #include "MiWorkspacePack.h" 64 CheckBasisFromCPy_Step::CheckBasisFromCPy_Step(
65 const new_basis_strategy_ptr_t& new_basis_strategy
66 ,value_type max_basis_cond_change_frac
68 : new_basis_strategy_(new_basis_strategy)
69 , max_basis_cond_change_frac_( max_basis_cond_change_frac )
74 void CheckBasisFromCPy_Step::reset() {
75 beta_min_ = std::numeric_limits<value_type>::max();
80 bool CheckBasisFromCPy_Step::do_step( Algorithm& _algo,
poss_type step_poss
81 , IterationPack::EDoStepType type,
poss_type assoc_step_poss )
83 using DenseLinAlgPack::norm_inf;
84 using LinAlgOpPack::V_MtV;
86 using Teuchos::dyn_cast;
87 using Teuchos::Workspace;
88 Teuchos::WorkspaceStore* wss = Teuchos::get_default_workspace_store().get();
90 NLPAlgo &algo = rsqp_algo(_algo);
91 NLPAlgoState &s = algo.rsqp_state();
92 Range1D decomp = s.con_decomp();
94 EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
95 std::ostream& out = algo.track().journal_out();
98 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
99 using IterationPack::print_algorithm_step;
100 print_algorithm_step( algo, step_poss, type, assoc_step_poss, out );
103 bool select_new_basis =
false;
106 DVectorSlice py_k = s.py().get_k(0)();
107 DVectorSlice c_k = s.c().get_k(0)();
108 DVectorSlice c_decomp_k = c_k(decomp);
109 Workspace<value_type> resid_ws(wss,py_k.size());
110 DVectorSlice resid(&resid_ws[0],resid_ws.size());
113 DecompositionSystemVarReduct
114 &decomp_sys =
dynamic_cast<DecompositionSystemVarReduct&
>(s.decomp_sys());
116 DecompositionSystemVarReduct
117 &decomp_sys = dyn_cast<DecompositionSystemVarReduct>(s.decomp_sys());
120 Vp_V( &resid, c_decomp_k );
124 small_num = std::numeric_limits<value_type>::min(),
125 nrm_resid = norm_inf(resid),
126 nrm_c_decomp = norm_inf(c_decomp_k),
127 beta = nrm_resid / (nrm_c_decomp+small_num);
129 if( (
int)olevel >= (int)PRINT_ALGORITHM_STEPS ) {
130 out <<
"\nbeta = ||(Gc(decomp)'*Y)*py_k + c_k(decomp)||inf / (||c_k(decomp)||inf + small_number)" 131 <<
"\n = "<<nrm_resid<<
" / ("<<nrm_c_decomp<<
" + "<<small_num<<
")" 132 <<
"\n = " << beta << std::endl;
136 if( beta < beta_min_ ) {
140 if( beta / beta_min_ > max_basis_cond_change_frac() ) {
141 if( (
int)olevel >= (int)PRINT_BASIC_ALGORITHM_INFO ) {
143 <<
"\nbeta_change = ( ||R*py+c||/||c|| = " << beta
144 <<
" ) / ( min ||R*py+c||/||c|| = " << beta_min_ <<
" )\n" 145 <<
" = " << (beta/beta_min_) <<
" > max_basis_cond_change_frac = " 146 << max_basis_cond_change_frac()
147 <<
"\n\nSelecting a new basis" 148 <<
" (k = " << algo.state().k() <<
") ...\n";
150 select_new_basis =
true;
153 if(select_new_basis) {
157 beta_min_ = std::numeric_limits<value_type>::max();
158 return new_basis_strategy().transistion_basis(algo,step_poss,type,assoc_step_poss);
164 void CheckBasisFromCPy_Step::print_step(
const Algorithm& algo,
poss_type step_poss
165 , IterationPack::EDoStepType type,
poss_type assoc_step_poss
166 , std::ostream& out,
const std::string& L )
const 169 << L <<
"*** Try to detect when the basis is becomming illconditioned\n" 170 << L <<
"default: beta_min = inf\n" 171 << L <<
" max_basis_cond_change_frac = " << max_basis_cond_change_frac() << std::endl
172 << L <<
"beta = norm_inf((Gc(decomp)'*Y)*py_k + c_k(decomp)) / (norm_inf(c_k(decomp))+small_number)\n" 173 << L <<
"select_new_basis = false\n" 174 << L <<
"if beta < beta_min then\n" 175 << L <<
" beta_min = beta\n" 177 << L <<
" if beta/ beta_min > max_basis_cond_change_frac then\n" 178 << L <<
" select_new_basis = true\n" 181 << L <<
"if select_new_basis == true then\n" 182 << L <<
" new basis selection : " << typeName(new_basis_strategy()) << std::endl;
183 new_basis_strategy().print_method( rsqp_algo(algo),step_poss,type,assoc_step_poss,out
186 << L <<
" end new basis selection\n"
void Vp_StMtV(VectorMutable *v_lhs, value_type alpha, const MatrixOp &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2, value_type beta=1.0)
void Vp_V(VectorMutable *v_lhs, const V &V_rhs)