31int main(
int argc,
char *argv[]) {
33 typedef std::vector<RealT> vector;
37 typedef typename vector::size_type luint;
39 ROL::GlobalMPISession mpiSession(&argc, &argv);
42 int iprint = argc - 1;
43 ROL::Ptr<std::ostream> outStream;
46 outStream = ROL::makePtrFromRef(std::cout);
48 outStream = ROL::makePtrFromRef(bhs);
60 ROL::Ptr<vector> x_ptr = ROL::makePtr<vector>(nx+2, 1.0);
61 ROL::Ptr<vector> y_ptr = ROL::makePtr<vector>(nx+2, 0.0);
62 for (luint i=0; i<nx+2; i++) {
75 ROL::Ptr<vector> l_ptr = ROL::makePtr<vector>(nx+2,0.0);
76 ROL::Ptr<vector> u_ptr = ROL::makePtr<vector>(nx+2,1.0);
77 ROL::Ptr<V> lo = ROL::makePtr<SV>(l_ptr);
78 ROL::Ptr<V> up = ROL::makePtr<SV>(u_ptr);
83 std::string filename =
"input.xml";
84 auto parlist = ROL::getParametersFromXmlFile( filename );
87 parlist->sublist(
"General").sublist(
"Krylov").set(
"Absolute Tolerance",1.e-8);
88 parlist->sublist(
"General").sublist(
"Krylov").set(
"Relative Tolerance",1.e-4);
89 parlist->sublist(
"General").sublist(
"Krylov").set(
"Iteration Limit",50);
91 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Step Tolerance",1.e-10);
92 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Gradient Tolerance",1.e-8);
93 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Iteration Limit", 10);
94 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Dual Scaling",(alpha>0.0)?alpha:1.e-4);
96 parlist->sublist(
"Status Test").set(
"Gradient Tolerance",1.e-12);
97 parlist->sublist(
"Status Test").set(
"Step Tolerance",1.e-16);
98 parlist->sublist(
"Status Test").set(
"Iteration Limit",100);
105 algo.
run(x, obj, bcon, *outStream);
108 std::ofstream file_pdas;
109 file_pdas.open(
"control_PDAS.txt");
110 for (
unsigned i = 0; i < (unsigned)nx+2; i++ ) {
111 file_pdas << (*x_ptr)[i] <<
"\n";
116 parlist->sublist(
"General").sublist(
"Krylov").set(
"Absolute Tolerance",1.e-4);
117 parlist->sublist(
"General").sublist(
"Krylov").set(
"Relative Tolerance",1.e-2);
118 parlist->sublist(
"General").sublist(
"Krylov").set(
"Iteration Limit",50);
125 algo.
run(y,obj,bcon,*outStream);
128 std::ofstream file_tr;
129 file_tr.open(
"control_TR.txt");
130 for (
unsigned i = 0; i < (unsigned)nx+2; i++ ) {
131 file_tr << (*y_ptr)[i] <<
"\n";
135 std::vector<RealT> u(nx,0.0);
136 std::vector<RealT> param(4,0.0);
139 file.open(
"state.txt");
140 for (
unsigned i=0; i<(unsigned)nx; i++) {
141 file << i/((
RealT)(nx+1)) <<
" " << u[i] <<
"\n";
146 ROL::Ptr<ROL::Vector<RealT> > diff = x.clone();
149 RealT error = diff->norm();
150 *outStream <<
"\nError between PDAS solution and TR solution is " << error <<
"\n";
151 errorFlag = ((error > 1e2*std::sqrt(ROL::ROL_EPSILON<RealT>())) ? 1 : 0);
153 catch (std::logic_error& err) {
154 *outStream << err.what() <<
"\n";
159 std::cout <<
"End Result: TEST FAILED\n";
161 std::cout <<
"End Result: TEST PASSED\n";
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.
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.
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...
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...