MOOCHO (Single Doxygen Collection) Version of the Day
ConstrainedOptPack_QPSolverRelaxedQPSchurSetOptions.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 // 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 "ConstrainedOptPack_QPSolverRelaxedQPSchurSetOptions.hpp"
00046 #include "OptionsFromStreamPack_StringToBool.hpp"
00047 
00048 // Define the options
00049 namespace {
00050 
00051   const int local_num_options = 22;
00052 
00053   enum local_EOptions {
00054     MAX_QP_ITER_FRAC
00055     ,MAX_REAL_RUNTIME
00056     ,INEQUALITY_PICK_POLICY
00057     ,BOUND_TOL
00058     ,INEQUALITY_TOL
00059     ,EQUALITY_TOL
00060     ,LOOSE_FEAS_TOL
00061     ,DUAL_INFEAS_TOL
00062     ,HUGE_PRIMAL_STEP
00063     ,HUGE_DUAL_STEP
00064     ,BIGM
00065     ,WARNING_TOL
00066     ,ERROR_TOL
00067     ,ITER_REFINE_MIN_ITER
00068     ,ITER_REFINE_MAX_ITER
00069     ,ITER_REFINE_OPT_TOL
00070     ,ITER_REFINE_FEAS_TOL
00071     ,ITER_REFINE_AT_SOLUTION
00072     ,PIVOT_WARNING_TOL
00073     ,PIVOT_SINGULAR_TOL
00074     ,PIVOT_WRONG_INERTIA_TOL
00075     ,PRINT_LEVEL
00076   };
00077 
00078   const char* local_SOptions[local_num_options] = {
00079     "max_qp_iter_frac"
00080     ,"max_real_runtime"
00081     ,"inequality_pick_policy"
00082     ,"bounds_tol"
00083     ,"inequality_tol"
00084     ,"equality_tol"
00085     ,"loose_feas_tol"
00086     ,"dual_infeas_tol"
00087     ,"huge_primal_step"
00088     ,"huge_dual_step"
00089     ,"bigM"
00090     ,"warning_tol"
00091     ,"error_tol"
00092     ,"iter_refine_min_iter"
00093     ,"iter_refine_max_iter"
00094     ,"iter_refine_opt_tol"
00095     ,"iter_refine_feas_tol"
00096     ,"iter_refine_at_solution"
00097     ,"pivot_warning_tol"
00098     ,"pivot_singular_tol"
00099     ,"pivot_wrong_inertia_tol"
00100     ,"print_level"
00101   };
00102 
00103 }
00104 
00105 namespace ConstrainedOptPack {
00106 
00107 QPSolverRelaxedQPSchurSetOptions::QPSolverRelaxedQPSchurSetOptions(
00108         QPSolverRelaxedQPSchur* target
00109       , const char opt_grp_name[] )
00110   : OptionsFromStreamPack::SetOptionsFromStreamNode(
00111         opt_grp_name, local_num_options, local_SOptions )
00112     , OptionsFromStreamPack::SetOptionsToTargetBase<
00113       QPSolverRelaxedQPSchur >( target )
00114 {}
00115 
00116 void QPSolverRelaxedQPSchurSetOptions::setOption(
00117   int option_num, const std::string& option_value )
00118 {
00119   using OptionsFromStreamPack::StringToBool;
00120   typedef QPSolverRelaxedQPSchur target_t;
00121   typedef QPSchurPack::ConstraintsRelaxedStd constr_t;
00122   switch( (local_EOptions)option_num ) {
00123     case MAX_QP_ITER_FRAC:
00124       target().max_qp_iter_frac(std::fabs(std::atof(option_value.c_str())));
00125       break;
00126     case MAX_REAL_RUNTIME:
00127       target().max_real_runtime(std::fabs(std::atof(option_value.c_str())));
00128       break;
00129     case INEQUALITY_PICK_POLICY:
00130       if(     option_value == "ADD_BOUNDS_THEN_MOST_VIOLATED_INEQUALITY" )
00131         target().inequality_pick_policy( constr_t::ADD_BOUNDS_THEN_MOST_VIOLATED_INEQUALITY );
00132       else if(  option_value == "ADD_BOUNDS_THEN_FIRST_VIOLATED_INEQUALITY" )
00133         target().inequality_pick_policy( constr_t::ADD_BOUNDS_THEN_FIRST_VIOLATED_INEQUALITY );
00134       else if(  option_value == "ADD_MOST_VIOLATED_BOUNDS_AND_INEQUALITY" )
00135         target().inequality_pick_policy( constr_t::ADD_MOST_VIOLATED_BOUNDS_AND_INEQUALITY );
00136       else
00137         throw std::invalid_argument( "QPSolverRelaxedQPSchurSetOptions::"
00138           "setOption(...) : Error, only the values of\n"
00139           " ADD_BOUNDS_THEN_MOST_VIOLATED_INEQUALITY\n"
00140           ", ADD_BOUNDS_THEN_FIRST_VIOLATED_INEQUALITY and"
00141           " ADD_MOST_VIOLATED_BOUNDS_AND_INEQUALITY \nare valid for the option"
00142           " \"QPSolverRelaxedQPSchur::inequality_pick_policy\"" );
00143       break;
00144     case BOUND_TOL:
00145       target().bounds_tol(std::fabs(std::atof(option_value.c_str())));
00146       break;
00147     case INEQUALITY_TOL:
00148       target().inequality_tol(std::fabs(std::atof(option_value.c_str())));
00149       break;
00150     case EQUALITY_TOL:
00151       target().equality_tol(std::fabs(std::atof(option_value.c_str())));
00152       break;
00153     case LOOSE_FEAS_TOL:
00154       target().loose_feas_tol(std::fabs(std::atof(option_value.c_str())));
00155       break;
00156     case DUAL_INFEAS_TOL:
00157       target().dual_infeas_tol(std::fabs(std::atof(option_value.c_str())));
00158       break;
00159     case HUGE_PRIMAL_STEP:
00160       target().huge_primal_step(std::fabs(std::atof(option_value.c_str())));
00161       break;
00162     case HUGE_DUAL_STEP:
00163       target().huge_dual_step(std::fabs(std::atof(option_value.c_str())));
00164       break;
00165     case BIGM:
00166       target().bigM(std::fabs(std::atof(option_value.c_str())));
00167       break;
00168     case WARNING_TOL:
00169       target().warning_tol(std::fabs(std::atof(option_value.c_str())));
00170       break;
00171     case ERROR_TOL:
00172       target().error_tol(std::fabs(std::atof(option_value.c_str())));
00173       break;
00174 
00175     case ITER_REFINE_MIN_ITER:
00176       target().iter_refine_min_iter(std::abs(std::atoi(option_value.c_str())));
00177       break;
00178     case ITER_REFINE_MAX_ITER:
00179       target().iter_refine_max_iter(std::abs(std::atoi(option_value.c_str())));
00180       break;
00181     case ITER_REFINE_OPT_TOL:
00182       target().iter_refine_opt_tol(std::fabs(std::atof(option_value.c_str())));
00183       break;
00184     case ITER_REFINE_FEAS_TOL:
00185       target().iter_refine_feas_tol(std::fabs(std::atof(option_value.c_str())));
00186       break;
00187     case ITER_REFINE_AT_SOLUTION:
00188       target().iter_refine_at_solution(StringToBool( "iter_refine_at_solution", option_value.c_str() ));
00189       break;
00190     case PIVOT_WARNING_TOL:
00191       target().pivot_warning_tol(std::fabs(std::atof(option_value.c_str())));
00192       break;
00193     case PIVOT_SINGULAR_TOL:
00194       target().pivot_singular_tol(std::fabs(std::atof(option_value.c_str())));
00195       break;
00196       case PIVOT_WRONG_INERTIA_TOL:
00197       target().pivot_wrong_inertia_tol(std::fabs(std::atof(option_value.c_str())));
00198       break;
00199     case PRINT_LEVEL:
00200       if(     option_value == "USE_INPUT_ARG" )
00201         target().print_level( target_t::USE_INPUT_ARG );
00202       else if(  option_value == "NO_OUTPUT" )
00203         target().print_level( target_t::NO_OUTPUT );
00204       else if(  option_value == "OUTPUT_BASIC_INFO" )
00205         target().print_level( target_t::OUTPUT_BASIC_INFO );
00206       else if(  option_value == "OUTPUT_ITER_SUMMARY" )
00207         target().print_level( target_t::OUTPUT_ITER_SUMMARY );
00208       else if(  option_value == "OUTPUT_ITER_STEPS" )
00209         target().print_level( target_t::OUTPUT_ITER_STEPS );
00210       else if(  option_value == "OUTPUT_ACT_SET" )
00211         target().print_level( target_t::OUTPUT_ACT_SET );
00212       else if(  option_value == "OUTPUT_ITER_QUANTITIES" )
00213         target().print_level( target_t::OUTPUT_ITER_QUANTITIES );
00214       else
00215         throw std::invalid_argument( "QPSolverRelaxedQPSchurSetOptions::"
00216           "setOption(...) : Error, only the values of USE_INPUT_ARG, NO_OUTPUT"
00217           ", OUTPUT_BASIC_INFO, OUTPUT_ITER_SUMMARY\n"
00218           ", OUTPUT_ITER_STEPS, OUTPUT_ACT_SET and"
00219           " OUTPUT_ITER_QUANTITIES \nare valid for the option"
00220           " \"QPSolverRelaxedQPSchur::print_level\"" );
00221       break;
00222     default:
00223       TEUCHOS_TEST_FOR_EXCEPT(true);  // Local error only?
00224   }
00225 }
00226 
00227 } // end namespace ConstrainedOptPack
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines