ROL
ROL_HS3.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_HS3_HPP
54#define ROL_HS3_HPP
55
56#include "ROL_StdVector.hpp"
57#include "ROL_TestProblem.hpp"
58#include "ROL_Bounds.hpp"
59#include "ROL_Types.hpp"
60
61namespace ROL {
62namespace ZOO {
63
66 template<class Real>
67 class Objective_HS3 : public Objective<Real> {
68
69 typedef std::vector<Real> vector;
70 typedef Vector<Real> V;
72
73 private:
74
75 ROL::Ptr<const vector> getVector( const V& x ) {
76
77 return dynamic_cast<const SV&>(x).getVector();
78 }
79
80 ROL::Ptr<vector> getVector( V& x ) {
81
82 return dynamic_cast<SV&>(x).getVector();
83 }
84
85 public:
87
88 Real value( const Vector<Real> &x, Real &tol ) {
89
90
91 ROL::Ptr<const vector> ex = getVector(x);
92 return (*ex)[1] + 1.e-5 * std::pow((*ex)[1] - (*ex)[0],2.0);
93 }
94
95 void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
96
97
98 ROL::Ptr<const vector> ex = getVector(x);
99 ROL::Ptr<vector> eg = getVector(g);
100 (*eg)[0] = -1.e-5 * 2.0 * ((*ex)[1] - (*ex)[0]);
101 (*eg)[1] = 1.0 + 1.e-5 * 2.0 * ((*ex)[1] - (*ex)[0]);
102 }
103#if USE_HESSVEC
104 void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
105
106
107 ROL::Ptr<const vector> ex = getVector(x);
108 ROL::Ptr<const vector> ev = getVector(v);
109 ROL::Ptr<vector> ehv = getVector(hv);
110 Real h11 = 1.e-5 * 2.0;
111 Real h22 = 1.e-5 * 2.0;
112 Real h12 = -1.e-5 * 2.0;
113 Real h21 = -1.e-5 * 2.0;
114
115 (*ehv)[0] = h11 * (*ev)[0] + h12 * (*ev)[1];
116 (*ehv)[1] = h21 * (*ev)[0] + h22 * (*ev)[1];
117 }
118#endif
119 void invHessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
120
121
122 ROL::Ptr<const vector> ex = getVector(x);
123 ROL::Ptr<const vector> ev = getVector(v);
124 ROL::Ptr<vector> ehv = getVector(hv);
125
126 Real h11 = 1.e-5 * 2.0;
127 Real h22 = 1.e-5 * 2.0;
128 Real h12 = -1.e-5 * 2.0;
129 Real h21 = -1.e-5 * 2.0;
130
131 (*ehv)[0] = 1.0/(h11*h22 - h12*h21) * (h22 * (*ev)[0] - h12 * (*ev)[1]);
132 (*ehv)[1] = 1.0/(h11*h22 - h12*h21) * (-h21 * (*ev)[0] + h11 * (*ev)[1]);
133 }
134 };
135
136template<class Real>
137class getHS3 : public TestProblem<Real> {
138public:
139 getHS3(void) {}
140
141 Ptr<Objective<Real>> getObjective(void) const {
142 // Instantiate Objective Function
143 return ROL::makePtr<Objective_HS3<Real>>();
144 }
145
146 Ptr<Vector<Real>> getInitialGuess(void) const {
147 // Problem dimension
148 int n = 2;
149 // Get Initial Guess
150 ROL::Ptr<std::vector<Real> > x0p = ROL::makePtr<std::vector<Real>>(n,0.0);
151 (*x0p)[0] = 10.0; (*x0p)[1] = 1.0;
152 return ROL::makePtr<StdVector<Real>>(x0p);
153 }
154
155 Ptr<Vector<Real>> getSolution(const int i = 0) const {
156 // Problem dimension
157 int n = 2;
158 // Get Solution
159 ROL::Ptr<std::vector<Real> > xp = ROL::makePtr<std::vector<Real>>(n,0.0);
160 (*xp)[0] = 0.0; (*xp)[1] = 0.0;
161 return ROL::makePtr<StdVector<Real>>(xp);
162 }
163
164 Ptr<BoundConstraint<Real>> getBoundConstraint(void) const {
165 // Problem dimension
166 int n = 2;
167 // Instantiate BoundConstraint
168 ROL::Ptr<std::vector<Real> > lp = ROL::makePtr<std::vector<Real>>(n,0.0);
169 (*lp)[0] = ROL_NINF<Real>(); (*lp)[1] = 0.0;
170 ROL::Ptr<Vector<Real> > l = ROL::makePtr<StdVector<Real>>(lp);
171 ROL::Ptr<std::vector<Real> > up = ROL::makePtr<std::vector<Real>>(n,0.0);
172 (*up)[0] = ROL_INF<Real>(); (*up)[1] = ROL_INF<Real>();
173 ROL::Ptr<Vector<Real> > u = ROL::makePtr<StdVector<Real>>(up);
174 return ROL::makePtr<Bounds<Real>>(l,u);
175 }
176};
177
178} // End ZOO Namespace
179} // End ROL Namespace
180
181#endif
Contains definitions of test objective functions.
Contains definitions of custom data types in ROL.
Provides the interface to evaluate objective functions.
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:84
W. Hock and K. Schittkowski 3rd test function.
Definition: ROL_HS3.hpp:67
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Definition: ROL_HS3.hpp:95
Vector< Real > V
Definition: ROL_HS3.hpp:70
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Definition: ROL_HS3.hpp:88
ROL::Ptr< vector > getVector(V &x)
Definition: ROL_HS3.hpp:80
StdVector< Real > SV
Definition: ROL_HS3.hpp:71
ROL::Ptr< const vector > getVector(const V &x)
Definition: ROL_HS3.hpp:75
std::vector< Real > vector
Definition: ROL_HS3.hpp:69
void invHessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply inverse Hessian approximation to vector.
Definition: ROL_HS3.hpp:119
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS3.hpp:146
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS3.hpp:155
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition: ROL_HS3.hpp:164
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS3.hpp:141