|
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 #include <typeinfo> 00031 00032 #include "MoochoPack_QPFailureReinitReducedHessian_Step.hpp" 00033 #include "MoochoPack_MoochoAlgorithmStepNames.hpp" 00034 #include "MoochoPack_Exceptions.hpp" 00035 #include "MoochoPack_moocho_algo_conversion.hpp" 00036 #include "IterationPack_print_algorithm_step.hpp" 00037 00038 namespace MoochoPack { 00039 00040 QPFailureReinitReducedHessian_Step::QPFailureReinitReducedHessian_Step( 00041 const null_space_step_ptr_t& null_space_step 00042 ) 00043 :null_space_step_(null_space_step) 00044 ,last_qp_failure_k_(-100) // has not failed yet. 00045 {} 00046 00047 bool QPFailureReinitReducedHessian_Step::do_step( 00048 Algorithm& _algo, poss_type step_poss, IterationPack::EDoStepType type 00049 ,poss_type assoc_step_poss 00050 ) 00051 { 00052 try { 00053 return null_space_step().do_step(_algo,step_poss,type,assoc_step_poss); 00054 } 00055 catch(const QPFailure& qp_excpt) { 00056 NLPAlgo &algo = rsqp_algo(_algo); 00057 NLPAlgoState &s = algo.rsqp_state(); 00058 EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level(); 00059 std::ostream &out = algo.track().journal_out(); 00060 00061 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_BASIC_ALGORITHM_INFO) ) { 00062 out << "\nQP failed! " 00063 << " (k = " << algo.state().k() << ")\n" 00064 << "QPFailure description: " << qp_excpt.what() << "\n"; 00065 } 00066 if( s.k() >= algo.algo_cntr().max_iter() ) { 00067 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_BASIC_ALGORITHM_INFO) ) { 00068 out << "\nThe maximum number of rSQP iterations\n" 00069 << " have been exceeded so quit " 00070 << " (k = " << algo.state().k() << ")\n"; 00071 } 00072 algo.terminate(false); 00073 return false; 00074 } 00075 if( last_qp_failure_k_ == s.k() ) { 00076 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_BASIC_ALGORITHM_INFO) ) { 00077 out << "\nThe QP failed again even with a new reduced Hessian rHL_k!" 00078 << " (k = " << algo.state().k() << ")\n" 00079 << "We quit!\n"; 00080 } 00081 throw; 00082 } 00083 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_BASIC_ALGORITHM_INFO) ) { 00084 out << "\nWiping out all memory for rHL and going back to reinitalize it ..." 00085 << " (k = " << algo.state().k() << ")\n"; 00086 } 00087 last_qp_failure_k_ = s.k(); // Remember this for later! 00088 if( (int)olevel >= (int)PRINT_ALGORITHM_STEPS ) { 00089 out << "Wipe out all update rHL_{k} for all k\n" 00090 << "goto ReducedHessian\n"; 00091 } 00092 s.rHL().set_all_not_updated(); 00093 algo.do_step_next( ReducedHessian_name ); 00094 return false; 00095 } 00096 return false; // will never be executed. 00097 } 00098 00099 void QPFailureReinitReducedHessian_Step::print_step( 00100 const Algorithm& algo 00101 ,poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss 00102 ,std::ostream& out, const std::string& L 00103 ) const 00104 { 00105 out 00106 << L << "do null space step : " << typeName(null_space_step()) << std::endl; 00107 null_space_step().print_step(algo,step_poss,type,assoc_step_poss,out,L+" "); 00108 out 00109 << L << "end null space step\n" 00110 << L << "if QPFailure was thrown then\n" 00111 << L << " if QP failed already then\n" 00112 << L << " rethrow QPFailure\n" 00113 << L << " end\n" 00114 << L << " if k > max_iter then\n" 00115 << L << " terminate the algorithm!\n" 00116 << L << " end\n" 00117 << L << " set all rHL_{k} to not updated\n" 00118 << L << " goto ReducedHessian\n" 00119 << L << "end\n" 00120 ; 00121 } 00122 00123 } // end namespace MoochoPack
1.7.4