54 #include "Teuchos_oblackholestream.hpp" 55 #include "Teuchos_GlobalMPISession.hpp" 62 int main(
int argc,
char *argv[]) {
64 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
67 int iprint = argc - 1;
68 Teuchos::RCP<std::ostream> outStream;
69 Teuchos::oblackholestream bhs;
71 outStream = Teuchos::rcp(&std::cout,
false);
73 outStream = Teuchos::rcp(&bhs,
false);
81 Teuchos::RCP<ROL::Objective<RealT> > obj;
82 Teuchos::RCP<ROL::EqualityConstraint<RealT> > constr;
83 Teuchos::RCP<std::vector<RealT> > x_rcp = Teuchos::rcp(
new std::vector<RealT> (0, 0.0) );
84 Teuchos::RCP<std::vector<RealT> > sol_rcp = Teuchos::rcp(
new std::vector<RealT> (0, 0.0) );
94 RealT left = -1e0, right = 1e0;
95 Teuchos::RCP<std::vector<RealT> > xtest_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
96 Teuchos::RCP<std::vector<RealT> > g_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
97 Teuchos::RCP<std::vector<RealT> > d_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
98 Teuchos::RCP<std::vector<RealT> > v_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
99 Teuchos::RCP<std::vector<RealT> > vc_rcp = Teuchos::rcp(
new std::vector<RealT> (nc, 0.0) );
100 Teuchos::RCP<std::vector<RealT> > vl_rcp = Teuchos::rcp(
new std::vector<RealT> (nc, 0.0) );
108 for (
int i=0; i<dim; i++) {
109 (*xtest_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
110 (*d_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
111 (*v_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
114 for (
int i=0; i<nc; i++) {
115 (*vc_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
116 (*vl_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
126 constr->checkApplyJacobian(xtest, v, vc,
true, *outStream); *outStream <<
"\n";
127 constr->checkApplyAdjointJacobian(xtest, vl, vc, xtest,
true, *outStream); *outStream <<
"\n";
128 constr->checkApplyAdjointHessian(xtest, vl, d, xtest,
true, *outStream); *outStream <<
"\n";
129 nlls.
checkGradient(xtest, d,
true, *outStream); *outStream <<
"\n";
130 nlls.
checkHessVec(xtest, v,
true, *outStream); *outStream <<
"\n";
131 nlls.
checkHessSym(xtest, d, v,
true, *outStream); *outStream <<
"\n";
134 Teuchos::ParameterList parlist;
135 std::string stepname =
"Trust Region";
136 parlist.sublist(
"Step").sublist(stepname).set(
"Subproblem Solver",
"Truncated CG");
137 parlist.sublist(
"Status Test").set(
"Gradient Tolerance",1.e-10);
138 parlist.sublist(
"Status Test").set(
"Constraint Tolerance",1.e-10);
139 parlist.sublist(
"Status Test").set(
"Step Tolerance",1.e-18);
140 parlist.sublist(
"Status Test").set(
"Iteration Limit",100);
144 *outStream <<
"\nSOLVE USING FULL HESSIAN\n";
146 algo.
run(x, nlls,
true, *outStream);
148 *outStream <<
"\nSOLVE USING GAUSS-NEWTON HESSIAN\n";
150 algo.
run(x, gnnlls,
true, *outStream);
152 catch (std::logic_error err) {
153 *outStream << err.what() <<
"\n";
158 std::cout <<
"End Result: TEST FAILED\n";
160 std::cout <<
"End Result: TEST PASSED\n";
int main(int argc, char *argv[])
virtual std::vector< std::vector< Real > > checkGradient(const Vector< Real > &x, const Vector< Real > &d, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference gradient check.
Provides the std::vector implementation of the ROL::Vector interface.
Provides an interface to run optimization algorithms.
Contains definitions for the equality constrained NLP from Nocedal/Wright, 2nd edition, page 574, example 18.2; note the typo in reversing the initial guess and the solution.
void set(const Vector< Real > &x)
Set where .
virtual std::vector< std::vector< Real > > checkHessVec(const Vector< Real > &x, const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference Hessian-applied-to-vector check.
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.
Provides the interface to evaluate nonlinear least squares objective functions.
virtual std::vector< Real > checkHessSym(const Vector< Real > &x, const Vector< Real > &v, const Vector< Real > &w, const bool printToStream=true, std::ostream &outStream=std::cout)
Hessian symmetry check.