48 int main(
int argc,
char* argv[]) {
50 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
51 ROL::Ptr<const Teuchos::Comm<int>> comm
52 = ROL::toPtr(Teuchos::DefaultComm<int>::getComm());
55 int iprint = argc - 1;
56 ROL::Ptr<std::ostream> outStream;
58 if (iprint > 0 && Teuchos::rank<int>(*comm)==0)
59 outStream = ROL::makePtrFromRef(std::cout);
61 outStream = ROL::makePtrFromRef(bhs);
67 auto parlist = ROL::getParametersFromXmlFile(
"input_ex10.xml");
72 ROL::Ptr<ROL::Vector<RealT>> z = ROL::makePtr<ROL::StdVector<RealT>>(nx+2,0.0);
73 ROL::Ptr<ROL::Vector<RealT>> u = ROL::makePtr<ROL::StdVector<RealT>>(nx,1.0);
74 ROL::Ptr<ROL::Vector<RealT>> p = ROL::makePtr<ROL::StdVector<RealT>>(nx,0.0);
79 int dim = 4, nSamp = parlist->sublist(
"Problem").get(
"Number of Samples",100);
80 std::vector<RealT> tmp = {-1, 1};
81 std::vector<std::vector<RealT>> bounds(dim,tmp);
82 ROL::Ptr<ROL::BatchManager<RealT>> bman
83 = ROL::makePtr<ROL::StdTeuchosBatchManager<RealT,int>>(comm);
84 ROL::Ptr<ROL::SampleGenerator<RealT>> sampler
85 = ROL::makePtr<ROL::MonteCarloGenerator<RealT>>(nSamp,bounds,bman);
91 ROL::Ptr<ROL::Objective_SimOpt<RealT>> objSimOpt
92 = ROL::makePtr<Objective_BurgersControl<RealT>>(alpha,nx);
93 ROL::Ptr<ROL::Constraint_SimOpt<RealT>> conSimOpt
94 = ROL::makePtr<Constraint_BurgersControl<RealT>>(nx);
95 conSimOpt->setSolveParameters(*parlist);
96 ROL::Ptr<ROL::Objective<RealT>> robj
97 = ROL::makePtr<ROL::Reduced_Objective_SimOpt<RealT>>(objSimOpt,conSimOpt,u,z,p);
101 bool runBundle = parlist->sublist(
"Problem").get(
"Run Bundle",
false);
105 ROL::Ptr<ROL::OptimizationProblem<double>> problem2
106 = ROL::makePtr<ROL::OptimizationProblem<double>>(robj, z);
107 problem2->setStochasticObjective(*parlist, sampler);
108 parlist->sublist(
"Step").set(
"Type",
"Bundle");
109 parlist->sublist(
"Step").sublist(
"Bundle").set(
"Distance Measure Coefficient",0.0);
111 solver2.
solve(*outStream);
114 ROL::Ptr<ROL::OptimizationProblem<double>> problem
115 = ROL::makePtr<ROL::OptimizationProblem<double>>(robj, z);
117 if (parlist->sublist(
"Problem").get(
"Run Derivative Check",
false)) {
118 problem->check(*outStream);
119 solver.check(*outStream);
121 solver.run(*outStream);
123 catch (std::logic_error& err) {
124 *outStream << err.what() <<
"\n";
129 std::cout <<
"End Result: TEST FAILED\n";
131 std::cout <<
"End Result: TEST PASSED\n";
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.