14 int main(
int argc,
char* argv[]) {
16 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
17 ROL::Ptr<const Teuchos::Comm<int>> comm
18 = ROL::toPtr(Teuchos::DefaultComm<int>::getComm());
21 int iprint = argc - 1;
22 ROL::Ptr<std::ostream> outStream;
24 if (iprint > 0 && Teuchos::rank<int>(*comm)==0)
25 outStream = ROL::makePtrFromRef(std::cout);
27 outStream = ROL::makePtrFromRef(bhs);
33 auto parlist = ROL::getParametersFromXmlFile(
"input_ex10.xml");
38 ROL::Ptr<ROL::Vector<RealT>> z = ROL::makePtr<ROL::StdVector<RealT>>(nx+2,0.0);
39 ROL::Ptr<ROL::Vector<RealT>> u = ROL::makePtr<ROL::StdVector<RealT>>(nx,1.0);
40 ROL::Ptr<ROL::Vector<RealT>> p = ROL::makePtr<ROL::StdVector<RealT>>(nx,0.0);
45 int dim = 4, nSamp = parlist->sublist(
"Problem").get(
"Number of Samples",100);
46 std::vector<RealT> tmp = {-1, 1};
47 std::vector<std::vector<RealT>> bounds(dim,tmp);
48 ROL::Ptr<ROL::BatchManager<RealT>> bman
49 = ROL::makePtr<ROL::StdTeuchosBatchManager<RealT,int>>(comm);
50 ROL::Ptr<ROL::SampleGenerator<RealT>> sampler
51 = ROL::makePtr<ROL::MonteCarloGenerator<RealT>>(nSamp,bounds,bman);
57 ROL::Ptr<ROL::Objective_SimOpt<RealT>> objSimOpt
58 = ROL::makePtr<Objective_BurgersControl<RealT>>(alpha,nx);
59 ROL::Ptr<ROL::Constraint_SimOpt<RealT>> conSimOpt
60 = ROL::makePtr<Constraint_BurgersControl<RealT>>(nx);
61 conSimOpt->setSolveParameters(*parlist);
62 ROL::Ptr<ROL::Objective<RealT>> robj
63 = ROL::makePtr<ROL::Reduced_Objective_SimOpt<RealT>>(objSimOpt,conSimOpt,u,z,p);
67 bool runBundle = parlist->sublist(
"Problem").get(
"Run Bundle",
false);
71 ROL::Ptr<ROL::OptimizationProblem<double>> problem2
72 = ROL::makePtr<ROL::OptimizationProblem<double>>(robj, z);
73 problem2->setStochasticObjective(*parlist, sampler);
74 parlist->sublist(
"Step").set(
"Type",
"Bundle");
75 parlist->sublist(
"Step").sublist(
"Bundle").set(
"Distance Measure Coefficient",0.0);
77 solver2.
solve(*outStream);
80 ROL::Ptr<ROL::Problem<double>> problem
81 = ROL::makePtr<ROL::Problem<double>>(robj, z);
83 if (parlist->sublist(
"Problem").get(
"Run Derivative Check",
false)) {
84 problem->check(
true,*outStream);
85 solver.check(*outStream);
87 solver.run(*outStream);
89 catch (std::logic_error& err) {
90 *outStream << err.what() <<
"\n";
95 std::cout <<
"End Result: TEST FAILED\n";
97 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.