ROL
ROL_ParameterListConverters.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef ROL_PARAMETER_LIST_CONVERTERS_H
11 #define ROL_PARAMETER_LIST_CONVERTERS_H
12 
13 #include <map>
14 #include "ROL_Types.hpp"
15 #include "ROL_ParameterList.hpp"
16 
17 
18 namespace ROL {
19 
20 namespace StringList {
21 
23 inline std::vector<std::string> join( const std::string &s1,
24  const std::string &s2 ) {
25  std::vector<std::string> v;
26  v.push_back(s1);
27  v.push_back(s2);
28 
29  return v;
30 }
31 
33 inline std::vector<std::string> join( const std::string &s1,
34  const std::string &s2,
35  const std::string &s3 ) {
36  std::vector<std::string> v;
37  v.push_back(s1);
38  v.push_back(s2);
39  v.push_back(s3);
40 
41  return v;
42 }
43 
45 inline std::vector<std::string> join( const std::string &s1,
46  const std::string &s2,
47  const std::string &s3,
48  const std::string &s4 ) {
49  std::vector<std::string> v;
50  v.push_back(s1);
51  v.push_back(s2);
52  v.push_back(s3);
53  v.push_back(s4);
54 
55  return v;
56 }
57 
59 inline std::vector<std::string> join( const std::string &s1,
60  const std::string &s2,
61  const std::string &s3,
62  const std::string &s4,
63  const std::string &s5 ) {
64  std::vector<std::string> v;
65  v.push_back(s1);
66  v.push_back(s2);
67  v.push_back(s3);
68  v.push_back(s4);
69  v.push_back(s5);
70 
71  return v;
72 }
73 
74 } // namespace StringList
75 
76 template<class ParameterType>
77 void setParameter( ROL::ParameterList &parlist,
78  const std::vector<std::string> &location,
79  const std::vector<std::string>::iterator iter,
80  ParameterType value ) {
81 
82  if( iter == location.end()-1 ) { // Key name
83  parlist.set(*iter,value);
84  }
85  else { // sublist
86  ROL::ParameterList &sublist = parlist.sublist(*iter);
87  setParameter(sublist,location,iter+1,value);
88  }
89 
90 
91 }
92 
93 
94 
96 inline void tierParameterList( ROL::ParameterList &outList,
97  const ROL::ParameterList &inList ) {
98 
99  using StringList::join;
100 
101  typedef std::string Str;
102  typedef std::vector<Str> Vec;
103  typedef std::map<Str,Vec> Map;
104  typedef ParameterList::ConstIterator IterPL;
105  typedef typename Vec::iterator IterVec;
106  typedef typename Map::iterator IterMap;
107 
108  Map dict;
109 
110  // Original flat list name heirarchical list name
111  dict["Use Inexact Gradient"] = join("General","Inexact Gradient");
112  dict["Use Inexact Objective Function"] = join("General","Inexact Objective Function");
113  dict["Use Inexact Hessian-Times-A-Vector"] = join("General","Inexact Hessian-Times-A-Vector");
114  dict["Use Projected Gradient Criticality Measure"] = join("General","Projected Gradient Criticality Measure");
115  dict["Scale for Epsilon Active Sets"] = join("General","Scale for Epsilon Active Sets");
116 
117  dict["Absolute Krylov Tolerance"] = join("General","Krylov","Absolute Tolerance");
118  dict["Relative Krylov Tolerance"] = join("General","Krylov","Relative Tolerance");
119  dict["Maximum Number of Krylov Iterations"] = join("General","Krylov","Iteration Limit");
120  dict["Krylov Type"] = join("General","Krylov","Type");
121 
122  dict["Barzilai-Borwein"] = join("General","Secant","Barzilai-Borwein");
123  dict["Maximum Secant Storage"] = join("General","Secant","Maximum Storage");
124  dict["Secant Type"] = join("General","Secant","Type");
125  dict["Use Secant Hessian-Times-A-Vector"] = join("General","Secant","Use as Hessian");
126  dict["Use Secant Preconditioning"] = join("General","Secant","Use as Preconditioner");
127 
128  dict["Gradient Tolerance"] = join("Status Test","Gradient Tolerance");
129  dict["Maximum Number of Iterations"] = join("Status Test","Iteration Limit");
130  dict["Step Tolerance"] = join("Status Test","Step Tolerance");
131 
132  dict["Accept Last Alpha"] = join("Step","Line Search","Accept Last Alpha");
133  dict["Accept Linesearch Minimizer"] = join("Step","Line Search","Accept Linesearch Minimizer");
134  dict["Maximum Number of Function Evaluations"] = join("Step","Line Search","Function Evaluation Limit");
135  dict["Initial Linesearch Parameter"] = join("Step","Line Search","Initial Step Size");
136  dict["Sufficient Decrease Parameter"] = join("Step","Line Search","Sufficient Decrease Tolerance");
137  dict["User Defined Linesearch Parameter"] = join("Step","Line Search","User Defined Initial Step Size");
138 
139  dict["Curvature Conditions Parameter"] = join("Step","Line Search","Curvature Condition","General Parameter");
140  dict["Curvature Conditions Parameter: Generalized Wolfe"] = join("Step","Line Search","Curvature Condition","Generalized Wolfe Parameter");
141  dict["Linesearch Curvature Condition"] = join("Step","Line Search","Curvature Condition","Type");
142 
143  dict["Nonlinear CG Type"] = join("Step","Line Search","Descent Method","Nonlinear CG Type");
144  dict["Descent Type"] = join("Step","Line Search","Descent Method","Type");
145 
146  dict["Backtracking Rate"] = join("Step","Line Search","Line-Search Method","Backtracking Rate");
147  dict["Bracketing Tolerance"] = join("Step","Line Search","Line-Search Method","Bracketing Tolerance");
148  dict["Linesearch Type"] = join("Step","Line Search","Line-Search Method","Type");
149 
150  dict["Initial Trust-Region Radius"] = join("Step","Trust Region","Initial Radius");
151  dict["Maximum Trust-Region Radius"] = join("Step","Trust Region","Maximum Radius");
152  dict["Radius Growing Threshold"] = join("Step","Trust Region","Radius Growing Threshold");
153  dict["Radius Growing Rate"] = join("Step","Trust Region","Radius Growing Rate");
154  dict["Radius Shrinking Threshold"] = join("Step","Trust Region","Radius Shrinking Threshold");
155  dict["Trust-Region Safeguard"] = join("Step","Trust Region","Safeguard Size");
156  dict["Trust-Region Subproblem Solver Type"] = join("Step","Trust Region","Subproblem Solver");
157  dict["Step Acceptance Parameter"] = join("Step","Trust Region","Step Acceptance Threshold");
158 
159  dict["Gradient Update Relative Tolerance"] = join("Step","Trust Region","Gradient","Relative Tolerance");
160  dict["Gradient Update Tolerance Scaling"] = join("Step","Trust Region","Gradient","Tolerance Scaling");
161  dict["Value Update Exponent"] = join("Step","Trust Region","Inexact","Value","Exponent");
162  dict["Value Update Forcing Sequence Initial Value"] = join("Step","Trust Region","Inexact","Value","Forcing Sequence Initial Value");
163  dict["Value Update Forcing Sequence Reduction Factor"] = join("Step","Trust Region","Inexact","Value","Forcing Sequence Reduction Factor");
164  dict["Value Update Forcing Sequence Update Frequency"] = join("Step","Trust Region","Inexact","Value","Forcing Sequence Update Frequency");
165  dict["Value Update Tolerance Scaling"] = join("Step","Trust Region","Inexact","Value","Tolerance Scaling");
166 
167 
168  // Add duplicate entries with unformatted keys
169  for(IterMap itmap = dict.begin(); itmap != dict.end(); ++itmap) {
170  Str key = itmap->first;
171  Vec value = itmap->second;
172  dict[removeStringFormat(key)] = value;
173  }
174 
175 
176  // Iterate over parameter list
177  for(IterPL itpl = inList.begin(); itpl != inList.end(); ++itpl) {
178 
179  // Get name of old key
180  Str key( inList.name(itpl) );
181 
182  // Look up location/name of new key
183  Vec location = dict[removeStringFormat(key)];
184 
185  // Skip if not found in map
186  if(location.size() != 0) {
187 
188  IterVec itvec = location.begin();
189 
190  if( inList.isType<bool>(key) ) {
191  bool value = inList.get<bool>( key );
192  setParameter( outList, location, itvec, value );
193  }
194  else if( inList.isType<int>(key) ) {
195  int value = inList.get<int>( key );
196  setParameter( outList, location, itvec, value );
197  }
198  else if( inList.isType<double>(key) ) {
199  double value = inList.get<double>( key );
200  setParameter( outList, location, itvec, value );
201  }
202  else if( inList.isType<std::string>(key) ) {
203  std::string value = inList.get<std::string>( key );
204  setParameter( outList, location, itvec, value );
205  }
206  else {
207  ROL_TEST_FOR_EXCEPTION( true, std::invalid_argument,
208  ">>>Error: Unhandled parameter type." );
209  }
210  }
211 
212  }
213 }
214 
215 } // namespace ROL
216 
217 #endif
void setParameter(ROL::ParameterList &parlist, const std::vector< std::string > &location, const std::vector< std::string >::iterator iter, ParameterType value)
Contains definitions of custom data types in ROL.
std::string removeStringFormat(std::string s)
Definition: ROL_Types.hpp:215
ROL::Objective_SimOpt value
std::vector< std::string > join(const std::string &s1, const std::string &s2)
Helper function for making vectors of strings.
void tierParameterList(ROL::ParameterList &outList, const ROL::ParameterList &inList)
Produce a heirarchical parameter list using the new names from a flat list of the old names...