MoochoPack_LineSearchFailureNewDecompositionSelection_Step.cpp

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_LineSearchFailureNewDecompositionSelection_Step.hpp"
00033 #include "MoochoPack_MoochoAlgorithmStepNames.hpp"
00034 #include "MoochoPack_moocho_algo_conversion.hpp"
00035 #include "MoochoPack_Exceptions.hpp"
00036 #include "IterationPack_print_algorithm_step.hpp"
00037 
00038 namespace MoochoPack {
00039 
00040 LineSearchFailureNewDecompositionSelection_Step::LineSearchFailureNewDecompositionSelection_Step(
00041   const line_search_step_ptr_t        &line_search_step
00042   ,const new_decomp_strategy_ptr_t    &new_decomp_strategy
00043   )
00044   :line_search_step_(line_search_step)
00045   ,new_decomp_strategy_(new_decomp_strategy)
00046   ,last_ls_failure_k_(-100) // has not failed yet
00047 {}
00048 
00049 bool LineSearchFailureNewDecompositionSelection_Step::do_step(
00050   Algorithm& _algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss
00051   )
00052 {
00053   try {
00054     return line_search_step().do_step(_algo,step_poss,type,assoc_step_poss);
00055   }
00056   catch(const LineSearchFailure& lsf_excpt) {
00057     NLPAlgo        &algo = rsqp_algo(_algo);
00058     NLPAlgoState   &s    = algo.rsqp_state();
00059 
00060     EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
00061     std::ostream& out = algo.track().journal_out();
00062 
00063     if( static_cast<int>(olevel) >= static_cast<int>(PRINT_BASIC_ALGORITHM_INFO) ) {
00064       out << "\nLine search failed "
00065         << " (k = " << algo.state().k() << ")\n"
00066         << "LineSearchFailure description: " << lsf_excpt.what() << "\n";
00067     }
00068 
00069     if( last_ls_failure_k_ == s.k() - 1 ) {
00070       if( static_cast<int>(olevel) >= static_cast<int>(PRINT_BASIC_ALGORITHM_INFO) ) {
00071         out << "\nThe line search failed again even with a new decomposition!"
00072           << " (k = " << algo.state().k() << ")\n"
00073           << "We quit!\n";
00074       }
00075       throw;
00076     }
00077 
00078     if( static_cast<int>(olevel) >= static_cast<int>(PRINT_BASIC_ALGORITHM_INFO) ) {
00079       out << "\nSelecting a new decomposition..."
00080         << " (k = " << algo.state().k() << ")\n";
00081     }
00082 
00083     last_ls_failure_k_ = s.k();
00084     return new_decomp_strategy().new_decomposition(algo,step_poss,type,assoc_step_poss);
00085   }
00086   return false; // will never be executed.
00087 }
00088 
00089 void LineSearchFailureNewDecompositionSelection_Step::print_step(
00090   const Algorithm& algo
00091   ,poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss
00092   ,std::ostream& out, const std::string& L
00093   ) const
00094 {
00095   out
00096     << L << "do line search step : " << typeName(line_search_step()) << std::endl;
00097   line_search_step().print_step(algo,step_poss,type,assoc_step_poss,out,L+"    ");
00098   out
00099     << L << "end line search step\n"
00100     << L << "if thrown line_search_failure then\n"
00101     << L << "  if line search failed at the last iteration also then\n"
00102     << L << "    throw line_search_failure\n"
00103     << L << "  end\n"
00104     << L << "  new decomposition selection : " << typeName(new_decomp_strategy()) << std::endl
00105     ;
00106   new_decomp_strategy().print_new_decomposition(
00107     rsqp_algo(algo),step_poss,type,assoc_step_poss,out, L + "    " );
00108   out
00109     << L << "  end new decomposition selection\n"
00110     << L << "end\n"
00111     ;
00112 }
00113 
00114 } // end namespace MoochoPack

Generated on Wed May 12 21:32:13 2010 for MoochoPack : Framework for Large-Scale Optimization Algorithms by  doxygen 1.4.7