23 #include "ROL_Sacado_Objective.hpp"
24 #include "ROL_Sacado_Constraint.hpp"
30 #include "ROL_ParameterList.hpp"
33 #include "Teuchos_GlobalMPISession.hpp"
41 int main(
int argc,
char **argv)
45 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
48 int iprint = argc - 1;
49 ROL::Ptr<std::ostream> outStream;
52 outStream = ROL::makePtrFromRef(std::cout);
54 outStream = ROL::makePtrFromRef(bhs);
66 ROL::Ptr< Sacado_Objective<RealT,Example_Objective> > obj =
67 ROL::makePtr<Sacado_Objective<RealT,Example_Objective>>();
69 ROL::Ptr< Sacado_Constraint<RealT,Example_Constraint > > constr =
70 ROL::makePtr<Sacado_Constraint<RealT,Example_Constraint >>(nc);
72 ROL::Ptr<std::vector<RealT> > x_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
74 ROL::Ptr<std::vector<RealT> > sol_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
86 (*sol_ptr)[0] = -1.717143570394391e+00;
87 (*sol_ptr)[1] = 1.595709690183565e+00;
88 (*sol_ptr)[2] = 1.827245752927178e+00;
89 (*sol_ptr)[3] = -7.636430781841294e-01;
90 (*sol_ptr)[4] = -7.636430781841294e-01;
92 RealT left = -1e0, right = 1e0;
93 ROL::Ptr<std::vector<RealT> > xtest_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
94 ROL::Ptr<std::vector<RealT> > g_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
95 ROL::Ptr<std::vector<RealT> > d_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
96 ROL::Ptr<std::vector<RealT> > v_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
97 ROL::Ptr<std::vector<RealT> > vc_ptr = ROL::makePtr<std::vector<RealT>>(nc, 0.0);
98 ROL::Ptr<std::vector<RealT> > vl_ptr = ROL::makePtr<std::vector<RealT>>(nc, 0.0);
107 for (
int i=0; i<
dim; i++) {
108 (*xtest_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
109 (*d_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
110 (*v_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
113 for (
int i=0; i<nc; i++) {
114 (*vc_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
115 (*vl_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
118 obj->checkGradient(xtest, d,
true, *outStream); *outStream <<
"\n";
119 obj->checkHessVec(xtest, v,
true, *outStream); *outStream <<
"\n";
120 obj->checkHessSym(xtest, d, v,
true, *outStream); *outStream <<
"\n";
121 constr->checkApplyJacobian(xtest, v, vc,
true, *outStream); *outStream <<
"\n";
122 constr->checkApplyAdjointJacobian(xtest, vl, vc, xtest,
true, *outStream); *outStream <<
"\n";
123 constr->checkApplyAdjointHessian(xtest, vl, d, xtest,
true, *outStream); *outStream <<
"\n";
125 ROL::Ptr<std::vector<RealT> > v1_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
126 ROL::Ptr<std::vector<RealT> > v2_ptr = ROL::makePtr<std::vector<RealT>>(nc, 0.0);
130 constr->solveAugmentedSystem(v1, v2, d, vc, xtest, augtol);
133 std::string paramfile =
"parameters.xml";
134 auto parlist = ROL::getParametersFromXmlFile(paramfile);
135 ROL::Ptr<ROL::Step<RealT>>
136 step = ROL::makePtr<ROL::CompositeStep<RealT>>(*parlist);
137 ROL::Ptr<ROL::StatusTest<RealT>>
138 status = ROL::makePtr<ROL::ConstraintStatusTest<RealT>>(*parlist);
143 algo.
run(x, g, vl, vc, *obj, *constr,
true, *outStream);
146 *outStream <<
"\nReference solution x_r =\n";
147 *outStream << std::scientific <<
" " << (*sol_ptr)[0] <<
"\n";
148 *outStream << std::scientific <<
" " << (*sol_ptr)[1] <<
"\n";
149 *outStream << std::scientific <<
" " << (*sol_ptr)[2] <<
"\n";
150 *outStream << std::scientific <<
" " << (*sol_ptr)[3] <<
"\n";
151 *outStream << std::scientific <<
" " << (*sol_ptr)[4] <<
"\n";
152 *outStream <<
"\nOptimal solution x =\n";
153 *outStream << std::scientific <<
" " << (*x_ptr)[0] <<
"\n";
154 *outStream << std::scientific <<
" " << (*x_ptr)[1] <<
"\n";
155 *outStream << std::scientific <<
" " << (*x_ptr)[2] <<
"\n";
156 *outStream << std::scientific <<
" " << (*x_ptr)[3] <<
"\n";
157 *outStream << std::scientific <<
" " << (*x_ptr)[4] <<
"\n";
161 *outStream << std::scientific <<
"\n Absolute Error: " << abserr;
162 *outStream << std::scientific <<
"\n Relative Error: " << relerr <<
"\n";
163 if ( relerr > sqrt(ROL::ROL_EPSILON<RealT>()) ) {
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";
void axpy(const Real alpha, const Vector< Real > &x)
Compute where .
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.
virtual void zero()
Set to zero vector.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
Real norm() const
Returns where .
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[])