57 #include "Teuchos_GlobalMPISession.hpp"
62 int main(
int argc,
char *argv[]) {
65 typedef std::vector<RealT> vec;
67 typedef ROL::Ptr<ROL::Vector<RealT> > PtrV;
69 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
71 std::string filename =
"input_ex02.xml";
73 auto parlist = ROL::getParametersFromXmlFile( filename );
75 int iprint = argc - 1;
76 ROL::Ptr<std::ostream> outStream;
79 outStream = ROL::makePtrFromRef(std::cout);
81 outStream = ROL::makePtrFromRef(bhs);
90 ROL::Ptr<vec> xopt_ptr = ROL::makePtr<vec>(xopt_dim,1.0);
91 ROL::Ptr<vec> li_ptr = ROL::makePtr<vec>(ci_dim,0.0);
93 PtrV xopt = ROL::makePtr<SV>(xopt_ptr);
94 PtrV li = ROL::makePtr<SV>(li_ptr);
100 ROL::Ptr<ROL::Objective<RealT> > obj_hs29 = ROL::makePtr<Objective_HS29<RealT>>();
101 ROL::Ptr<ROL::Constraint<RealT> > incon_hs29 = ROL::makePtr<InequalityConstraint_HS29<RealT>>();
103 ROL::Ptr<ROL::Vector<RealT> > bndc = li->clone();
104 ROL::Ptr<ROL::BoundConstraint<RealT> > bndcon = ROL::makePtr<ROL::Bounds<RealT> >(*bndc);
106 ROL::Ptr<vec> low_ptr = ROL::makePtr<vec>(xopt_dim, ROL::ROL_NINF<RealT>());
107 ROL::Ptr<vec> upp_ptr = ROL::makePtr<vec>(xopt_dim, ROL::ROL_INF<RealT>());
108 PtrV low = ROL::makePtr<SV>(low_ptr);
109 PtrV upp = ROL::makePtr<SV>(upp_ptr);
110 ROL::Ptr<ROL::BoundConstraint<RealT> > bndx = ROL::makePtr<ROL::Bounds<RealT> >(low, upp);
112 std::string stepname =
"Trust Region";
116 ROL::Ptr<ROL::Objective<RealT> > obj = problem.
getObjective();
117 ROL::Ptr<ROL::Constraint<RealT> > con = problem.
getConstraint();
122 ROL::Ptr<ROL::BoundFletcher<RealT> > fletcher_penalty = ROL::makePtr<ROL::BoundFletcher<RealT> >(obj, con, bndxs, *xs, *lis, *parlist);
124 ROL::Ptr<ROL::Vector<RealT> > v = xs->clone(); v->randomize();
125 std::vector<std::vector<RealT> > gCheck = fletcher_penalty->checkGradient(*xs, *v,
true );
127 ROL::Ptr<ROL::Vector<RealT> > w = xs->clone(); w->randomize();
128 std::vector<RealT> hCheck = fletcher_penalty->checkHessSym( *xs, *v, *w,
true, *outStream);
136 optSolver.
solve(*outStream);
138 *outStream << std::endl << std::setw(20) <<
"Computed Minimizer" << std::endl;
139 for(
int i=0;i<xopt_dim;++i ) {
140 *outStream << std::setw(20) << (*xopt_ptr)[i] << std::endl;
143 *outStream <<
"Exact minimizers: x* = (a,b,c), (a,-b,-c), (-a,b,-c), (-a,-b,c)" << std::endl;
144 *outStream <<
"Where a=4, b=" << 2*std::sqrt(2) <<
", and c=2" << std::endl;
147 catch (std::logic_error& err) {
148 *outStream << err.what() <<
"\n";
153 std::cout <<
"End Result: TEST FAILED\n";
155 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...
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.
basic_nullstream< char, char_traits< char >> nullstream
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)