MoochoPack_NLPSolverClientInterfaceSetOptions.cpp

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

Generated on Wed May 12 21:32:13 2010 for MoochoPack : Framework for Large-Scale Optimization Algorithms by  doxygen 1.4.7