57 #include "Teuchos_oblackholestream.hpp" 58 #include "Teuchos_GlobalMPISession.hpp" 59 #include "Teuchos_XMLParameterListHelpers.hpp" 80 gtol_(gtol), stol_(stol), max_iter_(max_iter) {}
85 if ( (state.
gnorm > this->gtol_) &&
86 (state.
snorm > this->stol_) &&
87 (state.
iter < this->max_iter_) ) {
91 if ( state.
iter < 2 ) {
102 int main(
int argc,
char *argv[]) {
104 typedef std::vector<RealT> vector;
108 typedef typename vector::size_type uint;
110 using Teuchos::RCP;
using Teuchos::rcp;
112 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
115 int iprint = argc - 1;
116 Teuchos::RCP<std::ostream> outStream;
117 Teuchos::oblackholestream bhs;
119 outStream = Teuchos::rcp(&std::cout,
false);
121 outStream = Teuchos::rcp(&bhs,
false);
132 RCP<vector> l_rcp = rcp(
new vector(dim) );
133 RCP<vector> u_rcp = rcp(
new vector(dim) );
135 RCP<V> lo = rcp(
new SV(l_rcp) );
136 RCP<V> up = rcp(
new SV(u_rcp) );
138 for ( uint i = 0; i < dim; i++ ) {
139 if ( i < dim/3.0 || i > 2*dim/3.0 ) {
151 std::string filename =
"input.xml";
152 RCP<Teuchos::ParameterList> parlist = rcp(
new Teuchos::ParameterList() );
153 Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() );
156 parlist->sublist(
"General").sublist(
"Krylov").set(
"Absolute Tolerance",1.e-4);
157 parlist->sublist(
"General").sublist(
"Krylov").set(
"Relative Tolerance",1.e-2);
158 parlist->sublist(
"General").sublist(
"Krylov").set(
"Iteration Limit",50);
161 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Step Tolerance",1.e-8);
162 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Gradient Tolerance",1.e-6);
163 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Iteration Limit", 1);
164 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Dual Scaling",(alpha>0.0)?alpha:1.e-4);
167 parlist->sublist(
"Status Test").set(
"Gradient Tolerance",1.e-12);
168 parlist->sublist(
"Status Test").set(
"Step Tolerance",1.e-14);
169 parlist->sublist(
"Status Test").set(
"Iteration Limit",100);
172 RCP<ROL::Algorithm<RealT> > algo = rcp(
new ROL::Algorithm<RealT>(
"Primal Dual Active Set",*parlist,
false));
175 RCP<vector> x_rcp = rcp(
new vector(dim, 0.0) );
180 algo->run(x, obj, icon,
true, *outStream);
182 file.open(
"control_PDAS.txt");
184 for ( uint i = 0; i < dim; i++ ) {
185 file << (*x_rcp)[i] <<
"\n";
191 Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() );
195 RCP<vector> y_rcp = rcp(
new vector(dim, 0.0) );
200 algo->run(y, obj, icon,
true, *outStream);
202 std::ofstream file_tr;
203 file_tr.open(
"control_TR.txt");
204 for ( uint i = 0; i < dim; i++ ) {
205 file_tr << (*y_rcp)[i] <<
"\n";
209 RCP<V> error = x.clone();
212 *outStream <<
"\nError between PDAS solution and TR solution is " << error->norm() <<
"\n";
215 catch (std::logic_error err) {
216 *outStream << err.what() <<
"\n";
221 std::cout <<
"End Result: TEST FAILED\n";
223 std::cout <<
"End Result: TEST PASSED\n";
int main(int argc, char *argv[])
StatusTest_PDAS(Real gtol=1.e-6, Real stol=1.e-12, int max_iter=100)
Contains definitions of custom data types in ROL.
Contains definitions for Poisson optimal control.
Defines the linear algebra or vector space interface.
State for algorithm class. Will be used for restarts.
Provides the std::vector implementation of the ROL::Vector interface.
Poisson distributed control.
Provides an interface to run optimization algorithms.
Provides an interface to check status of optimization algorithms.
Provides the interface to apply upper and lower bound constraints.
virtual ~StatusTest_PDAS()
virtual bool check(ROL::AlgorithmState< Real > &state)
Check algorithm status.
static const double ROL_EPSILON
Platform-dependent machine epsilon.