33 #include "json/json.h"
34 #include "Teuchos_ParameterList.hpp"
42 void addJSONPairToPL(
const Json::Value& block,
const std::string &key,ROL::ParameterList& parlist);
53 const std::string &key,
54 ROL::ParameterList& parlist) {
56 Json::Value val = block[key];
59 parlist.set(key,val.asString());
60 }
else if(val.isBool()) {
61 parlist.set(key,val.asBool());
62 }
else if(val.isInt()) {
63 parlist.set(key,val.asInt());
64 }
else if(val.isUInt()) {
65 parlist.set(key,val.asUInt());
66 }
else if(val.isDouble()) {
67 parlist.set(key,val.asDouble());
68 }
else if(val.isObject()) {
72 ROL_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
">>> ERROR (addJSONPairToPL, "
73 "json value has unsupported type.");
84 ROL::ParameterList& parlist) {
86 for(Json::ValueIterator itr = block.begin(); itr != block.end(); ++itr) {
103 ROL::ParameterList& parlist) {
106 std::ifstream stream(jsonFileName, std::ifstream::binary);
109 if(json.isMember(
"ROL")) {
110 Json::Value rolBlock = json[
"ROL"];
116 if(rolBlock.isMember(
"Algorithm")) {
117 std::string rolAlgorithm = rolBlock[
"Algorithm"].asString();
119 if(rolAlgorithm.find(
"Trust-Region") != std::string::npos) {
121 parlist.set(
"Step Type",
"Trust-Region");
124 if(rolAlgorithm.find(
"Cauchy Point") != std::string::npos) {
125 parlist.set(
"Trust-Region Subproblem Solver Type",
"Cauchy Point");
127 else if(rolAlgorithm.find(
"Double Dogleg") != std::string::npos) {
128 parlist.set(
"Trust-Region Subproblem Solver Type",
"Double Dogleg");
130 else if(rolAlgorithm.find(
"Dogleg") != std::string::npos) {
131 parlist.set(
"Trust-Region Subproblem Solver Type",
"Dogleg");
133 else if(rolAlgorithm.find(
"Truncated CG") != std::string::npos) {
134 parlist.set(
"Trust-Region Subproblem Solver Type",
"Truncated CG");
139 parlist.set(
"Step Type",
"Linesearch");
142 if(rolAlgorithm.find(
"Steepest Descent") != std::string::npos) {
143 parlist.set(
"Descent Type",
"Steepest Descent");
145 else if(rolAlgorithm.find(
"Quasi-Newton") != std::string::npos) {
146 parlist.set(
"Descent Type",
"Quasi-Newton Method");
148 else if(rolAlgorithm.find(
"Newton-Krylov") != std::string::npos) {
149 parlist.set(
"Descent Type",
"Newton-Krylov");
151 else if(rolAlgorithm.find(
"Nonlinear CG") != std::string::npos) {
152 parlist.set(
"Descent Type",
"Nonlinear CG");
159 parlist.set(
"Step Type",
"Linesearch");
160 parlist.set(
"Descent Type",
"Nonlinear CG");
172 template <
class Real>
175 if(parlist.get(
"Step Type",
"Linesearch")==
"Trust-Region") {
176 step = ROL::makePtr<ROL::TrustRegionStep<Real>>(parlist);
179 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.