ROL
step/test_11.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Rapid Optimization Library (ROL) Package
5 // Copyright (2014) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact lead developers:
38 //
39 // Drew Kouri (dpkouri@sandia.gov) and
40 // Denis Ridzal (dridzal@sandia.gov)
41 //
42 // ************************************************************************
43 // @HEADER
44 
49 #include "ROL_HS24.hpp"
50 #include "ROL_Algorithm.hpp"
52 
53 int main(int argc, char *argv[]) {
54 
55  using Teuchos::RCP;
56  using Teuchos::rcp;
57 
58  typedef double RealT;
59 
60  typedef ROL::Vector<RealT> V;
61  typedef ROL::BoundConstraint<RealT> BC;
62  typedef ROL::Objective<RealT> OBJ;
64 
65  using Teuchos::RCP;
66 
67  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
68 
69  int iprint = argc - 1;
70  RCP<std::ostream> outStream;
71  Teuchos::oblackholestream bhs; // outputs nothing
72  if (iprint > 0)
73  outStream = rcp(&std::cout, false);
74  else
75  outStream = rcp(&bhs, false);
76 
77  int errorFlag = 0;
78 
79  try {
80 
81  RCP<V> x = ROL::ZOO::getInitialGuess_HS24<RealT>();
82  RCP<V> xs = ROL::ZOO::getSolution_HS24<RealT>();
83  RCP<V> inmul = ROL::ZOO::getInequalityMultiplier_HS24<RealT>();
84 
85  RCP<BC> bnd = ROL::ZOO::getBoundConstraint_HS24<RealT>();
86  RCP<OBJ> obj = ROL::ZOO::getObjective_HS24<RealT>();
87  RCP<INEQ> incon = ROL::ZOO::getInequalityConstraint_HS24<RealT>();
88 
89  RCP<Teuchos::ParameterList> parlist = rcp( new Teuchos::ParameterList );
90 
91  std::string stepname = "Interior Point";
92 
93  RealT mu = 0.1; // Initial penalty parameter
94  RealT factor = 0.1; // Penalty reduction factor
95 
96  // Set solver parameters
97  parlist->sublist("Step").sublist("Interior Point").set("Initial Barrier Penalty",mu);
98  parlist->sublist("Step").sublist("Interior Point").set("Minimium Barrier Penalty",1e-8);
99  parlist->sublist("Step").sublist("Interior Point").set("Barrier Penalty Reduction Factor",factor);
100  parlist->sublist("Step").sublist("Interior Point").set("Subproblem Iteration Limit",30);
101 
102  parlist->sublist("Step").sublist("Composite Step").sublist("Optimality System Solver").set("Nominal Relative Tolerance",1.e-4);
103  parlist->sublist("Step").sublist("Composite Step").sublist("Optimality System Solver").set("Fix Tolerance",true);
104  parlist->sublist("Step").sublist("Composite Step").sublist("Tangential Subproblem Solver").set("Iteration Limit",20);
105  parlist->sublist("Step").sublist("Composite Step").sublist("Tangential Subproblem Solver").set("Relative Tolerance",1e-2);
106  parlist->sublist("Step").sublist("Composite Step").set("Output Level",0);
107 
108  parlist->sublist("Status Test").set("Gradient Tolerance",1.e-12);
109  parlist->sublist("Status Test").set("Constraint Tolerance",1.e-8);
110  parlist->sublist("Status Test").set("Step Tolerance",1.e-8);
111  parlist->sublist("Status Test").set("Iteration Limit",100);
112 
113  // Define Optimization Problem
114  ROL::OptimizationProblem<RealT> problem( obj, x, bnd, incon, inmul, parlist );
115 
116  RCP<V> d = x->clone();
117  RandomizeVector(*d);
118 
119 // problem.checkObjectiveGradient(*d);
120 // problem.checkObjectiveHessVec(*d);
121 
122  // Define algorithm.
123  RCP<ROL::Algorithm<RealT> > algo;
124  algo = rcp( new ROL::Algorithm<RealT>(stepname,*parlist) );
125 
126  algo->run(problem,true,*outStream);
127 
128  x->axpy(-1.0,*xs);
129 
130  if( x->norm()>= 1e-4 )
131  {
132  ++errorFlag;
133  }
134 
135  }
136  catch (std::logic_error err) {
137  *outStream << err.what() << "\n";
138  errorFlag = -1000;
139  }; // end try
140 
141  if (errorFlag != 0)
142  std::cout << "End Result: TEST FAILED\n";
143  else
144  std::cout << "End Result: TEST PASSED\n";
145 
146  return 0;
147 
148 
149 
150 }
Provides the interface to evaluate objective functions.
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].
int main(int argc, char *argv[])
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
Provides an interface to run optimization algorithms.
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.
double RealT
Provides a unique argument for inequality constraints, which otherwise behave exactly as equality con...