MoochoPack_LineSearch2ndOrderCorrect_StepSetOptions.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 "MoochoPack_LineSearch2ndOrderCorrect_StepSetOptions.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       NEWTON_OLEVEL,
00042     CONSTR_NORM_THRESHOLD,
00043     CONSTR_INCR_RATIO,
00044     AFTER_K_ITER,
00045     FORCED_CONSTR_REDUCTION,
00046     FORCED_REDUCT_RATIO,
00047     MAX_STEP_RATIO,
00048     MAX_NEWTON_ITER
00049   };
00050 
00051   const char* local_SOptions[local_num_options] = {
00052       "newton_olevel",
00053     "constr_norm_threshold",
00054     "constr_incr_ratio",
00055     "after_k_iter",
00056     "forced_constr_reduction",
00057     "forced_reduct_ratio",
00058     "max_step_ratio",
00059     "max_newton_iter"
00060   };
00061 
00062 }
00063 
00064 namespace MoochoPack {
00065 
00066 LineSearch2ndOrderCorrect_StepSetOptions::LineSearch2ndOrderCorrect_StepSetOptions(
00067         LineSearch2ndOrderCorrect_Step* target
00068       , const char opt_grp_name[] )
00069   : OptionsFromStreamPack::SetOptionsFromStreamNode(
00070         opt_grp_name, local_num_options, local_SOptions )
00071     , OptionsFromStreamPack::SetOptionsToTargetBase<
00072       LineSearch2ndOrderCorrect_Step >( target )
00073 {}
00074 
00075 void LineSearch2ndOrderCorrect_StepSetOptions::setOption(
00076   int option_num, const std::string& option_value )
00077 {
00078   typedef LineSearch2ndOrderCorrect_Step target_t;
00079   switch( (local_EOptions)option_num ) {
00080       case NEWTON_OLEVEL:
00081     {
00082       const std::string &option = option_value.c_str();
00083       if( option == "PRINT_USE_DEFAULT" )
00084         target().newton_olevel( target_t::PRINT_USE_DEFAULT );
00085       else if( option == "PRINT_NOTHING" )
00086         target().newton_olevel( target_t::PRINT_NEWTON_NOTHING );
00087       else if( option == "PRINT_SUMMARY_INFO" )
00088         target().newton_olevel( target_t::PRINT_NEWTON_SUMMARY_INFO );
00089       else if( option == "PRINT_STEPS" )
00090         target().newton_olevel( target_t::PRINT_NEWTON_STEPS );
00091       else if( option == "PRINT_VECTORS" )
00092         target().newton_olevel( target_t::PRINT_NEWTON_VECTORS );
00093       else
00094         throw std::invalid_argument( "Error, incorrect value for "
00095           "\"newton_olevel\"." );
00096       break;
00097     }
00098       case CONSTR_NORM_THRESHOLD:
00099       target().constr_norm_threshold(::fabs(::atof(option_value.c_str())));
00100       break;
00101       case CONSTR_INCR_RATIO:
00102       target().constr_incr_ratio(::fabs(::atof(option_value.c_str())));
00103       break;
00104     case AFTER_K_ITER:
00105       target().after_k_iter(::abs(::atoi(option_value.c_str())));
00106       break;
00107     case FORCED_CONSTR_REDUCTION:
00108     {
00109       const std::string &option = option_value.c_str();
00110       if( option == "LESS_X_D" )
00111         target().forced_constr_reduction(target_t::CONSTR_LESS_X_D );
00112       else if( option == "LESS_X" )
00113         target().forced_constr_reduction( target_t::CONSTR_LESS_X );
00114       else
00115         throw std::invalid_argument( "Error, incorrect value for "
00116           "\"forced_constr_reduction\"." );
00117       break;
00118     }
00119       case FORCED_REDUCT_RATIO:
00120       target().forced_reduct_ratio(::fabs(::atof(option_value.c_str())));
00121       break;
00122     case MAX_STEP_RATIO:
00123       target().max_step_ratio(::fabs(::atof(option_value.c_str())));
00124       break;
00125     case MAX_NEWTON_ITER:
00126       target().max_newton_iter(::abs(::atoi(option_value.c_str())));
00127       break;
00128     default:
00129       TEST_FOR_EXCEPT(true);  // Local error only?
00130   }
00131 }
00132 
00133 } // end namespace MoochoPack 

Generated on Tue Oct 20 12:51:47 2009 for MOOCHO (Single Doxygen Collection) by doxygen 1.4.7