57 #include "ROL_Sacado_Objective.hpp"
58 #include "ROL_Sacado_Constraint.hpp"
64 #include "ROL_ParameterList.hpp"
67 #include "Teuchos_GlobalMPISession.hpp"
75 int main(
int argc,
char **argv)
79 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
82 int iprint = argc - 1;
83 ROL::Ptr<std::ostream> outStream;
86 outStream = ROL::makePtrFromRef(std::cout);
88 outStream = ROL::makePtrFromRef(bhs);
100 ROL::Ptr< Sacado_Objective<RealT,Example_Objective> > obj =
101 ROL::makePtr<Sacado_Objective<RealT,Example_Objective>>();
103 ROL::Ptr< Sacado_Constraint<RealT,Example_Constraint > > constr =
104 ROL::makePtr<Sacado_Constraint<RealT,Example_Constraint >>(nc);
106 ROL::Ptr<std::vector<RealT> > x_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
108 ROL::Ptr<std::vector<RealT> > sol_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
120 (*sol_ptr)[0] = -1.717143570394391e+00;
121 (*sol_ptr)[1] = 1.595709690183565e+00;
122 (*sol_ptr)[2] = 1.827245752927178e+00;
123 (*sol_ptr)[3] = -7.636430781841294e-01;
124 (*sol_ptr)[4] = -7.636430781841294e-01;
126 RealT left = -1e0, right = 1e0;
127 ROL::Ptr<std::vector<RealT> > xtest_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
128 ROL::Ptr<std::vector<RealT> > g_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
129 ROL::Ptr<std::vector<RealT> > d_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
130 ROL::Ptr<std::vector<RealT> > v_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
131 ROL::Ptr<std::vector<RealT> > vc_ptr = ROL::makePtr<std::vector<RealT>>(nc, 0.0);
132 ROL::Ptr<std::vector<RealT> > vl_ptr = ROL::makePtr<std::vector<RealT>>(nc, 0.0);
141 for (
int i=0; i<
dim; i++) {
142 (*xtest_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
143 (*d_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
144 (*v_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
147 for (
int i=0; i<nc; i++) {
148 (*vc_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
149 (*vl_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
152 obj->checkGradient(xtest, d,
true, *outStream); *outStream <<
"\n";
153 obj->checkHessVec(xtest, v,
true, *outStream); *outStream <<
"\n";
154 obj->checkHessSym(xtest, d, v,
true, *outStream); *outStream <<
"\n";
155 constr->checkApplyJacobian(xtest, v, vc,
true, *outStream); *outStream <<
"\n";
156 constr->checkApplyAdjointJacobian(xtest, vl, vc, xtest,
true, *outStream); *outStream <<
"\n";
157 constr->checkApplyAdjointHessian(xtest, vl, d, xtest,
true, *outStream); *outStream <<
"\n";
159 ROL::Ptr<std::vector<RealT> > v1_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
160 ROL::Ptr<std::vector<RealT> > v2_ptr = ROL::makePtr<std::vector<RealT>>(nc, 0.0);
164 constr->solveAugmentedSystem(v1, v2, d, vc, xtest, augtol);
167 std::string paramfile =
"parameters.xml";
168 auto parlist = ROL::getParametersFromXmlFile(paramfile);
169 ROL::Ptr<ROL::Step<RealT>>
170 step = ROL::makePtr<ROL::CompositeStep<RealT>>(*parlist);
171 ROL::Ptr<ROL::StatusTest<RealT>>
172 status = ROL::makePtr<ROL::ConstraintStatusTest<RealT>>(*parlist);
177 algo.
run(x, g, vl, vc, *obj, *constr,
true, *outStream);
180 *outStream <<
"\nReference solution x_r =\n";
181 *outStream << std::scientific <<
" " << (*sol_ptr)[0] <<
"\n";
182 *outStream << std::scientific <<
" " << (*sol_ptr)[1] <<
"\n";
183 *outStream << std::scientific <<
" " << (*sol_ptr)[2] <<
"\n";
184 *outStream << std::scientific <<
" " << (*sol_ptr)[3] <<
"\n";
185 *outStream << std::scientific <<
" " << (*sol_ptr)[4] <<
"\n";
186 *outStream <<
"\nOptimal solution x =\n";
187 *outStream << std::scientific <<
" " << (*x_ptr)[0] <<
"\n";
188 *outStream << std::scientific <<
" " << (*x_ptr)[1] <<
"\n";
189 *outStream << std::scientific <<
" " << (*x_ptr)[2] <<
"\n";
190 *outStream << std::scientific <<
" " << (*x_ptr)[3] <<
"\n";
191 *outStream << std::scientific <<
" " << (*x_ptr)[4] <<
"\n";
195 *outStream << std::scientific <<
"\n Absolute Error: " << abserr;
196 *outStream << std::scientific <<
"\n Relative Error: " << relerr <<
"\n";
197 if ( relerr > sqrt(ROL::ROL_EPSILON<RealT>()) ) {
201 catch (std::logic_error& err) {
202 *outStream << err.what() <<
"\n";
207 std::cout <<
"End Result: TEST FAILED\n";
209 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[])