|
MoochoPack : Framework for Large-Scale Optimization Algorithms 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 00031 #include "MoochoPack_CheckConvergence_Strategy.hpp" 00032 #include "OptionsFromStreamPack_StringToBool.hpp" 00033 00034 namespace MoochoPack { 00035 00037 // CheckConvergence_Strategy 00039 00040 00041 CheckConvergence_Strategy::CheckConvergence_Strategy( 00042 EOptErrorCheck opt_error_check, 00043 EScaleKKTErrorBy scale_opt_error_by, 00044 EScaleKKTErrorBy scale_feas_error_by, 00045 EScaleKKTErrorBy scale_comp_error_by, 00046 bool scale_opt_error_by_Gf 00047 ) 00048 : 00049 opt_error_check_(opt_error_check), 00050 scale_opt_error_by_(scale_opt_error_by), 00051 scale_feas_error_by_(scale_feas_error_by), 00052 scale_comp_error_by_(scale_comp_error_by), 00053 scale_opt_error_by_Gf_(scale_opt_error_by_Gf) 00054 {} 00055 00056 00058 // CheckConvergence_StrategySetOptions 00060 00061 // Define the options 00062 namespace { 00063 00064 const int local_num_options = 4; 00065 00066 enum local_EOptions 00067 { 00068 SCALE_OPT_ERROR_BY, 00069 SCALE_FEAS_ERROR_BY, 00070 SCALE_COMP_ERROR_BY, 00071 SCALE_OPT_ERROR_BY_GF 00072 }; 00073 00074 const char* local_SOptions[local_num_options] = 00075 { 00076 "scale_opt_error_by", 00077 "scale_feas_error_by", 00078 "scale_comp_error_by", 00079 "scale_opt_error_by_Gf", 00080 }; 00081 00082 } // end namespace 00083 00084 CheckConvergence_StrategySetOptions::CheckConvergence_StrategySetOptions( 00085 CheckConvergence_Strategy* target, 00086 const char opt_grp_name[] ) 00087 : 00088 OptionsFromStreamPack::SetOptionsFromStreamNode( 00089 opt_grp_name, local_num_options, local_SOptions ), 00090 OptionsFromStreamPack::SetOptionsToTargetBase< 00091 CheckConvergence_Strategy >( target ) 00092 {} 00093 00094 00095 void CheckConvergence_StrategySetOptions::setOption( 00096 int option_num, 00097 const std::string& option_value ) 00098 { 00099 using OptionsFromStreamPack::StringToBool; 00100 00101 typedef CheckConvergence_Strategy target_t; 00102 switch( (local_EOptions)option_num ) 00103 { 00104 case SCALE_OPT_ERROR_BY: 00105 case SCALE_FEAS_ERROR_BY: 00106 case SCALE_COMP_ERROR_BY: 00107 { 00108 const std::string &option = option_value.c_str(); 00109 CheckConvergence_Strategy::EScaleKKTErrorBy scale_by = target_t::SCALE_BY_ONE; 00110 00111 if( option == "SCALE_BY_ONE" ) 00112 { scale_by = target_t::SCALE_BY_ONE; } 00113 else if( option == "SCALE_BY_NORM_2_X" ) 00114 { scale_by = target_t::SCALE_BY_NORM_2_X; } 00115 else if( option == "SCALE_BY_NORM_INF_X" ) 00116 { scale_by = target_t::SCALE_BY_NORM_INF_X; } 00117 else 00118 { 00119 throw std::invalid_argument( "Error, incorrect value for " 00120 "\"scale_kkt_error_by\". Only the options " 00121 "SCALE_BY_ONE, SCALE_BY_NORM_2_X, and SCALE_BY_NORM_INF_X " 00122 "are available" ); 00123 } 00124 00125 00126 if ((local_EOptions) option_num == SCALE_OPT_ERROR_BY) 00127 { 00128 target().scale_opt_error_by(scale_by); 00129 } 00130 else if ((local_EOptions) option_num == SCALE_FEAS_ERROR_BY) 00131 { 00132 target().scale_feas_error_by(scale_by); 00133 } 00134 else if ((local_EOptions) option_num == SCALE_COMP_ERROR_BY) 00135 { 00136 target().scale_comp_error_by(scale_by); 00137 } 00138 else 00139 { 00140 TEST_FOR_EXCEPTION( true, 00141 std::logic_error, 00142 "Unaccounted for option_num in CheckConvergence_Strategy.cpp" 00143 ); 00144 } 00145 00146 break; 00147 } 00148 case SCALE_OPT_ERROR_BY_GF: 00149 { 00150 target().scale_opt_error_by_Gf( 00151 StringToBool( "scale_opt_error_by_Gf", option_value.c_str() ) ); 00152 break; 00153 } 00154 default: 00155 TEST_FOR_EXCEPT(true); // Local error only? 00156 } 00157 } 00158 00159 } // end namespace MoochoPack
1.7.4