ROL
ROL_HS38.hpp
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 // Drew Kouri (dpkouri@sandia.gov) and
39 // Denis Ridzal (dridzal@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
49 #ifndef USE_HESSVEC
50 #define USE_HESSVEC 1
51 #endif
52 
53 #ifndef ROL_HS38_HPP
54 #define ROL_HS38_HPP
55 
56 #include "ROL_StdVector.hpp"
57 #include "ROL_Objective.hpp"
59 #include "ROL_Types.hpp"
60 
61 namespace ROL {
62 namespace ZOO {
63 
66  template<class Real>
67  class Objective_HS38 : public Objective<Real> {
68  public:
69  Objective_HS38(void) {}
70 
71  Real value( const Vector<Real> &x, Real &tol ) {
72  Teuchos::RCP<const std::vector<Real> > ex =
73  (Teuchos::dyn_cast<StdVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
74  return 100.0 * std::pow((*ex)[1] - std::pow((*ex)[0],2.0),2.0) + std::pow(1.0-(*ex)[0],2.0) +
75  90.0 * std::pow((*ex)[3] - std::pow((*ex)[2],2.0),2.0) + std::pow(1.0-(*ex)[2],2.0) +
76  10.1 * (std::pow((*ex)[1] - 1.0,2.0) + std::pow((*ex)[3]-1.0,2.0)) +
77  19.8 * ((*ex)[1] - 1.0) * ((*ex)[3] - 1.0);
78  }
79 
80  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
81  Teuchos::RCP<const std::vector<Real> > ex =
82  (Teuchos::dyn_cast<StdVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
83  Teuchos::RCP<std::vector<Real> > eg =
84  Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<StdVector<Real> >(g)).getVector());
85  (*eg)[0] = -4.0 * 100.0 * ((*ex)[1] - std::pow((*ex)[0],2.0)) * (*ex)[0] - 2.0 * (1.0-(*ex)[0]);
86  (*eg)[1] = 2.0 * 100.0 * ((*ex)[1] - std::pow((*ex)[0],2.0)) +
87  2.0 * 10.1 * ((*ex)[1] - 1.0) + 19.8*((*ex)[3] - 1.0);
88  (*eg)[2] = -4.0 * 90.0 * ((*ex)[3] - std::pow((*ex)[2],2.0)) * (*ex)[2] - 2.0 * (1.0-(*ex)[2]);
89  (*eg)[3] = 2.0 * 90.0 * ((*ex)[3] - std::pow((*ex)[2],2.0)) +
90  2.0 * 10.1 * ((*ex)[3] - 1.0) + 19.8*((*ex)[1] - 1.0);
91  }
92 #if USE_HESSVEC
93  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
94  Teuchos::RCP<const std::vector<Real> > ex =
95  (Teuchos::dyn_cast<StdVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
96  Teuchos::RCP<const std::vector<Real> > ev =
97  (Teuchos::dyn_cast<StdVector<Real> >(const_cast<Vector<Real> &>(v))).getVector();
98  Teuchos::RCP<std::vector<Real> > ehv =
99  Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<StdVector<Real> >(hv)).getVector());
100 
101  Real h11 = -4.0 * 100.0 * (*ex)[1] + 12.0 * 100.0 * std::pow((*ex)[0],2.0) + 2.0;
102  Real h12 = -4.0 * 100.0 * (*ex)[0];
103  Real h13 = 0.0;
104  Real h14 = 0.0;
105  Real h21 = -4.0 * 100.0 * (*ex)[0];
106  Real h22 = 2.0 * 100.0 + 2.0 * 10.1;
107  Real h23 = 0.0;
108  Real h24 = 19.8;
109  Real h31 = 0.0;
110  Real h32 = 0.0;
111  Real h33 = -4.0 * 90.0 * (*ex)[3] + 12.0 * 90.0 * std::pow((*ex)[2],2.0) + 2.0;
112  Real h34 = -4.0 * 90.0 * (*ex)[2];
113  Real h41 = 0.0;
114  Real h42 = 19.8;
115  Real h43 = -4.0 * 90.0 * (*ex)[2];
116  Real h44 = 2.0 * 90.0 + 2.0 * 10.1;
117 
118  (*ehv)[0] = h11 * (*ev)[0] + h12 * (*ev)[1] + h13 * (*ev)[2] + h14 * (*ev)[3];
119  (*ehv)[1] = h21 * (*ev)[0] + h22 * (*ev)[1] + h23 * (*ev)[2] + h24 * (*ev)[3];
120  (*ehv)[2] = h31 * (*ev)[0] + h32 * (*ev)[1] + h33 * (*ev)[2] + h34 * (*ev)[3];
121  (*ehv)[3] = h41 * (*ev)[0] + h42 * (*ev)[1] + h43 * (*ev)[2] + h44 * (*ev)[3];
122  }
123 #endif
124  };
125 
126  template<class Real>
127  void getHS38( Teuchos::RCP<Objective<Real> > &obj, Teuchos::RCP<BoundConstraint<Real> > &con,
128  Vector<Real> &x0, Vector<Real> &x ) {
129  // Cast Initial Guess and Solution Vectors
130  Teuchos::RCP<std::vector<Real> > x0p =
131  Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<StdVector<Real> >(x0)).getVector());
132  Teuchos::RCP<std::vector<Real> > xp =
133  Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<StdVector<Real> >(x)).getVector());
134  int n = xp->size();
135  // Resize Vectors
136  n = 4;
137  x0p->resize(n);
138  xp->resize(n);
139  // Instantiate Objective Function
140  obj = Teuchos::rcp( new Objective_HS38<Real> );
141  // Instantiate BoundConstraint
142  std::vector<Real> l(n,-10.0);
143  std::vector<Real> u(n,10.0);
144  con = Teuchos::rcp( new StdBoundConstraint<Real>(l,u) );
145  // Get Initial Guess
146  (*x0p)[0] = -3.0;
147  (*x0p)[1] = -1.0;
148  (*x0p)[2] = -3.0;
149  (*x0p)[3] = -1.0;
150  // Get Solution
151  (*xp)[0] = 1.0;
152  (*xp)[1] = 1.0;
153  (*xp)[2] = 1.0;
154  (*xp)[3] = 1.0;
155  }
156 
157 
158 } // End ZOO Namespace
159 } // End ROL Namespace
160 
161 #endif
Contains definitions for std::vector bound constraints.
Provides the interface to evaluate objective functions.
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Definition: ROL_HS38.hpp:80
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Contains definitions of custom data types in ROL.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:72
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Definition: ROL_HS38.hpp:71
W. Hock and K. Schittkowski 38th test function.
Definition: ROL_HS38.hpp:67
void getHS38(Teuchos::RCP< Objective< Real > > &obj, Teuchos::RCP< BoundConstraint< Real > > &con, Vector< Real > &x0, Vector< Real > &x)
Definition: ROL_HS38.hpp:127
Provides the std::vector implementation of the ROL::Vector interface.
Provides the interface to apply upper and lower bound constraints.