|
MoochoPack : Framework for Large-Scale Optimization Algorithms Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00005 // Copyright (2003) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #include <ostream> 00030 00031 #include "MoochoPack_LineSearchFullStep_Step.hpp" 00032 #include "MoochoPack_Exceptions.hpp" 00033 #include "MoochoPack_moocho_algo_conversion.hpp" 00034 #include "IterationPack_print_algorithm_step.hpp" 00035 #include "AbstractLinAlgPack_MatrixOpOut.hpp" 00036 #include "AbstractLinAlgPack_VectorMutable.hpp" 00037 #include "AbstractLinAlgPack_VectorStdOps.hpp" 00038 #include "AbstractLinAlgPack_VectorOut.hpp" 00039 #include "AbstractLinAlgPack_LinAlgOpPack.hpp" 00040 #include "AbstractLinAlgPack_assert_print_nan_inf.hpp" 00041 #include "Teuchos_TestForException.hpp" 00042 00043 namespace MoochoPack { 00044 00045 MoochoPack::LineSearchFullStep_Step::LineSearchFullStep_Step( 00046 const bounds_tester_ptr_t& bounds_tester 00047 ) 00048 : 00049 bounds_tester_(bounds_tester) 00050 {} 00051 00052 00053 bool LineSearchFullStep_Step::do_step(Algorithm& _algo 00054 , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss) 00055 { 00056 using AbstractLinAlgPack::Vp_StV; 00057 using AbstractLinAlgPack::assert_print_nan_inf; 00058 using LinAlgOpPack::V_VpV; 00059 00060 NLPAlgo &algo = rsqp_algo(_algo); 00061 NLPAlgoState &s = algo.rsqp_state(); 00062 NLP &nlp = algo.nlp(); 00063 00064 const size_type 00065 m = nlp.m(); 00066 00067 EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level(); 00068 std::ostream& out = algo.track().journal_out(); 00069 00070 // print step header. 00071 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00072 using IterationPack::print_algorithm_step; 00073 print_algorithm_step( algo, step_poss, type, assoc_step_poss, out ); 00074 } 00075 00076 // alpha_k = 1.0 00077 IterQuantityAccess<value_type> 00078 &alpha_iq = s.alpha(); 00079 if( !alpha_iq.updated_k(0) ) 00080 alpha_iq.set_k(0) = 1.0; 00081 00082 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00083 out << "\nf_k = " << s.f().get_k(0); 00084 if(m) 00085 out << "\n||c_k||inf = " << s.c().get_k(0).norm_inf(); 00086 out << "\nalpha_k = " << alpha_iq.get_k(0) << std::endl; 00087 } 00088 00089 // x_kp1 = x_k + d_k 00090 IterQuantityAccess<VectorMutable> &x_iq = s.x(); 00091 const Vector &x_k = x_iq.get_k(0); 00092 VectorMutable &x_kp1 = x_iq.set_k(+1); 00093 x_kp1 = x_k; 00094 Vp_StV( &x_kp1, alpha_iq.get_k(0), s.d().get_k(0) ); 00095 00096 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00097 out << "\n||x_kp1||inf = " << s.x().get_k(+1).norm_inf() << std::endl; 00098 } 00099 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) { 00100 out << "\nx_kp1 =\n" << s.x().get_k(+1); 00101 } 00102 00103 if(algo.algo_cntr().check_results()) { 00104 assert_print_nan_inf( 00105 x_kp1, "x_kp1",true 00106 ,int(olevel) >= int(PRINT_ALGORITHM_STEPS) ? &out : NULL 00107 ); 00108 if( nlp.num_bounded_x() ) { 00109 if(!bounds_tester().check_in_bounds( 00110 int(olevel) >= int(PRINT_ALGORITHM_STEPS) ? &out : NULL 00111 , int(olevel) >= int(PRINT_VECTORS) // print_all_warnings 00112 , int(olevel) >= int(PRINT_ITERATION_QUANTITIES) // print_vectors 00113 , nlp.xl(), "xl" 00114 , nlp.xu(), "xu" 00115 , x_kp1, "x_kp1" 00116 )) 00117 { 00118 TEST_FOR_EXCEPTION( 00119 true, TestFailed 00120 ,"LineSearchFullStep_Step::do_step(...) : Error, " 00121 "the variables bounds xl <= x_k(+1) <= xu where violated!" ); 00122 } 00123 } 00124 } 00125 00126 // Calcuate f and c at the new point. 00127 nlp.unset_quantities(); 00128 nlp.set_f( &s.f().set_k(+1) ); 00129 if(m) nlp.set_c( &s.c().set_k(+1) ); 00130 nlp.calc_f(x_kp1); 00131 if(m) nlp.calc_c( x_kp1, false ); 00132 nlp.unset_quantities(); 00133 00134 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00135 out << "\nf_kp1 = " << s.f().get_k(+1); 00136 if(m) 00137 out << "\n||c_kp1||inf = " << s.c().get_k(+1).norm_inf(); 00138 out << std::endl; 00139 } 00140 00141 if( m && static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) { 00142 out << "\nc_kp1 =\n" << s.c().get_k(+1); 00143 } 00144 00145 if(algo.algo_cntr().check_results()) { 00146 assert_print_nan_inf( s.f().get_k(+1), "f(x_kp1)", true, &out ); 00147 if(m) 00148 assert_print_nan_inf( s.c().get_k(+1), "c(x_kp1)", true, &out ); 00149 } 00150 00151 return true; 00152 } 00153 00154 void LineSearchFullStep_Step::print_step( const Algorithm& algo 00155 , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss 00156 , std::ostream& out, const std::string& L ) const 00157 { 00158 out 00159 << L << "if alpha_k is not updated then\n" 00160 << L << " alpha_k = 1.0\n" 00161 << L << "end\n" 00162 << L << "x_kp1 = x_k + alpha_k * d_k\n" 00163 << L << "f_kp1 = f(x_kp1)\n" 00164 << L << "if m > 0 then c_kp1 = c(x_kp1)\n"; 00165 } 00166 00167 } // end namespace MoochoPack
1.7.4