|
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 <assert.h> 00030 #include <math.h> 00031 00032 #include "MoochoPack_InitFinDiffReducedHessian_StepSetOptions.hpp" 00033 #include "OptionsFromStreamPack_StringToBool.hpp" 00034 00035 // Define the options 00036 namespace { 00037 00038 const int local_num_options = 4; 00039 00040 enum local_EOptions { 00041 INITIALIZATION_METHOD, 00042 MAX_COND, 00043 MIN_DIAG, 00044 STEP_SCALE 00045 }; 00046 00047 const char* local_SOptions[local_num_options] = { 00048 "initialization_method", 00049 "max_cond", 00050 "min_diag", 00051 "step_scale" 00052 }; 00053 00054 } 00055 00056 namespace MoochoPack { 00057 00058 InitFinDiffReducedHessian_StepSetOptions::InitFinDiffReducedHessian_StepSetOptions( 00059 InitFinDiffReducedHessian_Step* target 00060 , const char opt_grp_name[] ) 00061 : OptionsFromStreamPack::SetOptionsFromStreamNode( 00062 opt_grp_name, local_num_options, local_SOptions ) 00063 , OptionsFromStreamPack::SetOptionsToTargetBase< 00064 InitFinDiffReducedHessian_Step >( target ) 00065 {} 00066 00067 void InitFinDiffReducedHessian_StepSetOptions::setOption( 00068 int option_num, const std::string& option_value ) 00069 { 00070 typedef InitFinDiffReducedHessian_Step target_t; 00071 switch( (local_EOptions)option_num ) { 00072 case INITIALIZATION_METHOD: 00073 { 00074 const std::string &option = option_value.c_str(); 00075 if( option == "SCALE_IDENTITY" ) 00076 target().initialization_method( target_t::SCALE_IDENTITY ); 00077 else if( option == "SCALE_DIAGONAL" ) 00078 target().initialization_method( target_t::SCALE_DIAGONAL ); 00079 else if( option == "SCALE_DIAGONAL_ABS" ) 00080 target().initialization_method( target_t::SCALE_DIAGONAL_ABS ); 00081 else 00082 throw std::invalid_argument( "Error, incorrect value for " 00083 "\"initialization_method\"." ); 00084 break; 00085 } 00086 case MAX_COND: 00087 target().max_cond(std::fabs(std::atof(option_value.c_str()))); 00088 break; 00089 case MIN_DIAG: 00090 target().min_diag(std::abs(std::atoi(option_value.c_str()))); 00091 break; 00092 case STEP_SCALE: 00093 target().step_scale(std::fabs(std::atof(option_value.c_str()))); 00094 break; 00095 default: 00096 TEST_FOR_EXCEPT(true); // Local error only? 00097 } 00098 } 00099 00100 } // end namespace MoochoPack
1.7.4