|
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 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #include <ostream> 00043 00044 #include "MoochoPack_LineSearchFullStep_Step.hpp" 00045 #include "MoochoPack_Exceptions.hpp" 00046 #include "MoochoPack_moocho_algo_conversion.hpp" 00047 #include "IterationPack_print_algorithm_step.hpp" 00048 #include "AbstractLinAlgPack_MatrixOpOut.hpp" 00049 #include "AbstractLinAlgPack_VectorMutable.hpp" 00050 #include "AbstractLinAlgPack_VectorStdOps.hpp" 00051 #include "AbstractLinAlgPack_VectorOut.hpp" 00052 #include "AbstractLinAlgPack_LinAlgOpPack.hpp" 00053 #include "AbstractLinAlgPack_assert_print_nan_inf.hpp" 00054 #include "Teuchos_Assert.hpp" 00055 00056 namespace MoochoPack { 00057 00058 MoochoPack::LineSearchFullStep_Step::LineSearchFullStep_Step( 00059 const bounds_tester_ptr_t& bounds_tester 00060 ) 00061 : 00062 bounds_tester_(bounds_tester) 00063 {} 00064 00065 00066 bool LineSearchFullStep_Step::do_step(Algorithm& _algo 00067 , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss) 00068 { 00069 using AbstractLinAlgPack::Vp_StV; 00070 using AbstractLinAlgPack::assert_print_nan_inf; 00071 using LinAlgOpPack::V_VpV; 00072 00073 NLPAlgo &algo = rsqp_algo(_algo); 00074 NLPAlgoState &s = algo.rsqp_state(); 00075 NLP &nlp = algo.nlp(); 00076 00077 const size_type 00078 m = nlp.m(); 00079 00080 EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level(); 00081 std::ostream& out = algo.track().journal_out(); 00082 00083 // print step header. 00084 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00085 using IterationPack::print_algorithm_step; 00086 print_algorithm_step( algo, step_poss, type, assoc_step_poss, out ); 00087 } 00088 00089 // alpha_k = 1.0 00090 IterQuantityAccess<value_type> 00091 &alpha_iq = s.alpha(); 00092 if( !alpha_iq.updated_k(0) ) 00093 alpha_iq.set_k(0) = 1.0; 00094 00095 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00096 out << "\nf_k = " << s.f().get_k(0); 00097 if(m) 00098 out << "\n||c_k||inf = " << s.c().get_k(0).norm_inf(); 00099 out << "\nalpha_k = " << alpha_iq.get_k(0) << std::endl; 00100 } 00101 00102 // x_kp1 = x_k + d_k 00103 IterQuantityAccess<VectorMutable> &x_iq = s.x(); 00104 const Vector &x_k = x_iq.get_k(0); 00105 VectorMutable &x_kp1 = x_iq.set_k(+1); 00106 x_kp1 = x_k; 00107 Vp_StV( &x_kp1, alpha_iq.get_k(0), s.d().get_k(0) ); 00108 00109 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00110 out << "\n||x_kp1||inf = " << s.x().get_k(+1).norm_inf() << std::endl; 00111 } 00112 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) { 00113 out << "\nx_kp1 =\n" << s.x().get_k(+1); 00114 } 00115 00116 if(algo.algo_cntr().check_results()) { 00117 assert_print_nan_inf( 00118 x_kp1, "x_kp1",true 00119 ,int(olevel) >= int(PRINT_ALGORITHM_STEPS) ? &out : NULL 00120 ); 00121 if( nlp.num_bounded_x() ) { 00122 if(!bounds_tester().check_in_bounds( 00123 int(olevel) >= int(PRINT_ALGORITHM_STEPS) ? &out : NULL 00124 , int(olevel) >= int(PRINT_VECTORS) // print_all_warnings 00125 , int(olevel) >= int(PRINT_ITERATION_QUANTITIES) // print_vectors 00126 , nlp.xl(), "xl" 00127 , nlp.xu(), "xu" 00128 , x_kp1, "x_kp1" 00129 )) 00130 { 00131 TEUCHOS_TEST_FOR_EXCEPTION( 00132 true, TestFailed 00133 ,"LineSearchFullStep_Step::do_step(...) : Error, " 00134 "the variables bounds xl <= x_k(+1) <= xu where violated!" ); 00135 } 00136 } 00137 } 00138 00139 // Calcuate f and c at the new point. 00140 nlp.unset_quantities(); 00141 nlp.set_f( &s.f().set_k(+1) ); 00142 if(m) nlp.set_c( &s.c().set_k(+1) ); 00143 nlp.calc_f(x_kp1); 00144 if(m) nlp.calc_c( x_kp1, false ); 00145 nlp.unset_quantities(); 00146 00147 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00148 out << "\nf_kp1 = " << s.f().get_k(+1); 00149 if(m) 00150 out << "\n||c_kp1||inf = " << s.c().get_k(+1).norm_inf(); 00151 out << std::endl; 00152 } 00153 00154 if( m && static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) { 00155 out << "\nc_kp1 =\n" << s.c().get_k(+1); 00156 } 00157 00158 if(algo.algo_cntr().check_results()) { 00159 assert_print_nan_inf( s.f().get_k(+1), "f(x_kp1)", true, &out ); 00160 if(m) 00161 assert_print_nan_inf( s.c().get_k(+1), "c(x_kp1)", true, &out ); 00162 } 00163 00164 return true; 00165 } 00166 00167 void LineSearchFullStep_Step::print_step( const Algorithm& algo 00168 , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss 00169 , std::ostream& out, const std::string& L ) const 00170 { 00171 out 00172 << L << "if alpha_k is not updated then\n" 00173 << L << " alpha_k = 1.0\n" 00174 << L << "end\n" 00175 << L << "x_kp1 = x_k + alpha_k * d_k\n" 00176 << L << "f_kp1 = f(x_kp1)\n" 00177 << L << "if m > 0 then c_kp1 = c(x_kp1)\n"; 00178 } 00179 00180 } // end namespace MoochoPack
1.7.6.1