MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ConstrainedOptPack_QPSolverRelaxedQPSchurSetOptions.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include <assert.h>
43 #include <math.h>
44 
47 
48 // Define the options
49 namespace {
50 
51  const int local_num_options = 22;
52 
54  MAX_QP_ITER_FRAC
55  ,MAX_REAL_RUNTIME
56  ,INEQUALITY_PICK_POLICY
57  ,BOUND_TOL
58  ,INEQUALITY_TOL
59  ,EQUALITY_TOL
60  ,LOOSE_FEAS_TOL
61  ,DUAL_INFEAS_TOL
62  ,HUGE_PRIMAL_STEP
63  ,HUGE_DUAL_STEP
64  ,BIGM
65  ,WARNING_TOL
66  ,ERROR_TOL
67  ,ITER_REFINE_MIN_ITER
68  ,ITER_REFINE_MAX_ITER
69  ,ITER_REFINE_OPT_TOL
70  ,ITER_REFINE_FEAS_TOL
71  ,ITER_REFINE_AT_SOLUTION
72  ,PIVOT_WARNING_TOL
73  ,PIVOT_SINGULAR_TOL
74  ,PIVOT_WRONG_INERTIA_TOL
76  };
77 
78  const char* local_SOptions[local_num_options] = {
79  "max_qp_iter_frac"
80  ,"max_real_runtime"
81  ,"inequality_pick_policy"
82  ,"bounds_tol"
83  ,"inequality_tol"
84  ,"equality_tol"
85  ,"loose_feas_tol"
86  ,"dual_infeas_tol"
87  ,"huge_primal_step"
88  ,"huge_dual_step"
89  ,"bigM"
90  ,"warning_tol"
91  ,"error_tol"
92  ,"iter_refine_min_iter"
93  ,"iter_refine_max_iter"
94  ,"iter_refine_opt_tol"
95  ,"iter_refine_feas_tol"
96  ,"iter_refine_at_solution"
97  ,"pivot_warning_tol"
98  ,"pivot_singular_tol"
99  ,"pivot_wrong_inertia_tol"
100  ,"print_level"
101  };
102 
103 }
104 
105 namespace ConstrainedOptPack {
106 
108  QPSolverRelaxedQPSchur* target
109  , const char opt_grp_name[] )
110  : OptionsFromStreamPack::SetOptionsFromStreamNode(
111  opt_grp_name, local_num_options, local_SOptions )
112  , OptionsFromStreamPack::SetOptionsToTargetBase<
113  QPSolverRelaxedQPSchur >( target )
114 {}
115 
117  int option_num, const std::string& option_value )
118 {
120  typedef QPSolverRelaxedQPSchur target_t;
121  typedef QPSchurPack::ConstraintsRelaxedStd constr_t;
122  switch( (local_EOptions)option_num ) {
123  case MAX_QP_ITER_FRAC:
124  target().max_qp_iter_frac(std::fabs(std::atof(option_value.c_str())));
125  break;
126  case MAX_REAL_RUNTIME:
127  target().max_real_runtime(std::fabs(std::atof(option_value.c_str())));
128  break;
129  case INEQUALITY_PICK_POLICY:
130  if( option_value == "ADD_BOUNDS_THEN_MOST_VIOLATED_INEQUALITY" )
131  target().inequality_pick_policy( constr_t::ADD_BOUNDS_THEN_MOST_VIOLATED_INEQUALITY );
132  else if( option_value == "ADD_BOUNDS_THEN_FIRST_VIOLATED_INEQUALITY" )
133  target().inequality_pick_policy( constr_t::ADD_BOUNDS_THEN_FIRST_VIOLATED_INEQUALITY );
134  else if( option_value == "ADD_MOST_VIOLATED_BOUNDS_AND_INEQUALITY" )
135  target().inequality_pick_policy( constr_t::ADD_MOST_VIOLATED_BOUNDS_AND_INEQUALITY );
136  else
137  throw std::invalid_argument( "QPSolverRelaxedQPSchurSetOptions::"
138  "setOption(...) : Error, only the values of\n"
139  " ADD_BOUNDS_THEN_MOST_VIOLATED_INEQUALITY\n"
140  ", ADD_BOUNDS_THEN_FIRST_VIOLATED_INEQUALITY and"
141  " ADD_MOST_VIOLATED_BOUNDS_AND_INEQUALITY \nare valid for the option"
142  " \"QPSolverRelaxedQPSchur::inequality_pick_policy\"" );
143  break;
144  case BOUND_TOL:
145  target().bounds_tol(std::fabs(std::atof(option_value.c_str())));
146  break;
147  case INEQUALITY_TOL:
148  target().inequality_tol(std::fabs(std::atof(option_value.c_str())));
149  break;
150  case EQUALITY_TOL:
151  target().equality_tol(std::fabs(std::atof(option_value.c_str())));
152  break;
153  case LOOSE_FEAS_TOL:
154  target().loose_feas_tol(std::fabs(std::atof(option_value.c_str())));
155  break;
156  case DUAL_INFEAS_TOL:
157  target().dual_infeas_tol(std::fabs(std::atof(option_value.c_str())));
158  break;
159  case HUGE_PRIMAL_STEP:
160  target().huge_primal_step(std::fabs(std::atof(option_value.c_str())));
161  break;
162  case HUGE_DUAL_STEP:
163  target().huge_dual_step(std::fabs(std::atof(option_value.c_str())));
164  break;
165  case BIGM:
166  target().bigM(std::fabs(std::atof(option_value.c_str())));
167  break;
168  case WARNING_TOL:
169  target().warning_tol(std::fabs(std::atof(option_value.c_str())));
170  break;
171  case ERROR_TOL:
172  target().error_tol(std::fabs(std::atof(option_value.c_str())));
173  break;
174 
175  case ITER_REFINE_MIN_ITER:
176  target().iter_refine_min_iter(std::abs(std::atoi(option_value.c_str())));
177  break;
178  case ITER_REFINE_MAX_ITER:
179  target().iter_refine_max_iter(std::abs(std::atoi(option_value.c_str())));
180  break;
181  case ITER_REFINE_OPT_TOL:
182  target().iter_refine_opt_tol(std::fabs(std::atof(option_value.c_str())));
183  break;
184  case ITER_REFINE_FEAS_TOL:
185  target().iter_refine_feas_tol(std::fabs(std::atof(option_value.c_str())));
186  break;
187  case ITER_REFINE_AT_SOLUTION:
188  target().iter_refine_at_solution(StringToBool( "iter_refine_at_solution", option_value.c_str() ));
189  break;
190  case PIVOT_WARNING_TOL:
191  target().pivot_warning_tol(std::fabs(std::atof(option_value.c_str())));
192  break;
193  case PIVOT_SINGULAR_TOL:
194  target().pivot_singular_tol(std::fabs(std::atof(option_value.c_str())));
195  break;
196  case PIVOT_WRONG_INERTIA_TOL:
197  target().pivot_wrong_inertia_tol(std::fabs(std::atof(option_value.c_str())));
198  break;
199  case PRINT_LEVEL:
200  if( option_value == "USE_INPUT_ARG" )
201  target().print_level( target_t::USE_INPUT_ARG );
202  else if( option_value == "NO_OUTPUT" )
203  target().print_level( target_t::NO_OUTPUT );
204  else if( option_value == "OUTPUT_BASIC_INFO" )
205  target().print_level( target_t::OUTPUT_BASIC_INFO );
206  else if( option_value == "OUTPUT_ITER_SUMMARY" )
207  target().print_level( target_t::OUTPUT_ITER_SUMMARY );
208  else if( option_value == "OUTPUT_ITER_STEPS" )
209  target().print_level( target_t::OUTPUT_ITER_STEPS );
210  else if( option_value == "OUTPUT_ACT_SET" )
211  target().print_level( target_t::OUTPUT_ACT_SET );
212  else if( option_value == "OUTPUT_ITER_QUANTITIES" )
213  target().print_level( target_t::OUTPUT_ITER_QUANTITIES );
214  else
215  throw std::invalid_argument( "QPSolverRelaxedQPSchurSetOptions::"
216  "setOption(...) : Error, only the values of USE_INPUT_ARG, NO_OUTPUT"
217  ", OUTPUT_BASIC_INFO, OUTPUT_ITER_SUMMARY\n"
218  ", OUTPUT_ITER_STEPS, OUTPUT_ACT_SET and"
219  " OUTPUT_ITER_QUANTITIES \nare valid for the option"
220  " \"QPSolverRelaxedQPSchur::print_level\"" );
221  break;
222  default:
223  TEUCHOS_TEST_FOR_EXCEPT(true); // Local error only?
224  }
225 }
226 
227 } // end namespace ConstrainedOptPack
bool StringToBool(const char *opt_name, const char *str)
Convert a string "true" or "false" into bool #true# or #false#.
void abs(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = abs(vs_rhs)
Solves Quadratic Programming (QP) problems using QPSchur.
QPSolverRelaxedQPSchurSetOptions(QPSolverRelaxedQPSchur *target=0, const char opt_grp_name[]="QPSolverRelaxedQPSchur")
Constraints subclass that is used to represent generic varaible bounds, and general inequality and eq...
void setOption(int option_num, const std::string &option_value)
Overridden from SetOptionsFromStreamNode.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
const std::string & option_value(OptionsGroup::const_iterator &itr)