46 #include "MoochoPack/src/std/CheckBasisFromCPy_Step.h"
50 #include "ConstrainedOptPack/src/VectorWithNorms.h"
51 #include "AbstractLinAlgPack/src/AbstractLinAlgPack_MatrixOp.hpp"
55 #include "Midynamic_cast_verbose.h"
56 #include "MiWorkspacePack.h"
58 namespace LinAlgOpPack {
62 namespace MoochoPack {
64 CheckBasisFromCPy_Step::CheckBasisFromCPy_Step(
65 const new_basis_strategy_ptr_t& new_basis_strategy
68 : new_basis_strategy_(new_basis_strategy)
69 , max_basis_cond_change_frac_( max_basis_cond_change_frac )
74 void CheckBasisFromCPy_Step::reset() {
80 bool CheckBasisFromCPy_Step::do_step( Algorithm& _algo, poss_type step_poss
91 NLPAlgoState &s = algo.rsqp_state();
92 Range1D decomp = s.con_decomp();
95 std::ostream&
out = algo.track().journal_out();
103 bool select_new_basis =
false;
109 Workspace<value_type> resid_ws(wss,py_k.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 );
126 nrm_c_decomp =
norm_inf(c_decomp_k),
127 beta = nrm_resid / (nrm_c_decomp+small_num);
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() ) {
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) {
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
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"
std::string typeName(const T &t)
EJournalOutputLevel
enum for journal output.
T_To & dyn_cast(T_From &from)
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.
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)
v_lhs = alpha * op(M_rhs1) * v_rhs2 + beta * v_lhs (BLAS xGEMV)
value_type norm_inf(const SparseVectorSlice< T_Ele > &sv_rhs)
result = ||sv_rhs||inf (BLAS IxAMAX)
DenseLinAlgPack::VectorSliceTmpl< value_type > DVectorSlice
void V_MtV(VectorMutable *v_lhs, const MatrixOp &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const V &V_rhs2)
v_lhs = op(M_rhs1) * V_rhs2.
AbstractLinAlgPack::value_type value_type
value_type norm_inf(const DVectorSlice &vs_rhs)
result = ||vs_rhs||infinity (BLAS IxAMAX)
RangePack::Range1D Range1D
NLPAlgo & rsqp_algo(Algorithm &algo)
Convert from a Algorithm to a NLPAlgo.
TEUCHOSCORE_LIB_DLL_EXPORT Teuchos::RCP< WorkspaceStore > get_default_workspace_store()
void Vp_V(VectorMutable *v_lhs, const V &V_rhs)
v_lhs += V_rhs.