MoochoPack_NewDecompositionSelectionStd_Strategy.cpp

Go to the documentation of this file.
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 "MoochoPack_NewDecompositionSelectionStd_Strategy.hpp"
00030 #include "MoochoPack_MoochoAlgorithmStepNames.hpp"
00031 #include "MoochoPack_NLPAlgo.hpp"
00032 #include "MoochoPack_NLPAlgoState.hpp"
00033 
00034 namespace MoochoPack {
00035 
00036 NewDecompositionSelectionStd_Strategy::NewDecompositionSelectionStd_Strategy(
00037   const decomp_sys_handler_ptr_t   &decomp_sys_handler
00038   )
00039   :decomp_sys_handler_(decomp_sys_handler)
00040 {}
00041 
00042 bool NewDecompositionSelectionStd_Strategy::new_decomposition(
00043   NLPAlgo& algo, Algorithm::poss_type step_poss
00044   ,IterationPack::EDoStepType type, Algorithm::poss_type assoc_step_poss
00045   )
00046 {
00047   NLPAlgoState               &s     = algo.rsqp_state();
00048   EJournalOutputLevel     olevel = algo.algo_cntr().journal_output_level();
00049   std::ostream&           out    = algo.track().journal_out();
00050 
00051   // Check to see if we have a decomposition system set
00052   if( !get_decomp_sys_handler().get() ) {
00053     if( static_cast<int>(olevel) >= static_cast<int>(PRINT_BASIC_ALGORITHM_INFO) ) {
00054       out << "\nWe are asked to select a new basis but there is no\n"
00055           "decomposition system set so we have no choice but to terminiate\n"
00056           "the algorithm"
00057         << " (k = " << algo.state().k() << ")\n";
00058     }
00059     algo.terminate(false);
00060     return false;
00061   }
00062 
00063   // We may get an infinite loop here so make sure we are under the max
00064   // number of iterations.
00065   if( s.k() >= algo.algo_cntr().max_iter() ) {
00066     if( static_cast<int>(olevel) >= static_cast<int>(PRINT_BASIC_ALGORITHM_INFO) ) {
00067       out << "\nThe maximum number of rSQP iterations\n"
00068         << " have been exceeded so quit "
00069         << " (k = " << algo.state().k() << ")\n";
00070     }
00071     algo.terminate(false);
00072     return false;
00073   }
00074 
00075   // Select a new decomposition
00076   decomp_sys_handler().select_new_decomposition(true);
00077   if( (int)olevel >= (int)PRINT_ALGORITHM_STEPS ) {
00078     out << "x_kp1 = x_k\n"
00079       << "k=k+1\n"
00080       << "goto EvalNewPoint\n";
00081   }
00082   s.x().set_k(1) = s.x().get_k(0);
00083   s.alpha().set_k(0) = 0.0; // Show that no step was taken.
00084   algo.track().output_iteration( algo );
00085   s.next_iteration();
00086   algo.do_step_next( EvalNewPoint_name );
00087   return false;
00088 }
00089 
00090 void NewDecompositionSelectionStd_Strategy::print_new_decomposition(
00091   const NLPAlgo& algo, Algorithm::poss_type step_poss
00092   ,IterationPack::EDoStepType type, Algorithm::poss_type assoc_step_poss
00093   ,std::ostream& out, const std::string& L
00094   ) const
00095 {
00096   out
00097     << L << "if k > max_iter then\n"
00098     << L << "  terminate the algorithm\n"
00099     << L << "end\n"   
00100     << L << "Select a new basis at current point\n"
00101     << L << "x_kp1 = x_k\n"
00102     << L << "alpha_k = 0\n"
00103     << L << "k=k+1\n"
00104     << L << "goto EvalNewPoint\n";
00105 }
00106 
00107 } // end namespace MoochoPack 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:11:00 2011 for MOOCHO (Single Doxygen Collection) by  doxygen 1.6.3