ROL
step/test_11.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
14 #include "Teuchos_GlobalMPISession.hpp"
15 
16 #include "ROL_HS24.hpp"
17 #include "ROL_Algorithm.hpp"
19 
20 int main(int argc, char *argv[]) {
21 
22 
23 
24 
25  typedef double RealT;
26 
27  typedef ROL::Vector<RealT> V;
28  typedef ROL::BoundConstraint<RealT> BC;
29  typedef ROL::Objective<RealT> OBJ;
30  typedef ROL::InequalityConstraint<RealT> INEQ;
31 
32 
33 
34  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
35 
36  int iprint = argc - 1;
37  ROL::Ptr<std::ostream> outStream;
38  ROL::nullstream bhs; // outputs nothing
39  if (iprint > 0)
40  outStream = ROL::makePtrFromRef(std::cout);
41  else
42  outStream = ROL::makePtrFromRef(bhs);
43 
44  int errorFlag = 0;
45 
46  try {
47 
49  ROL::Ptr<V> x = HS24.getInitialGuess();
50  ROL::Ptr<V> xs = HS24.getSolution();
51  ROL::Ptr<V> inmul = HS24.getInequalityMultiplier();
52 
53  ROL::Ptr<BC> bnd = HS24.getBoundConstraint();
54  ROL::Ptr<OBJ> obj = HS24.getObjective();
55  ROL::Ptr<INEQ> incon = HS24.getInequalityConstraint();
56  ROL::Ptr<BC> inbnd = HS24.getSlackBoundConstraint();
57 
58 
59 
60  std::string stepname = "Interior Point";
61 
62  RealT mu = 0.1; // Initial penalty parameter
63  RealT factor = 0.1; // Penalty reduction factor
64 
65  // Set solver parameters
66  parlist->sublist("Step").sublist("Interior Point").set("Initial Barrier Penalty",mu);
67  parlist->sublist("Step").sublist("Interior Point").set("Minimium Barrier Penalty",1e-8);
68  parlist->sublist("Step").sublist("Interior Point").set("Barrier Penalty Reduction Factor",factor);
69  parlist->sublist("Step").sublist("Interior Point").set("Subproblem Iteration Limit",30);
70 
71  parlist->sublist("Step").sublist("Composite Step").sublist("Optimality System Solver").set("Nominal Relative Tolerance",1.e-4);
72  parlist->sublist("Step").sublist("Composite Step").sublist("Optimality System Solver").set("Fix Tolerance",true);
73  parlist->sublist("Step").sublist("Composite Step").sublist("Tangential Subproblem Solver").set("Iteration Limit",20);
74  parlist->sublist("Step").sublist("Composite Step").sublist("Tangential Subproblem Solver").set("Relative Tolerance",1e-2);
75  parlist->sublist("Step").sublist("Composite Step").set("Output Level",0);
76 
77  parlist->sublist("Status Test").set("Gradient Tolerance",1.e-12);
78  parlist->sublist("Status Test").set("Constraint Tolerance",1.e-8);
79  parlist->sublist("Status Test").set("Step Tolerance",1.e-8);
80  parlist->sublist("Status Test").set("Iteration Limit",100);
81 
82  // Define Optimization Problem
83  ROL::OptimizationProblem<RealT> problem( obj, x, bnd, incon, inmul, inbnd );
84 
85  ROL::Ptr<V> d = x->clone();
86  RandomizeVector(*d);
87 
88 // problem.checkObjectiveGradient(*d);
89 // problem.checkObjectiveHessVec(*d);
90 
91  // Define algorithm.
92  ROL::Ptr<ROL::Algorithm<RealT> > algo;
93  algo = ROL::makePtr<ROL::Algorithm<RealT>>(stepname,*parlist);
94 
95  algo->run(problem,true,*outStream);
96 
97  x->axpy(-1.0,*xs);
98 
99  if( x->norm()>= 1e-4 )
100  {
101  ++errorFlag;
102  }
103 
104  }
105  catch (std::logic_error& err) {
106  *outStream << err.what() << "\n";
107  errorFlag = -1000;
108  }; // end try
109 
110  if (errorFlag != 0)
111  std::cout << "End Result: TEST FAILED\n";
112  else
113  std::cout << "End Result: TEST PASSED\n";
114 
115  return 0;
116 
117 
118 
119 }
Provides the interface to evaluate objective functions.
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS24.hpp:160
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Definition: ROL_HS24.hpp:143
void RandomizeVector(Vector< Real > &x, const Real &lower=0.0, const Real &upper=1.0)
Fill a ROL::Vector with uniformly-distributed random numbers in the interval [lower,upper].
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
Vector< Real > V
Ptr< Vector< Real > > getInequalityMultiplier(void) const
Definition: ROL_HS24.hpp:176
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition: ROL_HS24.hpp:147
Contains definitions for W. Hock and K. Schittkowski 24th test problem which contains bound and inequ...
Provides the interface to apply upper and lower bound constraints.
basic_nullstream< char, char_traits< char >> nullstream
Definition: ROL_Stream.hpp:38
int main(int argc, char *argv[])
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS24.hpp:139
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS24.hpp:168
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Definition: ROL_HS24.hpp:181