48 #include "MoochoPack_ReducedHessianExactStd_Step.hpp"
49 #include "MoochoPack_moocho_algo_conversion.hpp"
50 #include "AbstractLinAlgPack_MatrixSymDenseInitialize.hpp"
51 #include "IterationPack_print_algorithm_step.hpp"
52 #include "ConstrainedOptPack/src/VectorWithNorms.h"
53 #include "NLPInterfacePack_NLPSecondOrder.hpp"
54 #include "AbstractLinAlgPack/src/AbstractLinAlgPack_MatrixSymOp.hpp"
55 #include "DenseLinAlgPack_LinAlgOpPack.hpp"
56 #include "DenseLinAlgPack_DMatrixAsTriSym.hpp"
57 #include "DenseLinAlgPack_DMatrixOut.hpp"
58 #include "DenseLinAlgPack_DVectorClass.hpp"
59 #include "DenseLinAlgPack_DVectorOp.hpp"
60 #include "DenseLinAlgPack_DVectorOut.hpp"
61 #include "Midynamic_cast_verbose.h"
63 namespace MoochoPack {
66 Algorithm& _algo, poss_type step_poss, IterationPack::EDoStepType type
67 , poss_type assoc_step_poss)
70 using DenseLinAlgPack::nonconst_sym;
74 using ConstrainedOptPack::NLPSecondOrder;
76 NLPAlgo &algo = rsqp_algo(_algo);
77 NLPAlgoState &s = algo.rsqp_state();
80 &nlp =
dynamic_cast<NLPSecondOrder&
>(algo.nlp());
82 &nlp =
dyn_cast<NLPSecondOrder>(algo.nlp());
85 *HL_sym_op =
dynamic_cast<MatrixSymOp*
>(&s.HL().get_k(0));
87 EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
88 std::ostream& out = algo.track().journal_out();
91 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
92 using IterationPack::print_algorithm_step;
93 print_algorithm_step( algo, step_poss, type, assoc_step_poss, out );
103 if( !s.lambda().updated_k(-1) ) {
104 if( static_cast<int>(olevel) >=
static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
105 out <<
"Initializing lambda_km1 = nlp.get_lambda_init ... \n";
107 nlp.get_init_lagrange_mult( &s.lambda().set_k(-1).v(), NULL );
108 if( static_cast<int>(olevel) >=
static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
109 out <<
"||lambda_km1||inf = " << s.lambda().get_k(-1).norm_inf() << std::endl;
111 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) {
112 out <<
"lambda_km1 = \n" << s.lambda().get_k(-1)();
116 nlp.set_HL( HL_sym_op );
117 nlp.calc_HL( s.x().get_k(0)(), s.lambda().get_k(-1)(),
false );
119 if( static_cast<int>(olevel) >=
static_cast<int>(PRINT_ITERATION_QUANTITIES) ) {
120 s.HL().get_k(0).output( out <<
"\nHL_k = \n" );
124 if( !s.rHL().updated_k(0) ) {
127 std::ostringstream omsg;
129 <<
"ReducedHessianExactStd_Step::do_step(...) : Error, "
130 <<
"The matrix HL with the concrete type "
131 <<
typeName(s.HL().get_k(0)) <<
" does not support the "
132 <<
"MatrixSymOp iterface";
133 throw std::logic_error( omsg.str() );
136 MatrixSymDenseInitialize
137 *rHL_sym_init =
dynamic_cast<MatrixSymDenseInitialize*
>(&s.rHL().set_k(0));
138 if( !rHL_sym_init ) {
139 std::ostringstream omsg;
141 <<
"ReducedHessianExactStd_Step::do_step(...) : Error, "
142 <<
"The matrix rHL with the concrete type "
143 <<
typeName(s.rHL().get_k(0)) <<
" does not support the "
144 <<
"MatrixSymDenseInitialize iterface";
145 throw std::logic_error( omsg.str() );
149 DMatrix rHL_sym_store(nind,nind);
150 DMatrixSliceSym rHL_sym(rHL_sym_store(),BLAS_Cpp::lower);
151 Mp_StMtMtM( &rHL_sym, 1.0, MatrixSymOp::DUMMY_ARG, *HL_sym_op
154 if( (
int)olevel >= (int)PRINT_ITERATION_QUANTITIES ) {
155 out <<
"\nLower triangular partion of dense reduced Hessian (ignore nonzeros above diagonal):\nrHL_dense = \n" << rHL_sym_store();
159 rHL_sym_init->initialize( rHL_sym );
161 if( (
int)olevel >= (
int)PRINT_ITERATION_QUANTITIES ) {
162 s.rHL().get_k(0).output( out <<
"\nrHL_k = \n" );
170 const Algorithm& algo, poss_type step_poss, IterationPack::EDoStepType type
171 , poss_type assoc_step_poss, std::ostream& out,
const std::string& L )
const
174 << L <<
"*** Calculate the exact reduced Hessian of the Lagrangian\n"
175 << L <<
"if lambda_km1 is not updated then\n"
176 << L <<
" lambda_km1 = nlp.get_lambda_init\n"
178 << L <<
"HL_k = HL(x_k,lambda_km1) <: R^(n+m) -> R^(n x n)\n"
179 << L <<
"if rHL_k is not updated then\n"
180 << L <<
" rHL_dense = Z_k' * HL_k * Z_k (MatrixSymOp interface for HL_k)\n"
181 << L <<
" rHL_k = rHL_dense (MatrixSymDenseInitialize interface for rHL_k)\n"
T_To & dyn_cast(T_From &from)
void Mp_StMtMtM(MatrixSymOp *sym_lhs, value_type alpha, MatrixSymOp::EMatRhsPlaceHolder dummy_place_holder, const MatrixSymOp &M, const MatrixOp &mwo_rhs, BLAS_Cpp::Transp mwo_rhs_trans, value_type beta=1.0)
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
bool do_step(Algorithm &algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss)
std::string typeName(const T &t)