45 #include "MoochoPack_LineSearchDirect_Step.hpp"
46 #include "MoochoPack_Exceptions.hpp"
47 #include "MoochoPack_moocho_algo_conversion.hpp"
48 #include "IterationPack_print_algorithm_step.hpp"
49 #include "ConstrainedOptPack_MeritFuncCalc1DQuadratic.hpp"
50 #include "ConstrainedOptPack_MeritFuncCalcNLP.hpp"
51 #include "AbstractLinAlgPack_VectorMutable.hpp"
52 #include "AbstractLinAlgPack_VectorStdOps.hpp"
53 #include "AbstractLinAlgPack_VectorOut.hpp"
54 #include "AbstractLinAlgPack_assert_print_nan_inf.hpp"
55 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
56 #include "Teuchos_Assert.hpp"
58 namespace MoochoPack {
61 const direct_line_search_ptr_t& direct_line_search
63 :direct_line_search_(direct_line_search)
74 NLPAlgo &algo = rsqp_algo(_algo);
76 NLP &nlp = algo.nlp();
78 EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
82 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
83 using IterationPack::print_algorithm_step;
84 print_algorithm_step( algo, step_poss, type, assoc_step_poss, out );
104 IterQuantityAccess<value_type>
106 &alpha_iq = s.alpha(),
108 IterQuantityAccess<VectorMutable>
113 VectorMutable &x_kp1 = x_iq.get_k(+1);
114 const Vector &x_k = x_iq.get_k(0);
115 value_type &f_kp1 = f_iq.get_k(+1);
116 const value_type &f_k = f_iq.get_k(0);
117 VectorMutable *c_kp1 = m ? &c_iq.get_k(+1) : NULL;
118 const Vector *c_k = m ? &c_iq.get_k(0) : NULL;
119 const Vector &d_k = d_iq.get_k(0);
120 value_type &alpha_k = alpha_iq.get_k(0);
126 &merit_func_nlp_k = s.merit_func_nlp().get_k(0);
127 if( (
int)olevel >= (
int)PRINT_ALGORITHM_STEPS ) {
128 out <<
"\nBegin definition of NLP merit function phi.value(f(x),c(x)):\n";
129 merit_func_nlp_k.print_merit_func( out,
" " );
130 out <<
"end definition of the NLP merit funciton\n";
134 Dphi_k = merit_func_nlp_k.deriv();
135 if( (
int)olevel >= (
int)PRINT_ALGORITHM_STEPS ) {
136 out <<
"\nDphi_k = " << Dphi_k << std::endl;
140 ,
"LineSearch2ndOrderCorrect_Step::do_step(...) : "
141 "Error, d_k is not a descent direction for the merit function "
142 "since Dphi_k = " << Dphi_k <<
" >= 0" );
145 &phi_kp1 = phi_iq.set_k(+1) = merit_func_nlp_k.value(
154 &phi_k = phi_iq.set_k(0) = merit_func_nlp_k.value(
167 nlp.unset_quantities();
169 if(m) nlp.set_c( c_kp1 );
171 phi_calc( &merit_func_nlp_k, &nlp );
176 const Vector* xd[2] = { &x_k, &d_k };
177 MeritFuncCalc1DQuadratic
178 phi_calc_1d( phi_calc, 1, xd, &x_kp1 );
180 if( !direct_line_search().do_line_search(
181 phi_calc_1d, phi_k, &alpha_k, &phi_kp1
182 ,( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS)
183 ? &out : static_cast<std::ostream*>(0) )
188 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_BASIC_ALGORITHM_INFO) )
190 <<
"\nThe maximum number of linesearch iterations has been exceeded "
191 <<
"(k = " << algo.
state().
k() <<
")\n"
192 <<
"(phi_k - phi_kp1)/phi_k = " << ((phi_k - phi_kp1)/phi_k)
193 <<
"\nso we will reject the step and declare a line search failure.\n";
196 ,
"LineSearchDirect_Step::do_step(): Line search failure" );
198 nlp.unset_quantities();
200 if( (
int)olevel >= (
int)PRINT_ALGORITHM_STEPS ) {
201 out <<
"\nalpha_k = " << alpha_k;
202 out <<
"\n||x_kp1||inf = " << x_kp1.norm_inf();
203 out <<
"\nf_kp1 = " << f_kp1;
205 out <<
"\n||c_kp1||inf = " << c_kp1->norm_inf();
206 out <<
"\nphi_kp1 = " << phi_kp1;
210 if( (
int)olevel >= (
int)PRINT_VECTORS ) {
211 out <<
"\nx_kp1 =\n" << x_kp1;
213 out <<
"\nc_kp1 =\n" << *c_kp1;
221 ,std::ostream& out,
const std::string& L
225 << L <<
"*** Preform a line search along the full space search direction d_k.\n"
226 << L <<
"Dphi_k = merit_func_nlp_k.deriv()\n"
227 << L <<
"if Dphi_k >= 0 then\n"
228 << L <<
" throw line_search_failure\n"
230 << L <<
"phi_kp1 = merit_func_nlp_k.value(f_kp1,c_kp1,h_kp1,hl,hu)\n"
231 << L <<
"phi_k = merit_func_nlp_k.value(f_k,c_k,h_k,hl,hu)\n"
232 << L <<
"begin direct line search (where phi = merit_func_nlp_k): \"" <<
typeName(direct_line_search()) <<
"\"\n";
233 direct_line_search().print_algorithm( out, L +
" " );
235 << L <<
"end direct line search\n"
236 << L <<
"if maximum number of linesearch iterations are exceeded then\n"
237 << L <<
" throw line_search_failure\n"
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void Vp_StV(VectorMutable *v_lhs, const value_type &alpha, const Vector &v_rhs)
rSQP Algorithm control class.
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
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual std::ostream & journal_out() const
Thrown if a line search failure occurs.
void V_VpV(VectorMutable *v_lhs, const V1 &V1_rhs1, const V2 &V2_rhs2)
Reduced space SQP state encapsulation interface.
AlgorithmTracker & track()
bool do_step(Algorithm &algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss)
NLPAlgoState & rsqp_state()
<<std aggr>="">> members for algo_cntr
LineSearchDirect_Step(const direct_line_search_ptr_t &direct_line_search=Teuchos::null)
std::string typeName(const T &t)