MoochoPack_LineSearch2ndOrderCorrect_StepSetOptions.cpp

Go to the documentation of this file.
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 "MoochoPack_LineSearch2ndOrderCorrect_StepSetOptions.hpp"
00035 #include "OptionsFromStreamPack_StringToBool.hpp"
00036 
00037 // Define the options
00038 namespace {
00039 
00040   const int local_num_options = 8;
00041 
00042   enum local_EOptions {
00043       NEWTON_OLEVEL,
00044     CONSTR_NORM_THRESHOLD,
00045     CONSTR_INCR_RATIO,
00046     AFTER_K_ITER,
00047     FORCED_CONSTR_REDUCTION,
00048     FORCED_REDUCT_RATIO,
00049     MAX_STEP_RATIO,
00050     MAX_NEWTON_ITER
00051   };
00052 
00053   const char* local_SOptions[local_num_options] = {
00054       "newton_olevel",
00055     "constr_norm_threshold",
00056     "constr_incr_ratio",
00057     "after_k_iter",
00058     "forced_constr_reduction",
00059     "forced_reduct_ratio",
00060     "max_step_ratio",
00061     "max_newton_iter"
00062   };
00063 
00064 }
00065 
00066 namespace MoochoPack {
00067 
00068 LineSearch2ndOrderCorrect_StepSetOptions::LineSearch2ndOrderCorrect_StepSetOptions(
00069         LineSearch2ndOrderCorrect_Step* target
00070       , const char opt_grp_name[] )
00071   : OptionsFromStreamPack::SetOptionsFromStreamNode(
00072         opt_grp_name, local_num_options, local_SOptions )
00073     , OptionsFromStreamPack::SetOptionsToTargetBase<
00074       LineSearch2ndOrderCorrect_Step >( target )
00075 {}
00076 
00077 void LineSearch2ndOrderCorrect_StepSetOptions::setOption(
00078   int option_num, const std::string& option_value )
00079 {
00080   typedef LineSearch2ndOrderCorrect_Step target_t;
00081   switch( (local_EOptions)option_num ) {
00082       case NEWTON_OLEVEL:
00083     {
00084       const std::string &option = option_value.c_str();
00085       if( option == "PRINT_USE_DEFAULT" )
00086         target().newton_olevel( target_t::PRINT_USE_DEFAULT );
00087       else if( option == "PRINT_NOTHING" )
00088         target().newton_olevel( target_t::PRINT_NEWTON_NOTHING );
00089       else if( option == "PRINT_SUMMARY_INFO" )
00090         target().newton_olevel( target_t::PRINT_NEWTON_SUMMARY_INFO );
00091       else if( option == "PRINT_STEPS" )
00092         target().newton_olevel( target_t::PRINT_NEWTON_STEPS );
00093       else if( option == "PRINT_VECTORS" )
00094         target().newton_olevel( target_t::PRINT_NEWTON_VECTORS );
00095       else
00096         throw std::invalid_argument( "Error, incorrect value for "
00097           "\"newton_olevel\"." );
00098       break;
00099     }
00100       case CONSTR_NORM_THRESHOLD:
00101       target().constr_norm_threshold(::fabs(::atof(option_value.c_str())));
00102       break;
00103       case CONSTR_INCR_RATIO:
00104       target().constr_incr_ratio(::fabs(::atof(option_value.c_str())));
00105       break;
00106     case AFTER_K_ITER:
00107       target().after_k_iter(::abs(::atoi(option_value.c_str())));
00108       break;
00109     case FORCED_CONSTR_REDUCTION:
00110     {
00111       const std::string &option = option_value.c_str();
00112       if( option == "LESS_X_D" )
00113         target().forced_constr_reduction(target_t::CONSTR_LESS_X_D );
00114       else if( option == "LESS_X" )
00115         target().forced_constr_reduction( target_t::CONSTR_LESS_X );
00116       else
00117         throw std::invalid_argument( "Error, incorrect value for "
00118           "\"forced_constr_reduction\"." );
00119       break;
00120     }
00121       case FORCED_REDUCT_RATIO:
00122       target().forced_reduct_ratio(::fabs(::atof(option_value.c_str())));
00123       break;
00124     case MAX_STEP_RATIO:
00125       target().max_step_ratio(::fabs(::atof(option_value.c_str())));
00126       break;
00127     case MAX_NEWTON_ITER:
00128       target().max_newton_iter(::abs(::atoi(option_value.c_str())));
00129       break;
00130     default:
00131       TEST_FOR_EXCEPT(true);  // Local error only?
00132   }
00133 }
00134 
00135 } // end namespace MoochoPack 
00136 
00137 #endif // 0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:10:59 2011 for MOOCHO (Single Doxygen Collection) by  doxygen 1.6.3