|
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 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #include <assert.h> 00043 00044 #include "MoochoPack_CheckConvergence_Strategy.hpp" 00045 #include "OptionsFromStreamPack_StringToBool.hpp" 00046 00047 namespace MoochoPack { 00048 00050 // CheckConvergence_Strategy 00052 00053 00054 CheckConvergence_Strategy::CheckConvergence_Strategy( 00055 EOptErrorCheck opt_error_check, 00056 EScaleKKTErrorBy scale_opt_error_by, 00057 EScaleKKTErrorBy scale_feas_error_by, 00058 EScaleKKTErrorBy scale_comp_error_by, 00059 bool scale_opt_error_by_Gf 00060 ) 00061 : 00062 opt_error_check_(opt_error_check), 00063 scale_opt_error_by_(scale_opt_error_by), 00064 scale_feas_error_by_(scale_feas_error_by), 00065 scale_comp_error_by_(scale_comp_error_by), 00066 scale_opt_error_by_Gf_(scale_opt_error_by_Gf) 00067 {} 00068 00069 00071 // CheckConvergence_StrategySetOptions 00073 00074 // Define the options 00075 namespace { 00076 00077 const int local_num_options = 4; 00078 00079 enum local_EOptions 00080 { 00081 SCALE_OPT_ERROR_BY, 00082 SCALE_FEAS_ERROR_BY, 00083 SCALE_COMP_ERROR_BY, 00084 SCALE_OPT_ERROR_BY_GF 00085 }; 00086 00087 const char* local_SOptions[local_num_options] = 00088 { 00089 "scale_opt_error_by", 00090 "scale_feas_error_by", 00091 "scale_comp_error_by", 00092 "scale_opt_error_by_Gf", 00093 }; 00094 00095 } // end namespace 00096 00097 CheckConvergence_StrategySetOptions::CheckConvergence_StrategySetOptions( 00098 CheckConvergence_Strategy* target, 00099 const char opt_grp_name[] ) 00100 : 00101 OptionsFromStreamPack::SetOptionsFromStreamNode( 00102 opt_grp_name, local_num_options, local_SOptions ), 00103 OptionsFromStreamPack::SetOptionsToTargetBase< 00104 CheckConvergence_Strategy >( target ) 00105 {} 00106 00107 00108 void CheckConvergence_StrategySetOptions::setOption( 00109 int option_num, 00110 const std::string& option_value ) 00111 { 00112 using OptionsFromStreamPack::StringToBool; 00113 00114 typedef CheckConvergence_Strategy target_t; 00115 switch( (local_EOptions)option_num ) 00116 { 00117 case SCALE_OPT_ERROR_BY: 00118 case SCALE_FEAS_ERROR_BY: 00119 case SCALE_COMP_ERROR_BY: 00120 { 00121 const std::string &option = option_value.c_str(); 00122 CheckConvergence_Strategy::EScaleKKTErrorBy scale_by = target_t::SCALE_BY_ONE; 00123 00124 if( option == "SCALE_BY_ONE" ) 00125 { scale_by = target_t::SCALE_BY_ONE; } 00126 else if( option == "SCALE_BY_NORM_2_X" ) 00127 { scale_by = target_t::SCALE_BY_NORM_2_X; } 00128 else if( option == "SCALE_BY_NORM_INF_X" ) 00129 { scale_by = target_t::SCALE_BY_NORM_INF_X; } 00130 else 00131 { 00132 throw std::invalid_argument( "Error, incorrect value for " 00133 "\"scale_kkt_error_by\". Only the options " 00134 "SCALE_BY_ONE, SCALE_BY_NORM_2_X, and SCALE_BY_NORM_INF_X " 00135 "are available" ); 00136 } 00137 00138 00139 if ((local_EOptions) option_num == SCALE_OPT_ERROR_BY) 00140 { 00141 target().scale_opt_error_by(scale_by); 00142 } 00143 else if ((local_EOptions) option_num == SCALE_FEAS_ERROR_BY) 00144 { 00145 target().scale_feas_error_by(scale_by); 00146 } 00147 else if ((local_EOptions) option_num == SCALE_COMP_ERROR_BY) 00148 { 00149 target().scale_comp_error_by(scale_by); 00150 } 00151 else 00152 { 00153 TEUCHOS_TEST_FOR_EXCEPTION( true, 00154 std::logic_error, 00155 "Unaccounted for option_num in CheckConvergence_Strategy.cpp" 00156 ); 00157 } 00158 00159 break; 00160 } 00161 case SCALE_OPT_ERROR_BY_GF: 00162 { 00163 target().scale_opt_error_by_Gf( 00164 StringToBool( "scale_opt_error_by_Gf", option_value.c_str() ) ); 00165 break; 00166 } 00167 default: 00168 TEUCHOS_TEST_FOR_EXCEPT(true); // Local error only? 00169 } 00170 } 00171 00172 } // end namespace MoochoPack
1.7.6.1