MoochoPack_NLPAlgoContainer.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 //#define RELEASE_TRACE
00030 
00031 #include <assert.h>
00032 
00033 #include <iostream> // used for debugging the Release version.
00034 
00035 #include "MoochoPack_NLPAlgoContainer.hpp"
00036 #include "MoochoPack_NLPAlgoInterface.hpp"
00037 #include "MoochoPack_NLPAlgoState.hpp"
00038 #include "NLPInterfacePack_NLP.hpp"
00039 #include "Teuchos_TestForException.hpp"
00040 
00041 namespace {
00042 
00043 void report_final_point( const MoochoPack::NLPAlgoState& s, const bool optimal, NLPInterfacePack::NLP* nlp )
00044 {
00045   const AbstractLinAlgPack::size_type
00046     m  = nlp->m(),
00047     nb = nlp->num_bounded_x();
00048   const IterationPack::IterQuantityAccess<AbstractLinAlgPack::VectorMutable>
00049     &x_iq = s.x();
00050   if( x_iq.updated_k(0) ) {
00051     nlp->report_final_solution(
00052       x_iq.get_k(0)                                                      // x
00053       ,( m  && s.lambda().updated_k(0) ) ? &s.lambda().get_k(0)  : NULL  // lambda
00054       ,( nb && s.nu().updated_k(0)     ) ? &s.nu().get_k(0)      : NULL  // nu
00055       , optimal                                                          // optimal = false
00056       );
00057   }
00058 }
00059 
00060 } // end namespace
00061 
00062 namespace MoochoPack {
00063 
00064 // Overridden from rSQPAlgoClient interface
00065 
00066 void NLPAlgoContainer::set_config(const config_ptr_t& config)
00067 {
00068   algo_ = Teuchos::null; // Remove our reference to the current (configured?) algorithm.
00069   config_ = config;
00070 }
00071 
00072 NLPAlgoContainer::config_ptr_t&
00073 NLPAlgoContainer::get_config()
00074 { 
00075   return config_;
00076 }
00077 
00078 const NLPAlgoContainer::config_ptr_t&
00079 NLPAlgoContainer::get_config() const
00080 { 
00081   return config_;
00082 }
00083 
00084 NLPAlgoConfig&
00085 NLPAlgoContainer::config()
00086 { 
00087   return *config_;
00088 }
00089 
00090 const NLPAlgoConfig&
00091 NLPAlgoContainer::config() const
00092 { 
00093   return *config_;
00094 }
00095 
00096 NLPSolverClientInterface::EFindMinReturn
00097 NLPAlgoContainer::find_min()
00098 {
00099   config().init_algo(&algo());
00100   EFindMinReturn solve_return;
00101   try {
00102     solve_return = algo().dispatch();
00103   }
00104   catch(...) {
00105     report_final_point(algo().retrieve_state(),false,&nlp());
00106     throw;
00107   }
00108   report_final_point(algo().retrieve_state(),solve_return==NLPSolverClientInterface::SOLUTION_FOUND,&nlp());
00109   return solve_return;
00110 }
00111 
00112 void NLPAlgoContainer::configure_algorithm(std::ostream* trase_out)
00113 {
00114   assert_valid_setup();
00115   if(!get_algo().get())
00116     config().config_algo_cntr(this,trase_out);
00117 }
00118 
00119 void NLPAlgoContainer::print_algorithm(std::ostream& out) const
00120 {
00121   algo().interface_print_algorithm(out);
00122 }
00123 
00124 void NLPAlgoContainer::set_algo_timing( bool algo_timing )
00125 {
00126   algo().interface_set_algo_timing(algo_timing);
00127 }
00128 
00129 bool NLPAlgoContainer::algo_timing() const
00130 {
00131   return algo().interface_algo_timing();
00132 }
00133 
00134 void NLPAlgoContainer::print_algorithm_times(
00135   std::ostream& out ) const
00136 {
00137   algo().interface_print_algorithm_times(out);
00138 }
00139 
00140 void NLPAlgoContainer::assert_valid_setup() const {
00141   TEST_FOR_EXCEPTION(
00142     !get_nlp().get(), NLPSolverClientInterface::InvalidSetup
00143     ,"NLPAlgoContainer::assert_valid_setup() : The NLP object has not been set" );
00144   TEST_FOR_EXCEPTION(
00145     !get_track().get(), NLPSolverClientInterface::InvalidSetup
00146     ,"NLPAlgoContainer::assert_valid_setup() : The AlgorithmTracker object has not been set" );
00147   TEST_FOR_EXCEPTION(
00148     !get_config().get(), NLPSolverClientInterface::InvalidSetup
00149     ,"NLPAlgoContainer::assert_valid_setup() : The NLPAlgoConfig object has not been set" );
00150 }
00151 
00152 } // end namespace MoochoPack

Generated on Tue Oct 20 12:51:47 2009 for MOOCHO (Single Doxygen Collection) by doxygen 1.4.7