53 #include "Teuchos_GlobalMPISession.hpp"
54 #include "Teuchos_XMLParameterListHelpers.hpp"
55 #include "Teuchos_LAPACK.hpp"
67 int main(
int argc,
char *argv[]) {
69 typedef std::vector<RealT> vector;
75 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
78 int iprint = argc - 1;
79 ROL::Ptr<std::ostream> outStream;
82 outStream = ROL::makePtrFromRef(std::cout);
84 outStream = ROL::makePtrFromRef(bhs);
96 ROL::Ptr<vector> x_ptr = ROL::makePtr<vector>(nx+2, 1.0);
97 ROL::Ptr<vector> y_ptr = ROL::makePtr<vector>(nx+2, 0.0);
98 for (uint i=0; i<nx+2; i++) {
111 ROL::Ptr<vector> l_ptr = ROL::makePtr<vector>(nx+2,0.0);
112 ROL::Ptr<vector> u_ptr = ROL::makePtr<vector>(nx+2,1.0);
113 ROL::Ptr<V> lo = ROL::makePtr<SV>(l_ptr);
114 ROL::Ptr<V> up = ROL::makePtr<SV>(u_ptr);
119 std::string filename =
"input.xml";
120 auto parlist = ROL::getParametersFromXmlFile( filename );
123 parlist->sublist(
"General").sublist(
"Krylov").set(
"Absolute Tolerance",1.e-8);
124 parlist->sublist(
"General").sublist(
"Krylov").set(
"Relative Tolerance",1.e-4);
125 parlist->sublist(
"General").sublist(
"Krylov").set(
"Iteration Limit",50);
127 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Step Tolerance",1.e-10);
128 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Gradient Tolerance",1.e-8);
129 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Iteration Limit", 10);
130 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Dual Scaling",(alpha>0.0)?alpha:1.e-4);
132 parlist->sublist(
"Status Test").set(
"Gradient Tolerance",1.e-12);
133 parlist->sublist(
"Status Test").set(
"Step Tolerance",1.e-16);
134 parlist->sublist(
"Status Test").set(
"Iteration Limit",100);
141 algo.
run(x, obj, bcon, *outStream);
144 std::ofstream file_pdas;
145 file_pdas.open(
"control_PDAS.txt");
146 for (
unsigned i = 0; i < (unsigned)nx+2; i++ ) {
147 file_pdas << (*x_ptr)[i] <<
"\n";
152 parlist->sublist(
"General").sublist(
"Krylov").set(
"Absolute Tolerance",1.e-4);
153 parlist->sublist(
"General").sublist(
"Krylov").set(
"Relative Tolerance",1.e-2);
154 parlist->sublist(
"General").sublist(
"Krylov").set(
"Iteration Limit",50);
161 algo.
run(y,obj,bcon,*outStream);
164 std::ofstream file_tr;
165 file_tr.open(
"control_TR.txt");
166 for (
unsigned i = 0; i < (unsigned)nx+2; i++ ) {
167 file_tr << (*y_ptr)[i] <<
"\n";
171 std::vector<RealT> u(nx,0.0);
172 std::vector<RealT> param(4,0.0);
175 file.open(
"state.txt");
176 for (
unsigned i=0; i<(unsigned)nx; i++) {
177 file << i/((
RealT)(nx+1)) <<
" " << u[i] <<
"\n";
182 ROL::Ptr<ROL::Vector<RealT> > diff = x.clone();
185 RealT error = diff->norm();
186 *outStream <<
"\nError between PDAS solution and TR solution is " << error <<
"\n";
187 errorFlag = ((error > 1e2*std::sqrt(ROL::ROL_EPSILON<RealT>())) ? 1 : 0);
189 catch (std::logic_error& err) {
190 *outStream << err.what() <<
"\n";
195 std::cout <<
"End Result: TEST FAILED\n";
197 std::cout <<
"End Result: TEST PASSED\n";
typename PV< Real >::size_type size_type
Provides an interface to run the trust-region algorithm of Lin and More.
void solve_state(std::vector< Real > &u, const std::vector< Real > &z, const std::vector< Real > ¶m)
Defines the linear algebra or vector space interface.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
virtual std::vector< std::vector< Real > > checkGradient(const Vector< Real > &x, const Vector< Real > &d, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference gradient check.
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, std::ostream &outStream=std::cout) override
Run algorithm on bound constrained problems (Type-B). This general interface supports the use of dual...
Provides the elementwise interface to apply upper and lower bound constraints.
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])
virtual std::vector< std::vector< Real > > checkHessVec(const Vector< Real > &x, const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference Hessian-applied-to-vector check.
Provides an interface to run the projected secant algorithm.
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, std::ostream &outStream=std::cout) override
Run algorithm on bound constrained problems (Type-B). This general interface supports the use of dual...