56 #include "Teuchos_oblackholestream.hpp"
57 #include "Teuchos_GlobalMPISession.hpp"
58 #include "Teuchos_XMLParameterListHelpers.hpp"
76 x_lo_.assign(lo.begin(),lo.end());
78 x_up_.assign(up.begin(),up.end());
79 for (
unsigned i = 0; i < (unsigned)
dim_; i++ ) {
90 Teuchos::RCP<const std::vector<Real> > ex =
94 for (
int i = 0; i < this->
dim_; i++ ) {
95 if ( (*ex)[i] >= this->
x_lo_[i] && (*ex)[i] <= this->
x_up_[i] ) { cnt *= 1; }
98 if ( cnt == 0 ) { val =
false; }
102 Teuchos::RCP<std::vector<Real> > ex =
103 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(x)).getVector());
104 for (
int i = 0; i < this->
dim_; i++ ) {
105 (*ex)[i] = std::max(this->
x_lo_[i],std::min(this->
x_up_[i],(*ex)[i]));
109 Teuchos::RCP<const std::vector<Real> > ex =
111 Teuchos::RCP<std::vector<Real> > ev =
112 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(v)).getVector());
113 Real epsn = std::min(eps,this->
min_diff_);
114 for (
int i = 0; i < this->
dim_; i++ ) {
115 if ( ((*ex)[i] <= this->
x_lo_[i]+epsn) ) {
121 Teuchos::RCP<const std::vector<Real> > ex =
123 Teuchos::RCP<std::vector<Real> > ev =
124 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(v)).getVector());
125 Real epsn = std::min(eps,this->
min_diff_);
126 for (
int i = 0; i < this->
dim_; i++ ) {
127 if ( ((*ex)[i] >= this->
x_up_[i]-epsn) ) {
133 Teuchos::RCP<const std::vector<Real> > ex =
135 Teuchos::RCP<const std::vector<Real> > eg =
137 Teuchos::RCP<std::vector<Real> > ev =
138 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(v)).getVector());
139 Real epsn = std::min(eps,this->
min_diff_);
140 for (
int i = 0; i < this->
dim_; i++ ) {
141 if ( ((*ex)[i] <= this->
x_lo_[i]+epsn && (*eg)[i] > 0.0) ){
147 Teuchos::RCP<const std::vector<Real> > ex =
149 Teuchos::RCP<const std::vector<Real> > eg =
151 Teuchos::RCP<std::vector<Real> > ev =
152 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
ROL::StdVector<Real> >(v)).getVector());
153 Real epsn = std::min(eps,this->
min_diff_);
154 for (
int i = 0; i < this->
dim_; i++ ) {
155 if ( ((*ex)[i] >= this->
x_up_[i]-epsn && (*eg)[i] < 0.0) ) {
161 Teuchos::RCP<std::vector<Real> > us = Teuchos::rcp(
new std::vector<Real>(this->
dim_,0.0) );
162 us->assign(this->
x_up_.begin(),this->
x_up_.end());
167 Teuchos::RCP<std::vector<Real> > ls = Teuchos::rcp(
new std::vector<Real>(this->
dim_,0.0) );
168 ls->assign(this->
x_lo_.begin(),this->
x_lo_.end());
202 template <
class Real>
220 if ( (state.
gnorm > this->gtol_) &&
221 (state.
snorm > this->stol_) &&
222 (state.
iter < this->max_iter_) ) {
226 if ( state.
iter < 2 ) {
237 int main(
int argc,
char *argv[]) {
239 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
242 int iprint = argc - 1;
243 Teuchos::RCP<std::ostream> outStream;
244 Teuchos::oblackholestream bhs;
246 outStream = Teuchos::rcp(&std::cout,
false);
248 outStream = Teuchos::rcp(&bhs,
false);
258 std::vector<RealT> lo(dim);
259 std::vector<RealT> up(dim);
260 for (
unsigned i = 0; i < (unsigned)dim; i++ ) {
261 if ( i < (
unsigned)dim/3 || i > 2*(unsigned)dim/3 ) {
272 Teuchos::ParameterList parlist;
274 parlist.set(
"Absolute Krylov Tolerance", 1.e-4);
275 parlist.set(
"Relative Krylov Tolerance", 1.e-2);
276 parlist.set(
"Maximum Number of Krylov Iterations", 50);
278 parlist.set(
"PDAS Relative Step Tolerance", 1.e-8);
279 parlist.set(
"PDAS Relative Gradient Tolerance", 1.e-6);
280 parlist.set(
"PDAS Maximum Number of Iterations", 1);
281 parlist.set(
"PDAS Dual Scaling", alpha);
295 Teuchos::RCP<std::vector<RealT> > x_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
297 for (
int i=0; i<dim; i++) {
303 algo_pdas.
run(x, obj, icon,
true);
306 file.open(
"control_PDAS.txt");
307 for (
unsigned i = 0; i < (unsigned)dim; i++ ) {
308 file << (*x_rcp)[i] <<
"\n";
313 std::string filename =
"input.xml";
314 Teuchos::RCP<Teuchos::ParameterList> parlist_tr = Teuchos::rcp(
new Teuchos::ParameterList() );
315 Teuchos::updateParametersFromXmlFile( filename, Teuchos::Ptr<Teuchos::ParameterList>(&*parlist_tr) );
320 Teuchos::RCP<std::vector<RealT> > y_rcp = Teuchos::rcp(
new std::vector<RealT> (dim, 0.0) );
322 for (
int i=0; i<dim; i++) {
327 algo_tr.
run(y,obj,icon,
true);
329 std::ofstream file_tr;
330 file_tr.open(
"control_TR.txt");
331 for (
unsigned i = 0; i < (unsigned)dim; i++ ) {
332 file_tr << (*y_rcp)[i] <<
"\n";
336 Teuchos::RCP<ROL::Vector<RealT> > error = x.
clone();
339 std::cout <<
"\nError between PDAS solution and TR solution is " << error->norm() <<
"\n";
342 catch (std::logic_error err) {
343 *outStream << err.what() <<
"\n";
348 std::cout <<
"End Result: TEST FAILED\n";
350 std::cout <<
"End Result: TEST PASSED\n";
Implements the computation of optimization steps with the Newton primal-dual active set method...
std::vector< Real > x_lo_
int main(int argc, char *argv[])
StatusTest_PDAS(Real gtol=1.e-6, Real stol=1.e-12, int max_iter=100)
std::vector< Real > x_up_
void project(ROL::Vector< Real > &x)
Project optimization variables onto the bounds.
BoundConstraint_PoissonControl(std::vector< Real > &lo, std::vector< Real > &up)
Contains definitions of custom data types in ROL.
Contains definitions for Poisson optimal control.
Defines the linear algebra or vector space interface.
Teuchos::RCP< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
State for algorithm class. Will be used for restarts.
void setVectorToLowerBound(ROL::Vector< Real > &l)
Set the input vector to the lower bound.
Provides the std::vector implementation of the ROL::Vector interface.
virtual std::vector< std::string > run(Vector< Real > &x, Objective< Real > &obj, bool print=false, std::ostream &outStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This is the primary Type-U interface.
Poisson distributed control.
Provides an interface to check status of optimization algorithms.
void pruneUpperActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the upper -active set.
bool isFeasible(const ROL::Vector< Real > &x)
Check if the vector, v, is feasible.
Provides the interface to apply upper and lower bound constraints.
void pruneLowerActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the lower -binding set.
void pruneLowerActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the lower -active set.
virtual void set(const Vector &x)
Set where .
virtual ~StatusTest_PDAS()
virtual bool check(ROL::AlgorithmState< Real > &state)
Check algorithm status.
void setVectorToUpperBound(ROL::Vector< Real > &u)
Set the input vector to the upper bound.
void pruneUpperActive(ROL::Vector< Real > &v, const ROL::Vector< Real > &g, const ROL::Vector< Real > &x, Real eps)
Set variables to zero if they correspond to the upper -binding set.
Provides the interface to compute optimization steps with trust regions.