|
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 #include <math.h> 00044 00045 #include "MoochoPack_NLPSolverClientInterfaceSetOptions.hpp" 00046 #include "OptionsFromStreamPack_StringToBool.hpp" 00047 00048 // Define the options 00049 namespace { 00050 00051 const int local_num_options = 13; 00052 00053 enum local_EOptions { 00054 MAX_ITER, 00055 MAX_RUN_TIME, 00056 OPT_TOL, 00057 FEAS_TOL, 00058 COMP_TOL, 00059 STEP_TOL, 00060 JOURNAL_OUTPUT_LEVEL, 00061 NULL_SPACE_JOURNAL_OUTPUT_LEVEL, 00062 JOURNAL_PRINT_DIGITS, 00063 CHECK_RESULTS, 00064 CALC_CONDITIONING, 00065 CALC_MATRIX_NORMS, 00066 CALC_MATRIX_INFO_NULL_SPACE_ONLY 00067 }; 00068 00069 const char* local_SOptions[local_num_options] = { 00070 ("max_iter"), 00071 ("max_run_time"), 00072 ("opt_tol"), 00073 ("feas_tol"), 00074 ("comp_tol"), 00075 ("step_tol"), 00076 ("journal_output_level"), 00077 ("null_space_journal_output_level"), 00078 ("journal_print_digits"), 00079 ("check_results"), 00080 ("calc_conditioning"), 00081 ("calc_matrix_norms"), 00082 ("calc_matrix_info_null_space_only") 00083 }; 00084 00085 } 00086 00087 namespace MoochoPack { 00088 00089 NLPSolverClientInterfaceSetOptions::NLPSolverClientInterfaceSetOptions( 00090 NLPSolverClientInterface* target 00091 , const char opt_grp_name[] ) 00092 : OptionsFromStreamPack::SetOptionsFromStreamNode( 00093 opt_grp_name, local_num_options, local_SOptions ) 00094 , OptionsFromStreamPack::SetOptionsToTargetBase< 00095 NLPSolverClientInterface >( target ) 00096 {} 00097 00098 void NLPSolverClientInterfaceSetOptions::setOption( 00099 int option_num, const std::string& option_value ) 00100 { 00101 namespace ofsp = OptionsFromStreamPack; 00102 using ofsp::StringToBool; 00103 00104 typedef NLPSolverClientInterface target_t; 00105 switch( (local_EOptions)option_num ) { 00106 case MAX_ITER: 00107 target().max_iter(std::abs(std::atoi(option_value.c_str()))); 00108 break; 00109 case MAX_RUN_TIME: 00110 target().max_run_time(std::fabs(std::atof(option_value.c_str()))); 00111 break; 00112 case OPT_TOL: 00113 target().opt_tol(std::fabs(std::atof(option_value.c_str()))); 00114 break; 00115 case FEAS_TOL: 00116 target().feas_tol(std::fabs(std::atof(option_value.c_str()))); 00117 break; 00118 case COMP_TOL: 00119 target().comp_tol(std::fabs(std::atof(option_value.c_str()))); 00120 break; 00121 case STEP_TOL: 00122 target().step_tol(std::fabs(std::atof(option_value.c_str()))); 00123 break; 00124 case JOURNAL_OUTPUT_LEVEL: 00125 { 00126 if( option_value == "PRINT_NOTHING" ) 00127 target().journal_output_level(PRINT_NOTHING); 00128 else if( option_value == "PRINT_BASIC_ALGORITHM_INFO" ) 00129 target().journal_output_level(PRINT_BASIC_ALGORITHM_INFO); 00130 else if( option_value == "PRINT_ALGORITHM_STEPS" ) 00131 target().journal_output_level(PRINT_ALGORITHM_STEPS); 00132 else if( option_value == "PRINT_ACTIVE_SET" ) 00133 target().journal_output_level(PRINT_ACTIVE_SET); 00134 else if( option_value == "PRINT_VECTORS" ) 00135 target().journal_output_level(PRINT_VECTORS); 00136 else if( option_value == "PRINT_ITERATION_QUANTITIES" ) 00137 target().journal_output_level(PRINT_ITERATION_QUANTITIES); 00138 else 00139 TEUCHOS_TEST_FOR_EXCEPTION( 00140 true,std::invalid_argument 00141 ,"NLPSolverClientInterfaceSetOptions::setOption(...) : " 00142 "Error, incorrect value \""<<option_value<<"\" for \"journal_output_level\"." ); 00143 if((int)target().null_space_journal_output_level() <= (int)PRINT_ALGORITHM_STEPS) 00144 target().null_space_journal_output_level(target().journal_output_level()); 00145 break; 00146 } 00147 case NULL_SPACE_JOURNAL_OUTPUT_LEVEL: 00148 { 00149 if( option_value == "DEFAULT" ) 00150 target().null_space_journal_output_level(target().journal_output_level()); 00151 else if( option_value == "PRINT_ACTIVE_SET" ) 00152 target().null_space_journal_output_level(PRINT_ACTIVE_SET); 00153 else if( option_value == "PRINT_VECTORS" ) 00154 target().null_space_journal_output_level(PRINT_VECTORS); 00155 else if( option_value == "PRINT_ITERATION_QUANTITIES" ) 00156 target().null_space_journal_output_level(PRINT_ITERATION_QUANTITIES); 00157 else 00158 TEUCHOS_TEST_FOR_EXCEPTION( 00159 true,std::invalid_argument 00160 ,"NLPSolverClientInterfaceSetOptions::setOption(...) : " 00161 "Error, incorrect value \""<<option_value<<"\" for \"null_space_journal_output_level\"." ); 00162 break; 00163 } 00164 case JOURNAL_PRINT_DIGITS: 00165 target().journal_print_digits(std::abs(std::atoi(option_value.c_str()))); 00166 break; 00167 case CHECK_RESULTS: 00168 target().check_results( 00169 StringToBool( "check_results", option_value.c_str() ) 00170 ); 00171 break; 00172 case CALC_CONDITIONING: 00173 target().calc_conditioning( 00174 StringToBool( "calc_conditioning", option_value.c_str() ) 00175 ); 00176 break; 00177 case CALC_MATRIX_NORMS: 00178 target().calc_matrix_norms( 00179 StringToBool( "calc_matrix_norms", option_value.c_str() ) 00180 ); 00181 break; 00182 case CALC_MATRIX_INFO_NULL_SPACE_ONLY: 00183 target().calc_matrix_info_null_space_only( 00184 StringToBool( "calc_matrix_info_null_space_only", option_value.c_str() ) 00185 ); 00186 break; 00187 default: 00188 TEUCHOS_TEST_FOR_EXCEPT(true); // Local error only? 00189 } 00190 } 00191 00192 } // end namespace MoochoPack
1.7.6.1