22 #include "Teuchos_GlobalMPISession.hpp"
27 int main(
int argc,
char *argv[]) {
30 typedef std::vector<RealT> vec;
32 typedef ROL::Ptr<ROL::Vector<RealT> > PtrV;
34 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
36 std::string filename =
"input_ex02.xml";
38 auto parlist = ROL::getParametersFromXmlFile( filename );
40 int iprint = argc - 1;
41 ROL::Ptr<std::ostream> outStream;
44 outStream = ROL::makePtrFromRef(std::cout);
46 outStream = ROL::makePtrFromRef(bhs);
55 ROL::Ptr<vec> xopt_ptr = ROL::makePtr<vec>(xopt_dim,1.0);
56 ROL::Ptr<vec> li_ptr = ROL::makePtr<vec>(ci_dim,0.0);
58 PtrV xopt = ROL::makePtr<SV>(xopt_ptr);
59 PtrV li = ROL::makePtr<SV>(li_ptr);
65 ROL::Ptr<ROL::Objective<RealT> > obj_hs29 = ROL::makePtr<Objective_HS29<RealT>>();
66 ROL::Ptr<ROL::Constraint<RealT> > incon_hs29 = ROL::makePtr<InequalityConstraint_HS29<RealT>>();
68 ROL::Ptr<ROL::Vector<RealT> > bndc = li->clone();
69 ROL::Ptr<ROL::BoundConstraint<RealT> > bndcon = ROL::makePtr<ROL::Bounds<RealT> >(*bndc);
71 ROL::Ptr<vec> low_ptr = ROL::makePtr<vec>(xopt_dim, ROL::ROL_NINF<RealT>());
72 ROL::Ptr<vec> upp_ptr = ROL::makePtr<vec>(xopt_dim, ROL::ROL_INF<RealT>());
73 PtrV low = ROL::makePtr<SV>(low_ptr);
74 PtrV upp = ROL::makePtr<SV>(upp_ptr);
75 ROL::Ptr<ROL::BoundConstraint<RealT> > bndx = ROL::makePtr<ROL::Bounds<RealT> >(low, upp);
77 std::string stepname =
"Trust Region";
81 ROL::Ptr<ROL::Objective<RealT> > obj = problem.
getObjective();
82 ROL::Ptr<ROL::Constraint<RealT> > con = problem.
getConstraint();
87 ROL::Ptr<ROL::BoundFletcher<RealT> > fletcher_penalty = ROL::makePtr<ROL::BoundFletcher<RealT> >(obj, con, bndxs, *xs, *lis, *parlist);
89 ROL::Ptr<ROL::Vector<RealT> > v = xs->clone(); v->randomize();
90 std::vector<std::vector<RealT> > gCheck = fletcher_penalty->checkGradient(*xs, *v,
true );
92 ROL::Ptr<ROL::Vector<RealT> > w = xs->clone(); w->randomize();
93 std::vector<RealT> hCheck = fletcher_penalty->checkHessSym( *xs, *v, *w,
true, *outStream);
101 optSolver.
solve(*outStream);
103 *outStream << std::endl << std::setw(20) <<
"Computed Minimizer" << std::endl;
104 for(
int i=0;i<xopt_dim;++i ) {
105 *outStream << std::setw(20) << (*xopt_ptr)[i] << std::endl;
108 *outStream <<
"Exact minimizers: x* = (a,b,c), (a,-b,-c), (-a,b,-c), (-a,-b,c)" << std::endl;
109 *outStream <<
"Where a=4, b=" << 2*std::sqrt(2) <<
", and c=2" << std::endl;
112 catch (std::logic_error& err) {
113 *outStream << err.what() <<
"\n";
118 std::cout <<
"End Result: TEST FAILED\n";
120 std::cout <<
"End Result: TEST PASSED\n";
Contains definitions for W. Hock and K. Schittkowski 32nd test problem which contains only inequality...
virtual Ptr< Objective< Real > > getObjective(void)
virtual Ptr< BoundConstraint< Real > > getBoundConstraint(void)
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
basic_nullstream< char, std::char_traits< char >> nullstream
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
virtual Ptr< Vector< Real > > getSolutionVector(void)
virtual Ptr< Vector< Real > > getMultiplierVector(void)
Provides a simplified interface for solving a wide range of optimization problems.
int main(int argc, char *argv[])
int solve(const ROL::Ptr< StatusTest< Real > > &status=ROL::nullPtr, const bool combineStatus=true)
Solve optimization problem with no iteration output.
virtual Ptr< Constraint< Real > > getConstraint(void)