ROL
ROL_HS21.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 ROL_HS21_HPP
50#define ROL_HS21_HPP
51
52#include "ROL_StdObjective.hpp"
53#include "ROL_StdConstraint.hpp"
54#include "ROL_StdVector.hpp"
55#include "ROL_TestProblem.hpp"
56#include "ROL_Bounds.hpp"
57
58namespace ROL {
59namespace ZOO {
60
61template<class Real>
62class Objective_HS21 : public StdObjective<Real> {
63public:
64 Real value( const std::vector<Real> &x, Real &tol ) {
65 const Real c1(0.1), c2(100);
66 return c1*x[0]*x[0] + x[1]*x[1] - c2;
67 }
68
69 void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
70 const Real two(2), c1(0.1);
71 g[0] = two*c1*x[0];
72 g[1] = two*x[1];
73 }
74
75 void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
76 const Real two(2), c1(0.1);
77 hv[0] = two*c1*v[0];
78 hv[1] = two*v[1];
79 }
80}; // class Objective_HS21
81
82template<class Real>
83class Constraint_HS21 : public StdConstraint<Real> {
84public:
85 void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
86 const Real c1(10);
87 c[0] = c1*x[0] - x[1] - c1;
88 }
89
90 void applyJacobian( std::vector<Real> &jv, const std::vector<Real> &v,
91 const std::vector<Real> &x, Real &tol ) {
92 const Real c1(10);
93 jv[0] = c1*v[0] - v[1];
94 }
95
96 void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
97 const std::vector<Real> &x, Real &tol ) {
98 const Real c1(10);
99 ajv[0] = c1*v[0];
100 ajv[1] = -v[0];
101 }
102
103 void applyAdjointHessian( std::vector<Real> &ahuv, const std::vector<Real> &u,
104 const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
105 ahuv.assign(ahuv.size(),static_cast<Real>(0));
106 }
107}; // class Constraint_HS21
108
109template<class Real>
110class getHS21 : public TestProblem<Real> {
111public:
112 getHS21(void) {}
113
114 Ptr<Objective<Real> > getObjective( void ) const {
115 return makePtr<Objective_HS21<Real>>();
116 }
117
118 Ptr<Constraint<Real> > getInequalityConstraint( void ) const {
119 return makePtr<Constraint_HS21<Real>>();
120 }
121
122 Ptr<BoundConstraint<Real>> getBoundConstraint( void ) const {
123 Ptr<std::vector<Real>> lp = makePtr<std::vector<Real>>(2,2.0);
124 (*lp)[1] = static_cast<Real>(-50);
125
126 Ptr<Vector<Real>> l = makePtr<StdVector<Real>>(lp);
127 Ptr<Vector<Real>> u = makePtr<StdVector<Real>>(2,50.0);
128
129 return makePtr<Bounds<Real>>(l,u);
130 }
131
132 Ptr<Vector<Real>> getInitialGuess( void ) const {
133 return makePtr<StdVector<Real>>(2,-1.0);
134 }
135
136 Ptr<Vector<Real>> getSolution( const int i = 0 ) const {
137 Ptr<std::vector<Real> > xp = makePtr<std::vector<Real>>(2,0.0);
138 (*xp)[0] = static_cast<Real>(2);
139 return makePtr<StdVector<Real>>(xp);
140 }
141
142 Ptr<Vector<Real>> getInequalityMultiplier( void ) const {
143 return makePtr<StdVector<Real>>(1,0.0);
144 }
145
146 Ptr<BoundConstraint<Real>> getSlackBoundConstraint(void) const {
147 Ptr<Vector<Real>> l = makePtr<StdVector<Real>>(1,0.0);
148 Ptr<Vector<Real>> u = makePtr<StdVector<Real>>(1,ROL_INF<Real>());
149 return makePtr<Bounds<Real>>(l,u);
150 }
151};
152
153} // namespace ZOO
154} // namespace ROL
155
156#endif // ROL_HS21_HPP
Contains definitions of test objective functions.
Defines the equality constraint operator interface for StdVectors.
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector's.
void applyAdjointHessian(std::vector< Real > &ahuv, const std::vector< Real > &u, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS21.hpp:103
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS21.hpp:85
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS21.hpp:96
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS21.hpp:90
Real value(const std::vector< Real > &x, Real &tol)
Definition: ROL_HS21.hpp:64
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS21.hpp:75
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition: ROL_HS21.hpp:69
Ptr< Vector< Real > > getInequalityMultiplier(void) const
Definition: ROL_HS21.hpp:142
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Definition: ROL_HS21.hpp:146
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS21.hpp:132
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Definition: ROL_HS21.hpp:118
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS21.hpp:136
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS21.hpp:114
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition: ROL_HS21.hpp:122