55 #include "Teuchos_oblackholestream.hpp" 56 #include "Teuchos_GlobalMPISession.hpp" 63 int main(
int argc,
char *argv[]) {
65 typedef std::vector<RealT> vector;
71 typedef typename vector::size_type uint;
74 using Teuchos::RCP;
using Teuchos::rcp;
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);
96 RCP<vector> x_exact_rcp = rcp(
new vector(xdim), 0.0 );
97 (*x_exact_rcp)[0] = 1.0;
98 (*x_exact_rcp)[1] = 1.0;
100 RCP<V> x = rcp(
new SV( rcp(
new vector(xdim, 0.0) ) ) );
101 RCP<V> d = rcp(
new SV( rcp(
new vector(xdim, 0.0) ) ) );
102 RCP<V> xtest = rcp(
new SV( rcp(
new vector(xdim, 0.0) ) ) );
104 RCP<V> c1 = rcp(
new SV( rcp(
new vector(cdim, 1.0) ) ) );
105 RCP<V> c2 = rcp(
new SV( rcp(
new vector(cdim, 1.0) ) ) );
106 RCP<V> l1 = rcp(
new SV( rcp(
new vector(cdim, 1.0) ) ) );
107 RCP<V> l2 = rcp(
new SV( rcp(
new vector(cdim, 1.0) ) ) );
114 SV x_exact( x_exact_rcp );
117 x->applyUnary(ROL::Elementwise::Fill<RealT>(2.0));
128 *outStream <<
"Checking objective" << std::endl;
129 obj->checkGradient(*x,*d,
true,*outStream);
131 *outStream <<
"\nChecking first equality constraint" << std::endl;
132 con1->checkApplyJacobian( *xtest, *d, *c1 ,
true, *outStream );
133 con1->checkApplyAdjointJacobian( *xtest, *l1, *c1, *d,
true, *outStream );
134 con1->checkApplyAdjointHessian( *xtest, *l1, *d, *xtest,
true, *outStream );
136 *outStream <<
"\nChecking second equality constraint" << std::endl;
137 con2->checkApplyJacobian( *xtest, *d, *c2,
true, *outStream );
138 con2->checkApplyAdjointJacobian( *xtest, *l2, *c2, *d,
true, *outStream );
139 con2->checkApplyAdjointHessian( *xtest, *l2, *d, *xtest,
true, *outStream );
141 *outStream <<
"\nChecking partitioned equality constraint" << std::endl;
142 con->checkApplyJacobian( *xtest, *d, *c,
true, *outStream );
143 con->checkApplyAdjointJacobian( *xtest, *l, *c, *d,
true, *outStream );
144 con->checkApplyAdjointHessian( *xtest, *l, *d, *xtest,
true, *outStream );
147 Teuchos::ParameterList parlist;
148 std::string stepname =
"Composite Step";
149 parlist.sublist(
"Step").sublist(stepname).sublist(
"Optimality System Solver").set(
"Nominal Relative Tolerance",1.e-4);
150 parlist.sublist(
"Step").sublist(stepname).sublist(
"Optimality System Solver").set(
"Fix Tolerance",
true);
151 parlist.sublist(
"Step").sublist(stepname).sublist(
"Tangential Subproblem Solver").set(
"Iteration Limit",20);
152 parlist.sublist(
"Step").sublist(stepname).sublist(
"Tangential Subproblem Solver").set(
"Relative Tolerance",1e-2);
153 parlist.sublist(
"Step").sublist(stepname).set(
"Output Level",0);
154 parlist.sublist(
"Status Test").set(
"Gradient Tolerance",1.e-12);
155 parlist.sublist(
"Status Test").set(
"Constraint Tolerance",1.e-12);
156 parlist.sublist(
"Status Test").set(
"Step Tolerance",1.e-18);
157 parlist.sublist(
"Status Test").set(
"Iteration Limit",100);
160 algo.
run(*x,x->dual(),*l,*c,*obj,*con,
true,*outStream);
162 x->axpy(-1.0,x_exact);
164 if( x->norm() > 1e-6 ) {
169 catch (std::logic_error err) {
170 *outStream << err.what() <<
"\n";
175 std::cout <<
"End Result: TEST FAILED\n";
177 std::cout <<
"End Result: TEST PASSED\n";
Provides the interface to evaluate objective functions.
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].
Teuchos::RCP< Vector< Real > > CreatePartitionedVector(const Teuchos::RCP< Vector< Real > > &a)
Defines the linear algebra or vector space interface.
Teuchos::RCP< EqualityConstraint< Real > > CreateEqualityConstraintPartitioned(const Teuchos::RCP< EqualityConstraint< Real > > &con1, const Teuchos::RCP< EqualityConstraint< Real > > &con2)
Contains definitions for W. Hock and K. Schittkowski 39th test function.
Defines the equality constraint operator interface.
Provides the std::vector implementation of the ROL::Vector interface.
Provides an interface to run optimization algorithms.
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.
int main(int argc, char *argv[])
W. Hock and K. Schittkowski 39th test function.