|
NLPInterfacePack: C++ Interfaces and Implementation for Non-Linear Programs 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 "NLPInterfacePack_NLPFirstDerivTesterSetOptions.hpp" 00033 00034 // Define the options 00035 namespace { 00036 00037 const int local_num_options = 4; 00038 00039 enum local_EOptions { 00040 FD_TESTING_METHOD 00041 ,NUM_FD_DIRECTIONS 00042 ,WARNING_TOL 00043 ,ERROR_TOL 00044 }; 00045 00046 const char* local_SOptions[local_num_options] = { 00047 "fd_testing_method" 00048 ,"num_fd_directions" 00049 ,"warning_tol" 00050 ,"error_tol" 00051 }; 00052 00053 } 00054 00055 namespace NLPInterfacePack { 00056 00057 NLPFirstDerivTesterSetOptions::NLPFirstDerivTesterSetOptions( 00058 NLPFirstDerivTester* target 00059 , const char opt_grp_name[] ) 00060 : OptionsFromStreamPack::SetOptionsFromStreamNode( 00061 opt_grp_name, local_num_options, local_SOptions ) 00062 , OptionsFromStreamPack::SetOptionsToTargetBase< 00063 NLPFirstDerivTester >( target ) 00064 {} 00065 00066 void NLPFirstDerivTesterSetOptions::setOption( 00067 int option_num, const std::string& option_value ) 00068 { 00069 typedef NLPFirstDerivTester target_t; 00070 switch( (local_EOptions)option_num ) { 00071 case FD_TESTING_METHOD: 00072 { 00073 const std::string &option = option_value.c_str(); 00074 if( option == "FD_COMPUTE_ALL" ) 00075 target().fd_testing_method( target_t::FD_COMPUTE_ALL ); 00076 else if( option == "FD_DIRECTIONAL" ) 00077 target().fd_testing_method( target_t::FD_DIRECTIONAL ); 00078 else 00079 throw std::invalid_argument( "Error, incorrect value for " 00080 "\"fd_testing_method\". Only the options " 00081 "FD_COMPUTE_ALL and FD_DIRECTIONAL are available" ); 00082 break; 00083 } 00084 case NUM_FD_DIRECTIONS: 00085 target().num_fd_directions(std::atoi(option_value.c_str())); 00086 break; 00087 case WARNING_TOL: 00088 target().warning_tol(std::fabs(std::atof(option_value.c_str()))); 00089 break; 00090 case ERROR_TOL: 00091 target().error_tol(std::fabs(std::atof(option_value.c_str()))); 00092 break; 00093 default: 00094 TEST_FOR_EXCEPT(true); // Local error only? 00095 } 00096 } 00097 00098 } // end namespace NLPInterfacePack
1.7.4