|
MoochoPack : Framework for Large-Scale Optimization Algorithms Version of the Day
|
00001 #if 0 00002 00003 // @HEADER 00004 // *********************************************************************** 00005 // 00006 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00007 // Copyright (2003) Sandia Corporation 00008 // 00009 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00010 // license for use of this work by or on behalf of the U.S. Government. 00011 // 00012 // This library is free software; you can redistribute it and/or modify 00013 // it under the terms of the GNU Lesser General Public License as 00014 // published by the Free Software Foundation; either version 2.1 of the 00015 // License, or (at your option) any later version. 00016 // 00017 // This library is distributed in the hope that it will be useful, but 00018 // WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 // Lesser General Public License for more details. 00021 // 00022 // You should have received a copy of the GNU Lesser General Public 00023 // License along with this library; if not, write to the Free Software 00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00025 // USA 00026 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00027 // 00028 // *********************************************************************** 00029 // @HEADER 00030 00031 #include <assert.h> 00032 #include <math.h> 00033 00034 #include "ReducedHessianBFGSStd_StepSetOptions.h" 00035 #include "OptionsFromStreamPack_StringToBool.hpp" 00036 00037 // Define the options 00038 namespace { 00039 00040 const int local_num_options = 5; 00041 00042 enum local_EOptions { 00043 RESCALE_INIT_IDENTITY 00044 ,USE_DAMPENING 00045 ,SECANT_TESTING 00046 ,SECANT_WARNING_TOL 00047 ,SECANT_ERROR_TOL 00048 }; 00049 00050 const char* local_SOptions[local_num_options] = { 00051 "rescale_init_identity" 00052 ,"use_dampening" 00053 ,"secant_testing" 00054 ,"secant_warning_tol" 00055 ,"secant_error_tol" 00056 }; 00057 00058 } 00059 00060 namespace MoochoPack { 00061 00062 ReducedHessianBFGSStd_StepSetOptions::ReducedHessianBFGSStd_StepSetOptions( 00063 ReducedHessianBFGSStd_Step* target 00064 , const char opt_grp_name[] ) 00065 : OptionsFromStreamPack::SetOptionsFromStreamNode( 00066 opt_grp_name, local_num_options, local_SOptions ) 00067 , OptionsFromStreamPack::SetOptionsToTargetBase< 00068 ReducedHessianBFGSStd_Step >( target ) 00069 {} 00070 00071 void ReducedHessianBFGSStd_StepSetOptions::setOption( 00072 int option_num, const std::string& option_value ) 00073 { 00074 using OptionsFromStreamPack::StringToBool; 00075 typedef ReducedHessianBFGSStd_Step target_t; 00076 switch( (local_EOptions)option_num ) { 00077 case RESCALE_INIT_IDENTITY: 00078 target().rescale_init_identity( 00079 StringToBool( "rescale_init_identity", option_value.c_str() )); 00080 break; 00081 case USE_DAMPENING: 00082 target().use_dampening( 00083 StringToBool( "use_dampening", option_value.c_str() )); 00084 break; 00085 case SECANT_TESTING: 00086 { 00087 const std::string &option = option_value.c_str(); 00088 if( option == "DEFAULT" ) 00089 target().secant_testing( target_t::SECANT_TEST_DEFAULT ); 00090 else if( option == "TEST" ) 00091 target().secant_testing( target_t::SECANT_TEST_ALWAYS ); 00092 else if( option == "NO_TEST" ) 00093 target().secant_testing( target_t::SECANT_NO_TEST ); 00094 else 00095 throw std::invalid_argument( "Error, incorrect value for " 00096 "\"secant_testing\"." ); 00097 break; 00098 } 00099 case SECANT_WARNING_TOL: 00100 target().secant_warning_tol(::fabs(::atof(option_value.c_str()))); 00101 break; 00102 case SECANT_ERROR_TOL: 00103 target().secant_error_tol(::fabs(::atof(option_value.c_str()))); 00104 break; 00105 default: 00106 TEST_FOR_EXCEPT(true); // Local error only? 00107 } 00108 } 00109 00110 } // end namespace MoochoPack 00111 00112 #endif // 0
1.7.4