67 #include "json/json.h"
68 #include "Teuchos_ParameterList.hpp"
76 void addJSONPairToPL(
const Json::Value& block,
const std::string &key,ROL::ParameterList& parlist);
87 const std::string &key,
88 ROL::ParameterList& parlist) {
90 Json::Value val = block[key];
93 parlist.set(key,val.asString());
94 }
else if(val.isBool()) {
95 parlist.set(key,val.asBool());
96 }
else if(val.isInt()) {
97 parlist.set(key,val.asInt());
98 }
else if(val.isUInt()) {
99 parlist.set(key,val.asUInt());
100 }
else if(val.isDouble()) {
101 parlist.set(key,val.asDouble());
102 }
else if(val.isObject()) {
106 ROL_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
">>> ERROR (addJSONPairToPL, "
107 "json value has unsupported type.");
118 ROL::ParameterList& parlist) {
120 for(Json::ValueIterator itr = block.begin(); itr != block.end(); ++itr) {
137 ROL::ParameterList& parlist) {
140 std::ifstream stream(jsonFileName, std::ifstream::binary);
143 if(json.isMember(
"ROL")) {
144 Json::Value rolBlock = json[
"ROL"];
150 if(rolBlock.isMember(
"Algorithm")) {
151 std::string rolAlgorithm = rolBlock[
"Algorithm"].asString();
153 if(rolAlgorithm.find(
"Trust-Region") != std::string::npos) {
155 parlist.set(
"Step Type",
"Trust-Region");
158 if(rolAlgorithm.find(
"Cauchy Point") != std::string::npos) {
159 parlist.set(
"Trust-Region Subproblem Solver Type",
"Cauchy Point");
161 else if(rolAlgorithm.find(
"Double Dogleg") != std::string::npos) {
162 parlist.set(
"Trust-Region Subproblem Solver Type",
"Double Dogleg");
164 else if(rolAlgorithm.find(
"Dogleg") != std::string::npos) {
165 parlist.set(
"Trust-Region Subproblem Solver Type",
"Dogleg");
167 else if(rolAlgorithm.find(
"Truncated CG") != std::string::npos) {
168 parlist.set(
"Trust-Region Subproblem Solver Type",
"Truncated CG");
173 parlist.set(
"Step Type",
"Linesearch");
176 if(rolAlgorithm.find(
"Steepest Descent") != std::string::npos) {
177 parlist.set(
"Descent Type",
"Steepest Descent");
179 else if(rolAlgorithm.find(
"Quasi-Newton") != std::string::npos) {
180 parlist.set(
"Descent Type",
"Quasi-Newton Method");
182 else if(rolAlgorithm.find(
"Newton-Krylov") != std::string::npos) {
183 parlist.set(
"Descent Type",
"Newton-Krylov");
185 else if(rolAlgorithm.find(
"Nonlinear CG") != std::string::npos) {
186 parlist.set(
"Descent Type",
"Nonlinear CG");
193 parlist.set(
"Step Type",
"Linesearch");
194 parlist.set(
"Descent Type",
"Nonlinear CG");
206 template <
class Real>
209 if(parlist.get(
"Step Type",
"Linesearch")==
"Trust-Region") {
210 step = ROL::makePtr<ROL::TrustRegionStep<Real>>(parlist);
213 step = ROL::makePtr<ROL::LineSearchStep<Real>>(parlist);
void stepFactory(ROL::ParameterList &parlist, ROL::Ptr< ROL::Step< Real > > &step)
A minimalist step factory which specializes the Step Type depending on whether a Trust-Region or Line...
Provides the interface to compute optimization steps.
void JSON_Parameters(const std::string &jsonFileName, ROL::ParameterList &parlist)
Read a JSON file and store all parameters in a ROL::ParameterList. Checks for a key called "Algorithm...
void addJSONBlockToPL(const Json::Value &block, ROL::ParameterList &parlist)
Iterate over a block and insert key-value pairs into the ROL::ParameterList.
void addJSONPairToPL(const Json::Value &block, const std::string &key, ROL::ParameterList &parlist)
Given a JSON block and a key, get the value and insert the key-value pair into a ROL::ParameterList. If the value is itself a block, recursively iterate.