56 #include "Teuchos_GlobalMPISession.hpp"
63 int main(
int argc,
char *argv[]) {
65 typedef std::vector<RealT> vector;
73 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
76 int iprint = argc - 1;
77 ROL::Ptr<std::ostream> outStream;
80 outStream = ROL::makePtrFromRef(std::cout);
82 outStream = ROL::makePtrFromRef(bhs);
93 ROL::Ptr<vector> x_exact_ptr = ROL::makePtr<vector>(xdim);
94 (*x_exact_ptr)[0] = 1.0;
95 (*x_exact_ptr)[1] = 1.0;
97 ROL::Ptr<V> x = ROL::makePtr<SV>( ROL::makePtr<vector>(xdim, 0.0) );
98 ROL::Ptr<V> d = ROL::makePtr<SV>( ROL::makePtr<vector>(xdim, 0.0) );
99 ROL::Ptr<V> xtest = ROL::makePtr<SV>( ROL::makePtr<vector>(xdim, 0.0) );
101 ROL::Ptr<V> c1 = ROL::makePtr<SV>( ROL::makePtr<vector>(cdim, 1.0) );
102 ROL::Ptr<V> c2 = ROL::makePtr<SV>( ROL::makePtr<vector>(cdim, 1.0) );
103 ROL::Ptr<V> l1 = ROL::makePtr<SV>( ROL::makePtr<vector>(cdim, 1.0) );
104 ROL::Ptr<V> l2 = ROL::makePtr<SV>( ROL::makePtr<vector>(cdim, 1.0) );
111 SV x_exact( x_exact_ptr );
114 x->applyUnary(ROL::Elementwise::Fill<RealT>(2.0));
119 ROL::Ptr<OBJ> obj = ROL::makePtr<ROL::ZOO::Objective_HS39<RealT>>();
120 ROL::Ptr<EC> con1 = ROL::makePtr<ROL::ZOO::Constraint_HS39a<RealT>>();
121 ROL::Ptr<EC> con2 = ROL::makePtr<ROL::ZOO::Constraint_HS39b<RealT>>();
122 std::vector<ROL::Ptr<EC> > cvec(2); cvec[0] = con1; cvec[1] = con2;
124 ROL::Ptr<EC> con = ROL::makePtr<ROL::Constraint_Partitioned<RealT>>(cvec);
126 *outStream <<
"Checking objective" << std::endl;
127 obj->checkGradient(*x,*d,
true,*outStream);
129 *outStream <<
"\nChecking first equality constraint" << std::endl;
130 con1->checkApplyJacobian( *xtest, *d, *c1 ,
true, *outStream );
131 con1->checkApplyAdjointJacobian( *xtest, *l1, *c1, *d,
true, *outStream );
132 con1->checkApplyAdjointHessian( *xtest, *l1, *d, *xtest,
true, *outStream );
134 *outStream <<
"\nChecking second equality constraint" << std::endl;
135 con2->checkApplyJacobian( *xtest, *d, *c2,
true, *outStream );
136 con2->checkApplyAdjointJacobian( *xtest, *l2, *c2, *d,
true, *outStream );
137 con2->checkApplyAdjointHessian( *xtest, *l2, *d, *xtest,
true, *outStream );
139 *outStream <<
"\nChecking partitioned equality constraint" << std::endl;
140 con->checkApplyJacobian( *xtest, *d, *c,
true, *outStream );
141 con->checkApplyAdjointJacobian( *xtest, *l, *c, *d,
true, *outStream );
142 con->checkApplyAdjointHessian( *xtest, *l, *d, *xtest,
true, *outStream );
145 ROL::ParameterList parlist;
146 std::string stepname =
"Composite Step";
147 parlist.sublist(
"Step").sublist(stepname).sublist(
"Optimality System Solver").set(
"Nominal Relative Tolerance",1.e-4);
148 parlist.sublist(
"Step").sublist(stepname).sublist(
"Optimality System Solver").set(
"Fix Tolerance",
true);
149 parlist.sublist(
"Step").sublist(stepname).sublist(
"Tangential Subproblem Solver").set(
"Iteration Limit",20);
150 parlist.sublist(
"Step").sublist(stepname).sublist(
"Tangential Subproblem Solver").set(
"Relative Tolerance",1e-2);
151 parlist.sublist(
"Step").sublist(stepname).set(
"Output Level",0);
152 parlist.sublist(
"Status Test").set(
"Gradient Tolerance",1.e-12);
153 parlist.sublist(
"Status Test").set(
"Constraint Tolerance",1.e-12);
154 parlist.sublist(
"Status Test").set(
"Step Tolerance",1.e-18);
155 parlist.sublist(
"Status Test").set(
"Iteration Limit",100);
158 algo.
run(*x,x->dual(),*l,*c,*obj,*con,
true,*outStream);
160 x->axpy(-1.0,x_exact);
162 if( x->norm() > 1e-6 ) {
167 catch (std::logic_error err) {
168 *outStream << err.what() <<
"\n";
173 std::cout <<
"End Result: TEST FAILED\n";
175 std::cout <<
"End Result: TEST PASSED\n";
Provides the interface to evaluate objective functions.
typename PV< Real >::size_type size_type
ROL::Ptr< Vector< Real > > CreatePartitionedVector(const ROL::Ptr< Vector< Real >> &a)
virtual std::vector< std::string > run(Vector< Real > &x, Objective< Real > &obj, bool print=false, std::ostream &outStream=std::cout, bool printVectors=false, std::ostream &vectorStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This is the primary Type-U interface.
void RandomizeVector(Vector< Real > &x, const Real &lower=0.0, const Real &upper=1.0)
Fill a ROL::Vector with uniformly-distributed random numbers in the interval [lower,upper].
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...
Contains definitions for W. Hock and K. Schittkowski 39th test function.
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Provides an interface to run optimization algorithms.
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])
Defines the general constraint operator interface.