NLPInterfacePack_NLPDirectTesterSetOptions.cpp

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_NLPDirectTesterSetOptions.hpp"
00033 #include "OptionsFromStreamPack_StringToBool.hpp"
00034 
00035 // Define the options
00036 namespace {
00037 
00038   const int local_num_options = 8;
00039 
00040   enum local_EOptions {
00041     GF_TESTING_METHOD
00042     ,GF_WARNING_TOL
00043     ,GF_ERROR_TOL
00044     ,GC_TESTING_METHOD
00045     ,GC_WARNING_TOL
00046     ,GC_ERROR_TOL
00047     ,NUM_FD_DIRECTIONS
00048     ,DUMP_ALL
00049   };
00050 
00051   const char* local_SOptions[local_num_options] = {
00052       "Gf_testing_method"
00053       ,"Gf_warning_tol"
00054       ,"Gf_error_tol"
00055       ,"Gc_testing_method"
00056       ,"Gc_warning_tol"
00057       ,"Gc_error_tol"
00058       ,"num_fd_directions"
00059       ,"dump_all"
00060   };
00061 
00062 }
00063 
00064 namespace NLPInterfacePack {
00065 
00066 NLPDirectTesterSetOptions::NLPDirectTesterSetOptions(
00067   NLPDirectTester* target
00068   ,const char opt_grp_name[]
00069   )
00070   :OptionsFromStreamPack::SetOptionsFromStreamNode(opt_grp_name,local_num_options,local_SOptions)
00071   ,OptionsFromStreamPack::SetOptionsToTargetBase<NLPDirectTester>( target )
00072 {}
00073 
00074 void NLPDirectTesterSetOptions::setOption(
00075   int option_num, const std::string& option_value
00076   )
00077 {
00078   namespace ofsp = OptionsFromStreamPack;
00079   using ofsp::StringToBool;
00080   typedef NLPDirectTester target_t;
00081   switch( (local_EOptions)option_num ) {
00082     case GF_TESTING_METHOD:
00083     {
00084       const std::string &option = option_value.c_str();
00085       if( option == "FD_COMPUTE_ALL" )
00086         target().Gf_testing_method( target_t::FD_COMPUTE_ALL );
00087       else if( option == "FD_DIRECTIONAL" )
00088         target().Gf_testing_method( target_t::FD_DIRECTIONAL );
00089       else
00090         throw std::invalid_argument( "Error, incorrect value for "
00091                                      "\"Gf_testing_method\".  Only the options "
00092                                      "FD_COMPUTE_ALL and FD_DIRECTIONAL are available" );
00093       break;
00094     }
00095     case GF_WARNING_TOL:
00096       target().Gf_warning_tol(::fabs(::atof(option_value.c_str())));
00097       break;
00098     case GF_ERROR_TOL:
00099       target().Gf_error_tol(::fabs(::atof(option_value.c_str())));
00100       break;
00101     case GC_TESTING_METHOD:
00102     {
00103       const std::string &option = option_value.c_str();
00104       if( option == "FD_COMPUTE_ALL" )
00105         target().Gc_testing_method( target_t::FD_COMPUTE_ALL );
00106       else if( option == "FD_DIRECTIONAL" )
00107         target().Gc_testing_method( target_t::FD_DIRECTIONAL );
00108       else
00109         throw std::invalid_argument( "Error, incorrect value for "
00110                                      "\"Gc_testing_method\".  Only the options "
00111                                      "FD_COMPUTE_ALL and FD_DIRECTIONAL are available" );
00112       break;
00113     }
00114     case GC_WARNING_TOL:
00115       target().Gc_warning_tol(::fabs(::atof(option_value.c_str())));
00116       break;
00117     case GC_ERROR_TOL:
00118       target().Gc_error_tol(::fabs(::atof(option_value.c_str())));
00119       break;
00120     case NUM_FD_DIRECTIONS:
00121       target().num_fd_directions(::abs(::atoi(option_value.c_str())));
00122       break;
00123     case DUMP_ALL:
00124       target().dump_all(StringToBool("dump_all",option_value.c_str()));
00125       break;
00126     default:
00127       TEST_FOR_EXCEPT(true); // Local error only?
00128   }
00129 }
00130 
00131 } // end namespace NLPInterfacePack

Generated on Thu Sep 18 12:34:03 2008 for NLPInterfacePack: C++ Interfaces and Implementation for Non-Linear Programs by doxygen 1.3.9.1