ConstrainedOptPack_DecompositionSystemTesterSetOptions.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 #include <assert.h>
00030 #include <math.h>
00031 
00032 #include "ConstrainedOptPack_DecompositionSystemTesterSetOptions.hpp"
00033 #include "OptionsFromStreamPack_StringToBool.hpp"
00034 #include "Teuchos_TestForException.hpp"
00035 
00036 // Define the options
00037 namespace {
00038 
00039   const int local_num_options = 8;
00040 
00041   enum local_EOptions {
00042     PRINT_TESTS
00043     ,DUMP_ALL
00044     ,TEST_FOR_EXCEPTION
00045     ,NUM_RANDOM_TESTS
00046       ,MULT_WARNING_TOL
00047       ,MULT_ERROR_TOL
00048       ,SOLVE_WARNING_TOL
00049       ,SOLVE_ERROR_TOL
00050   };
00051 
00052   const char* local_SOptions[local_num_options] = {
00053     "print_tests"
00054     ,"dump_all"
00055     ,"throw_exception"
00056     ,"num_random_tests"
00057       ,"mult_warning_tol"
00058       ,"mult_error_tol"
00059       ,"solve_warning_tol"
00060       ,"solve_error_tol"
00061   };
00062 
00063 }
00064 
00065 namespace ConstrainedOptPack {
00066 
00067 DecompositionSystemTesterSetOptions::DecompositionSystemTesterSetOptions(
00068         DecompositionSystemTester* target
00069       , const char opt_grp_name[] )
00070   : OptionsFromStreamPack::SetOptionsFromStreamNode(
00071         opt_grp_name, local_num_options, local_SOptions )
00072     , OptionsFromStreamPack::SetOptionsToTargetBase<
00073       DecompositionSystemTester >( target )
00074 {}
00075 
00076 void DecompositionSystemTesterSetOptions::setOption(
00077   int option_num, const std::string& option_value )
00078 {
00079   using OptionsFromStreamPack::StringToBool;
00080   typedef DecompositionSystemTester target_t;
00081   switch( (local_EOptions)option_num ) {
00082     case PRINT_TESTS:
00083     {
00084       const std::string &option = option_value.c_str();
00085       if( option == "PRINT_NONE" )
00086         target().print_tests( target_t::PRINT_NONE );
00087         else if( option == "PRINT_BASIC" )
00088         target().print_tests( target_t::PRINT_BASIC );
00089         else if( option == "PRINT_MORE" )
00090         target().print_tests( target_t::PRINT_MORE );
00091         else if( option == "PRINT_ALL" )
00092         target().print_tests( target_t::PRINT_ALL );
00093       else
00094         TEST_FOR_EXCEPTION(
00095           true, std::invalid_argument
00096           ,"Error, incorrect value for "
00097           "\"print_tests\".  Only the options "
00098           "PRINT_NONE, PRINT_BASIS, PRINT_MORE and PRINT_ALL are allowed" );
00099       break;
00100     }
00101     case DUMP_ALL:
00102       target().dump_all(
00103         StringToBool( "dump_all", option_value.c_str() )
00104         );
00105       break;
00106     case TEST_FOR_EXCEPTION:
00107       target().throw_exception(
00108         StringToBool( "throw_exception", option_value.c_str() )
00109         );
00110       break;
00111       case NUM_RANDOM_TESTS:
00112       target().num_random_tests(std::abs(std::atoi(option_value.c_str())));
00113       break;
00114       case MULT_WARNING_TOL:
00115       target().mult_warning_tol(std::fabs(std::atof(option_value.c_str())));
00116       break;
00117       case MULT_ERROR_TOL:
00118       target().mult_error_tol(std::fabs(std::atof(option_value.c_str())));
00119       break;
00120       case SOLVE_WARNING_TOL:
00121       target().solve_warning_tol(std::fabs(std::atof(option_value.c_str())));
00122       break;
00123       case SOLVE_ERROR_TOL:
00124       target().solve_error_tol(std::fabs(std::atof(option_value.c_str())));
00125       break;
00126     default:
00127       TEST_FOR_EXCEPT(true);  // Local error only?
00128   }
00129 }
00130 
00131 } // end namespace ConstrainedOptPack

Generated on Tue Jul 13 09:30:51 2010 for MOOCHO (Single Doxygen Collection) by  doxygen 1.4.7