68 #include "Teuchos_oblackholestream.hpp" 69 #include "Teuchos_GlobalMPISession.hpp" 70 #include "Teuchos_XMLParameterListHelpers.hpp" 74 int main(
int argc,
char *argv[]) {
76 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
79 int iprint = argc - 1;
80 Teuchos::RCP<std::ostream> outStream;
81 Teuchos::oblackholestream bhs;
83 outStream = Teuchos::rcp(&std::cout,
false);
85 outStream = Teuchos::rcp(&bhs,
false);
95 Teuchos::ParameterList parlist;
97 std::string jsonFileName(
"parameters.json");
98 parlist.setName(
"Imported from " + jsonFileName);
102 std::string stepname =
"Trust Region";
105 Teuchos::RCP<ROL::Step<RealT> > step = stepFactory.
getStep(stepname, parlist);
108 RealT gtol = parlist.get(
"Gradient Tolerance",1e-12);
109 RealT stol = parlist.get(
"Step Tolerance",1e-14);
110 int maxit = parlist.get(
"Maximum Number of Iterations",100);
111 Teuchos::RCP<ROL::StatusTest<RealT> > status = Teuchos::rcp(
new ROL::StatusTest<RealT>(gtol, stol, maxit));
115 Teuchos::RCP<std::vector<RealT> > x_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 1.0) );
116 Teuchos::RCP<std::vector<RealT> > k_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
121 for(
int i=0;i<dim;++i) {
128 algo.
run(x, obj,
true, *outStream);
131 Teuchos::RCP<std::vector<RealT> > xtrue_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
137 *outStream << std::scientific <<
"\n Absolute Error: " << abserr;
143 Teuchos::writeParameterListToXmlFile(parlist,
"parameters.xml");
146 catch (std::logic_error err) {
147 *outStream << err.what() <<
"\n";
152 std::cout <<
"End Result: TEST FAILED\n";
154 std::cout <<
"End Result: TEST PASSED\n";
void axpy(const Real alpha, const Vector< Real > &x)
Compute where .
void stepFactory(Teuchos::ParameterList &parlist, Teuchos::RCP< ROL::Step< Real > > &step)
A minimalist step factory which specializes the Step Type depending on whether a Trust-Region or Line...
int main(int argc, char *argv[])
Real norm() const
Returns where .
Provides the std::vector implementation of the ROL::Vector interface.
Provides an interface to run optimization algorithms.
Provides an interface to check status of optimization algorithms.
Contains definitions for the Zakharov function as evaluated using only the ROL::Vector interface...
virtual std::vector< std::string > run(Vector< Real > &x, Objective< Real > &obj, bool print=false, std::ostream &outStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This is the primary Type-U interface.
void JSON_Parameters(const std::string &jsonFileName, Teuchos::ParameterList &parlist)
Read a JSON file and store all parameters in a Teuchos::ParameterList. Checks for a key called "Algor...
Teuchos::RCP< Step< Real > > getStep(const std::string &type, Teuchos::ParameterList &parlist) const
static const double ROL_EPSILON
Platform-dependent machine epsilon.