55 #include "Teuchos_GlobalMPISession.hpp"
62 int main(
int argc,
char *argv[]) {
64 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
67 int iprint = argc - 1;
68 ROL::Ptr<std::ostream> outStream;
71 outStream = ROL::makePtrFromRef(std::cout);
73 outStream = ROL::makePtrFromRef(bhs);
81 ROL::Ptr<ROL::Objective<RealT> > obj;
82 ROL::Ptr<ROL::Constraint<RealT> > constr;
83 ROL::Ptr<ROL::Vector<RealT> > x;
84 ROL::Ptr<ROL::Vector<RealT> > sol;
96 RealT left = -1e0, right = 1e0;
97 ROL::Ptr<std::vector<RealT> > xtest_ptr = ROL::makePtr<std::vector<RealT>>(dim, 0.0);
98 ROL::Ptr<std::vector<RealT> > g_ptr = ROL::makePtr<std::vector<RealT>>(dim, 0.0);
99 ROL::Ptr<std::vector<RealT> > d_ptr = ROL::makePtr<std::vector<RealT>>(dim, 0.0);
100 ROL::Ptr<std::vector<RealT> > v_ptr = ROL::makePtr<std::vector<RealT>>(dim, 0.0);
101 ROL::Ptr<std::vector<RealT> > vc_ptr = ROL::makePtr<std::vector<RealT>>(nc, 0.0);
102 ROL::Ptr<std::vector<RealT> > vl_ptr = ROL::makePtr<std::vector<RealT>>(nc, 0.0);
110 for (
int i=0; i<dim; i++) {
111 (*xtest_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
112 (*d_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
113 (*v_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
116 for (
int i=0; i<nc; i++) {
117 (*vc_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
118 (*vl_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
128 constr->checkApplyJacobian(xtest, v, vc,
true, *outStream); *outStream <<
"\n";
129 constr->checkApplyAdjointJacobian(xtest, vl, vc, xtest,
true, *outStream); *outStream <<
"\n";
130 constr->checkApplyAdjointHessian(xtest, vl, d, xtest,
true, *outStream); *outStream <<
"\n";
131 nlls.
checkGradient(xtest, d,
true, *outStream); *outStream <<
"\n";
132 nlls.
checkHessVec(xtest, v,
true, *outStream); *outStream <<
"\n";
133 nlls.
checkHessSym(xtest, d, v,
true, *outStream); *outStream <<
"\n";
136 ROL::ParameterList parlist;
137 std::string stepname =
"Trust Region";
138 parlist.sublist(
"Step").sublist(stepname).set(
"Subproblem Solver",
"Truncated CG");
139 parlist.sublist(
"Status Test").set(
"Gradient Tolerance",1.e-10);
140 parlist.sublist(
"Status Test").set(
"Constraint Tolerance",1.e-10);
141 parlist.sublist(
"Status Test").set(
"Step Tolerance",1.e-18);
142 parlist.sublist(
"Status Test").set(
"Iteration Limit",100);
146 *outStream <<
"\nSOLVE USING FULL HESSIAN\n";
148 algo.
run(*x, nlls,
true, *outStream);
150 *outStream <<
"\nSOLVE USING GAUSS-NEWTON HESSIAN\n";
152 algo.
run(*x, gnnlls,
true, *outStream);
154 catch (std::logic_error err) {
155 *outStream << err.what() <<
"\n";
160 std::cout <<
"End Result: TEST FAILED\n";
162 std::cout <<
"End Result: TEST PASSED\n";
Ptr< Constraint< Real > > getEqualityConstraint(void) const
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.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
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 ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Provides an interface to run optimization algorithms.
Ptr< Objective< Real > > getObjective(void) const
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 .
Ptr< Vector< Real > > getSolution(const int i=0) const
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])
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.
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.
Ptr< Vector< Real > > getInitialGuess(void) const