57 #include "ROL_Sacado_Objective.hpp"
58 #include "ROL_Sacado_EqualityConstraint.hpp"
65 #include "Teuchos_oblackholestream.hpp"
66 #include "Teuchos_GlobalMPISession.hpp"
67 #include "Teuchos_XMLParameterListHelpers.hpp"
75 int main(
int argc,
char **argv)
79 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
82 int iprint = argc - 1;
83 Teuchos::RCP<std::ostream> outStream;
84 Teuchos::oblackholestream bhs;
86 outStream = Teuchos::rcp(&std::cout,
false);
88 outStream = Teuchos::rcp(&bhs,
false);
100 Teuchos::RCP< Sacado_Objective<RealT,Example_Objective> > obj =
101 Teuchos::rcp(
new Sacado_Objective<RealT,Example_Objective> ());
103 Teuchos::RCP< Sacado_EqualityConstraint<RealT,Example_Constraint > > constr =
104 Teuchos::rcp(
new Sacado_EqualityConstraint<RealT,Example_Constraint > (nc));
106 Teuchos::RCP<std::vector<RealT> > x_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
108 Teuchos::RCP<std::vector<RealT> > sol_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
120 (*sol_rcp)[0] = -1.717143570394391e+00;
121 (*sol_rcp)[1] = 1.595709690183565e+00;
122 (*sol_rcp)[2] = 1.827245752927178e+00;
123 (*sol_rcp)[3] = -7.636430781841294e-01;
124 (*sol_rcp)[4] = -7.636430781841294e-01;
126 Teuchos::ParameterList parlist;
129 parlist.set(
"Nominal SQP Optimality Solver Tolerance", 1.e-2);
132 RealT left = -1e0, right = 1e0;
133 Teuchos::RCP<std::vector<RealT> > xtest_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
134 Teuchos::RCP<std::vector<RealT> > g_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
135 Teuchos::RCP<std::vector<RealT> > d_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
136 Teuchos::RCP<std::vector<RealT> > v_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
137 Teuchos::RCP<std::vector<RealT> > vc_rcp = Teuchos::rcp(
new std::vector<RealT> (nc, 0.0) );
138 Teuchos::RCP<std::vector<RealT> > vl_rcp = Teuchos::rcp(
new std::vector<RealT> (nc, 0.0) );
147 for (
int i=0; i<dim; i++) {
148 (*xtest_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
149 (*d_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
150 (*v_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
153 for (
int i=0; i<nc; i++) {
154 (*vc_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
155 (*vl_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
158 obj->checkGradient(xtest, d,
true, *outStream); *outStream <<
"\n";
159 obj->checkHessVec(xtest, v,
true, *outStream); *outStream <<
"\n";
160 obj->checkHessSym(xtest, d, v,
true, *outStream); *outStream <<
"\n";
161 constr->checkApplyJacobian(xtest, v, vc,
true, *outStream); *outStream <<
"\n";
162 constr->checkApplyAdjointJacobian(xtest, vl, vc, xtest,
true, *outStream); *outStream <<
"\n";
163 constr->checkApplyAdjointHessian(xtest, vl, d, xtest,
true, *outStream); *outStream <<
"\n";
165 Teuchos::RCP<std::vector<RealT> > v1_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
166 Teuchos::RCP<std::vector<RealT> > v2_rcp = Teuchos::rcp(
new std::vector<RealT> (nc, 0.0) );
170 constr->solveAugmentedSystem(v1, v2, d, vc, xtest, augtol);
185 std::vector<std::string> output = algo.
run(x, g, vl, vc, *obj, *constr,
false);
186 for (
unsigned i = 0; i < output.size(); i++ ) {
187 *outStream << output[i];
191 *outStream <<
"\nReference solution x_r =\n";
192 *outStream << std::scientific <<
" " << (*sol_rcp)[0] <<
"\n";
193 *outStream << std::scientific <<
" " << (*sol_rcp)[1] <<
"\n";
194 *outStream << std::scientific <<
" " << (*sol_rcp)[2] <<
"\n";
195 *outStream << std::scientific <<
" " << (*sol_rcp)[3] <<
"\n";
196 *outStream << std::scientific <<
" " << (*sol_rcp)[4] <<
"\n";
197 *outStream <<
"\nOptimal solution x =\n";
198 *outStream << std::scientific <<
" " << (*x_rcp)[0] <<
"\n";
199 *outStream << std::scientific <<
" " << (*x_rcp)[1] <<
"\n";
200 *outStream << std::scientific <<
" " << (*x_rcp)[2] <<
"\n";
201 *outStream << std::scientific <<
" " << (*x_rcp)[3] <<
"\n";
202 *outStream << std::scientific <<
" " << (*x_rcp)[4] <<
"\n";
206 *outStream << std::scientific <<
"\n Absolute Error: " << abserr;
207 *outStream << std::scientific <<
"\n Relative Error: " << relerr <<
"\n";
212 catch (std::logic_error err) {
213 *outStream << err.what() <<
"\n";
218 std::cout <<
"End Result: TEST FAILED\n";
220 std::cout <<
"End Result: TEST PASSED\n";
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
int main(int argc, char **argv)
virtual void zero()
Set to zero vector.
Real norm() const
Returns where .
Provides the std::vector implementation of the ROL::Vector interface.
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.
Implements the computation of optimization steps with composite-step trust-region SQP methods...
static const double ROL_EPSILON
Platform-dependent machine epsilon.