54 #include "Teuchos_oblackholestream.hpp" 55 #include "Teuchos_GlobalMPISession.hpp" 56 #include "Teuchos_XMLParameterListHelpers.hpp" 62 int main(
int argc,
char *argv[]) {
64 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
67 int iprint = argc - 1;
68 Teuchos::RCP<std::ostream> outStream;
69 Teuchos::oblackholestream bhs;
71 outStream = Teuchos::rcp(&std::cout,
false);
73 outStream = Teuchos::rcp(&bhs,
false);
81 std::string filename =
"input.xml";
82 Teuchos::RCP<Teuchos::ParameterList> parlist = Teuchos::rcp(
new Teuchos::ParameterList() );
83 Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() );
84 parlist->sublist(
"General").set(
"Inexact Hessian-Times-A-Vector",
true);
86 parlist->sublist(
"General").set(
"Inexact Hessian-Times-A-Vector",
false);
93 parlist->sublist(
"General").sublist(
"Krylov").set(
"Type",
"Conjugate Residuals");
94 parlist->sublist(
"General").sublist(
"Krylov").set(
"Absolute Tolerance", 1.e-8);
95 parlist->sublist(
"General").sublist(
"Krylov").set(
"Relative Tolerance", 1.e-4);
96 parlist->sublist(
"General").sublist(
"Krylov").set(
"Iteration Limit", 50);
107 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Step Tolerance",1.e-10);
108 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Gradient Tolerance",1.e-8);
109 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Iteration Limit",1);
110 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Dual Scaling",1.e8);
113 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Step Tolerance",1.e-10);
114 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Gradient Tolerance",1.e-8);
115 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Iteration Limit",10);
116 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Dual Scaling",1.e-2);
119 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Step Tolerance",1.e-10);
120 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Gradient Tolerance",1.e-8);
121 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Iteration Limit",10);
122 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Dual Scaling",1.e10);
125 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Step Tolerance",1.e-10);
126 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Gradient Tolerance",1.e-8);
127 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Iteration Limit",1);
128 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Dual Scaling",1.e-3);
131 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Step Tolerance",1.e-10);
132 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Gradient Tolerance",1.e-8);
133 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Iteration Limit",1);
134 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Dual Scaling",1.e0);
136 case ROL::TESTOPTPROBLEM_LAST:
break;
141 Teuchos::RCP<std::vector<RealT> > x0_rcp = Teuchos::rcp(
new std::vector<RealT> );
145 Teuchos::RCP<std::vector<RealT> > z_rcp = Teuchos::rcp(
new std::vector<RealT> );
149 Teuchos::RCP<ROL::Objective<RealT> > obj = Teuchos::null;
150 Teuchos::RCP<ROL::BoundConstraint<RealT> > con = Teuchos::null;
151 ROL::getTestObjectives<RealT>(obj,con,x0,z,prob);
155 Teuchos::rcp_const_cast<std::vector<RealT> >(
157 parlist->sublist(
"General").sublist(
"Krylov").set(
"Iteration Limit", 2*dim);
166 Teuchos::RCP<std::vector<RealT> > x_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
171 Teuchos::RCP<std::vector<RealT> > e_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
183 algo.
run(x, *obj, *con,
true, *outStream);
188 *outStream <<
"\nNorm of Error: " << e.
norm() <<
"\n";
191 Teuchos::RCP<const ROL::AlgorithmState<RealT> > state = algo.
getState();
192 errorFlag += ((e.
norm() < std::max(1.e-6*z.
norm(),1.e-8) || (state->gnorm < 1.e-6)) ? 0 : 1);
196 catch (std::logic_error err) {
197 *outStream << err.what() <<
"\n";
202 std::cout <<
"End Result: TEST FAILED\n";
204 std::cout <<
"End Result: TEST PASSED\n";
ETestOptProblem
Enumeration of test optimization problems.
Implements the computation of optimization steps with the Newton primal-dual active set method...
void axpy(const Real alpha, const Vector< Real > &x)
Compute where .
Teuchos::RCP< const AlgorithmState< Real > > getState(void) const
Contains definitions of test objective functions.
virtual void zero()
Set to zero vector.
Real norm() const
Returns where .
Provides the std::vector implementation of the ROL::Vector interface.
std::string ETestOptProblemToString(ETestOptProblem to)
Provides an interface to run optimization algorithms.
Provides an interface to check status of optimization algorithms.
int main(int argc, char *argv[])
void set(const Vector< Real > &x)
Set where .
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.