MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MoochoPack_LineSearchFilter_StepSetOptions.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 
46 #include "Teuchos_Assert.hpp"
47 
48 // Define the options
49 namespace {
50 
51 const int local_num_options = 11;
52 
54  {
55  GAMMA_THETA
56  ,GAMMA_F
57  ,F_MIN
58  ,GAMMA_ALPHA
59  ,DELTA
60  ,S_THETA
61  ,S_F
62  ,THETA_SMALL_FACT
63  ,THETA_MAX
64  ,ETA_F
65  ,BACK_TRACK_FRAC
66  };
67 
68 const char* local_SOptions[local_num_options] =
69  {
70  "gamma_theta"
71  ,"gamma_f"
72  ,"f_min"
73  ,"gamma_alpha"
74  ,"delta"
75  ,"s_theta"
76  ,"s_f"
77  ,"theta_small_fact"
78  ,"theta_max"
79  ,"eta_f"
80  ,"back_track_frac"
81  };
82 
83 }
84 
85 namespace MoochoPack {
86 
87 LineSearchFilter_StepSetOptions::LineSearchFilter_StepSetOptions(
88  LineSearchFilter_Step* target
89  , const char opt_grp_name[] )
90  :
91  OptionsFromStreamPack::SetOptionsFromStreamNode(
92  opt_grp_name, local_num_options, local_SOptions ),
93  OptionsFromStreamPack::SetOptionsToTargetBase< LineSearchFilter_Step >( target )
94  {
95  }
96 
97 void LineSearchFilter_StepSetOptions::setOption(
98  int option_num, const std::string& option_value )
99  {
101 
102  typedef LineSearchFilter_Step target_t;
103  switch( (local_EOptions)option_num ) {
104  case GAMMA_THETA:
105  target().gamma_theta(std::atof(option_value.c_str()));
106  break;
107  case GAMMA_F:
108  target().gamma_f(std::atof(option_value.c_str()));
109  break;
110  case F_MIN: {
111  if( option_value == "UNBOUNDED" )
112  target().f_min(target_t::F_MIN_UNBOUNDED);
113  else
114  target().f_min(std::atof(option_value.c_str()));
115  break;
116  }
117  case GAMMA_ALPHA:
118  target().gamma_alpha(std::atof(option_value.c_str()));
119  break;
120  case DELTA:
121  target().delta(std::atof(option_value.c_str()));
122  break;
123  case S_THETA:
124  target().s_theta(std::atof(option_value.c_str()));
125  break;
126  case S_F:
127  target().s_f(std::atof(option_value.c_str()));
128  break;
129  case THETA_SMALL_FACT:
130  target().theta_small_fact(std::atof(option_value.c_str()));
131  break;
132  case THETA_MAX:
133  target().theta_max(std::atof(option_value.c_str()));
134  break;
135  case ETA_F:
136  target().eta_f(std::atof(option_value.c_str()));
137  break;
138  case BACK_TRACK_FRAC:
139  target().back_track_frac(std::atof(option_value.c_str()));
140  break;
141  default:
142  TEUCHOS_TEST_FOR_EXCEPT(true); // Local error only?
143  }
144  }
145 
146 } // 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_EXCEPT(throw_exception_test)
const std::string & option_value(OptionsGroup::const_iterator &itr)