MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MoochoPack_NLPSolverClientInterfaceSetOptions.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 = 13;
52 
54  MAX_ITER,
55  MAX_RUN_TIME,
56  OPT_TOL,
57  FEAS_TOL,
58  COMP_TOL,
59  STEP_TOL,
60  JOURNAL_OUTPUT_LEVEL,
61  NULL_SPACE_JOURNAL_OUTPUT_LEVEL,
62  JOURNAL_PRINT_DIGITS,
63  CHECK_RESULTS,
64  CALC_CONDITIONING,
65  CALC_MATRIX_NORMS,
66  CALC_MATRIX_INFO_NULL_SPACE_ONLY
67 };
68 
69 const char* local_SOptions[local_num_options] = {
70  ("max_iter"),
71  ("max_run_time"),
72  ("opt_tol"),
73  ("feas_tol"),
74  ("comp_tol"),
75  ("step_tol"),
76  ("journal_output_level"),
77  ("null_space_journal_output_level"),
78  ("journal_print_digits"),
79  ("check_results"),
80  ("calc_conditioning"),
81  ("calc_matrix_norms"),
82  ("calc_matrix_info_null_space_only")
83 };
84 
85 }
86 
87 namespace MoochoPack {
88 
91  , const char opt_grp_name[] )
92  : OptionsFromStreamPack::SetOptionsFromStreamNode(
93  opt_grp_name, local_num_options, local_SOptions )
94  , OptionsFromStreamPack::SetOptionsToTargetBase<
95  NLPSolverClientInterface >( target )
96 {}
97 
99  int option_num, const std::string& option_value )
100 {
101  namespace ofsp = OptionsFromStreamPack;
102  using ofsp::StringToBool;
103 
104  typedef NLPSolverClientInterface target_t;
105  switch( (local_EOptions)option_num ) {
106  case MAX_ITER:
107  target().max_iter(std::abs(std::atoi(option_value.c_str())));
108  break;
109  case MAX_RUN_TIME:
110  target().max_run_time(std::fabs(std::atof(option_value.c_str())));
111  break;
112  case OPT_TOL:
113  target().opt_tol(std::fabs(std::atof(option_value.c_str())));
114  break;
115  case FEAS_TOL:
116  target().feas_tol(std::fabs(std::atof(option_value.c_str())));
117  break;
118  case COMP_TOL:
119  target().comp_tol(std::fabs(std::atof(option_value.c_str())));
120  break;
121  case STEP_TOL:
122  target().step_tol(std::fabs(std::atof(option_value.c_str())));
123  break;
124  case JOURNAL_OUTPUT_LEVEL:
125  {
126  if( option_value == "PRINT_NOTHING" )
127  target().journal_output_level(PRINT_NOTHING);
128  else if( option_value == "PRINT_BASIC_ALGORITHM_INFO" )
129  target().journal_output_level(PRINT_BASIC_ALGORITHM_INFO);
130  else if( option_value == "PRINT_ALGORITHM_STEPS" )
131  target().journal_output_level(PRINT_ALGORITHM_STEPS);
132  else if( option_value == "PRINT_ACTIVE_SET" )
133  target().journal_output_level(PRINT_ACTIVE_SET);
134  else if( option_value == "PRINT_VECTORS" )
135  target().journal_output_level(PRINT_VECTORS);
136  else if( option_value == "PRINT_ITERATION_QUANTITIES" )
137  target().journal_output_level(PRINT_ITERATION_QUANTITIES);
138  else
140  true,std::invalid_argument
141  ,"NLPSolverClientInterfaceSetOptions::setOption(...) : "
142  "Error, incorrect value \""<<option_value<<"\" for \"journal_output_level\"." );
143  if((int)target().null_space_journal_output_level() <= (int)PRINT_ALGORITHM_STEPS)
144  target().null_space_journal_output_level(target().journal_output_level());
145  break;
146  }
147  case NULL_SPACE_JOURNAL_OUTPUT_LEVEL:
148  {
149  if( option_value == "DEFAULT" )
150  target().null_space_journal_output_level(target().journal_output_level());
151  else if( option_value == "PRINT_ACTIVE_SET" )
152  target().null_space_journal_output_level(PRINT_ACTIVE_SET);
153  else if( option_value == "PRINT_VECTORS" )
154  target().null_space_journal_output_level(PRINT_VECTORS);
155  else if( option_value == "PRINT_ITERATION_QUANTITIES" )
156  target().null_space_journal_output_level(PRINT_ITERATION_QUANTITIES);
157  else
159  true,std::invalid_argument
160  ,"NLPSolverClientInterfaceSetOptions::setOption(...) : "
161  "Error, incorrect value \""<<option_value<<"\" for \"null_space_journal_output_level\"." );
162  break;
163  }
164  case JOURNAL_PRINT_DIGITS:
165  target().journal_print_digits(std::abs(std::atoi(option_value.c_str())));
166  break;
167  case CHECK_RESULTS:
168  target().check_results(
169  StringToBool( "check_results", option_value.c_str() )
170  );
171  break;
172  case CALC_CONDITIONING:
173  target().calc_conditioning(
174  StringToBool( "calc_conditioning", option_value.c_str() )
175  );
176  break;
177  case CALC_MATRIX_NORMS:
178  target().calc_matrix_norms(
179  StringToBool( "calc_matrix_norms", option_value.c_str() )
180  );
181  break;
182  case CALC_MATRIX_INFO_NULL_SPACE_ONLY:
183  target().calc_matrix_info_null_space_only(
184  StringToBool( "calc_matrix_info_null_space_only", option_value.c_str() )
185  );
186  break;
187  default:
188  TEUCHOS_TEST_FOR_EXCEPT(true); // Local error only?
189  }
190 }
191 
192 } // end namespace MoochoPack
bool StringToBool(const char *opt_name, const char *str)
Convert a string "true" or "false" into bool #true# or #false#.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void abs(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = abs(vs_rhs)
NLPSolverClientInterfaceSetOptions(NLPSolverClientInterface *target=0, const char opt_grp_name[]="NLPSolverClientInterface")
void setOption(int option_num, const std::string &option_value)
Overridden from SetOptionsFromStreamNode.
This is the most basic interface that clients use to solve an NLP.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
const std::string & option_value(OptionsGroup::const_iterator &itr)