ROL
ROL_Quartic.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_QUARTIC_HPP
54#define ROL_QUARTIC_HPP
55
57#include "ROL_StdObjective.hpp"
58#include "ROL_StdConstraint.hpp"
59#include "ROL_TestProblem.hpp"
60
61namespace ROL {
62namespace ZOO {
63
64 template<class Real>
65 class Objective_Quartic : public StdObjective<Real> {
66 public:
68
69 Real value( const std::vector<Real> &x, Real &tol ) {
70 const Real one(1);
71 return std::pow(x[0]-one, 4) + std::pow(x[1]-one, 4);
72 }
73
74 void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
75 const Real one(1), four(4);
76 g[0] = four * std::pow(x[0]-one, 3);
77 g[1] = four * std::pow(x[1]-one, 3);
78 }
79#if USE_HESSVEC
80 void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
81 const Real one(1), twelve(12);
82 hv[0] = twelve * std::pow(x[0]-one, 2) * v[0];
83 hv[1] = twelve * std::pow(x[1]-one, 2) * v[1];
84 }
85#endif
86 };
87
88 template<class Real>
89 class Constraint_Quartic : public StdConstraint<Real> {
90 public:
92
93 void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
94 const Real half(0.5);
95 c[0] = std::pow(x[0], 2) - half*x[1];
96 c[1] = std::pow(x[1], 2) - half*x[0];
97 }
98
99 void applyJacobian( std::vector<Real> &jv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
100 const Real half(0.5), two(2);
101 jv[0] = two*x[0]*v[0] - half*v[1];
102 jv[1] = two*x[1]*v[1] - half*v[0];
103 }
104
105 void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
106 const Real half(0.5), two(2);
107 ajv[0] = two*x[0]*v[0] - half*v[1];
108 ajv[1] = two*x[1]*v[1] - half*v[0];
109 }
110#if USE_HESSVEC
111 void applyAdjointHessian( std::vector<Real> &ahuv, const std::vector<Real> &u, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
112 const Real two(2);
113 ahuv[0] = two*u[0]*v[0];
114 ahuv[1] = two*u[1]*v[1];
115 }
116#endif
117 };
118
119 template<class Real>
120 class getQuartic : public TestProblem<Real> {
121 public:
123
124 Ptr<Objective<Real>> getObjective(void) const {
125 return makePtr<Objective_Quartic<Real>>();
126 }
127
128 Ptr<Vector<Real>> getInitialGuess(void) const {
129 int n = 2;
130 Ptr<std::vector<Real>> scale = makePtr<std::vector<Real>>(n,static_cast<Real>(1.0));
131 Ptr<std::vector<Real>> xp = makePtr<std::vector<Real>>(n,static_cast<Real>(1.0));
132 return makePtr<PrimalScaledStdVector<Real>>(xp,scale);
133 }
134
135 Ptr<Vector<Real>> getSolution(const int i = 0) const {
136 int n = 2;
137 Ptr<std::vector<Real>> scale = makePtr<std::vector<Real>>(n,static_cast<Real>(1.0));
138 Ptr<std::vector<Real>> xp = makePtr<std::vector<Real>>(n,static_cast<Real>(0.5));
139 return makePtr<PrimalScaledStdVector<Real>>(xp,scale);
140 }
141
142 Ptr<BoundConstraint<Real>> getBoundConstraint(void) const {
143 int n = 2;
144 Ptr<std::vector<Real>> scale = makePtr<std::vector<Real>>(n,static_cast<Real>(1.0));
145 Ptr<std::vector<Real>> lp = makePtr<std::vector<Real>>(n,static_cast<Real>(0.0));
146 Ptr<std::vector<Real>> up = makePtr<std::vector<Real>>(n,static_cast<Real>(0.0));
147 (*lp)[0] = static_cast<Real>( 0.5);
148 (*lp)[1] = static_cast<Real>(-2.9);
149 (*up)[0] = static_cast<Real>( 5.8);
150 (*up)[1] = static_cast<Real>( 2.9);
151 Ptr<Vector<Real>> l = makePtr<PrimalScaledStdVector<Real>>(lp,scale);
152 Ptr<Vector<Real>> u = makePtr<PrimalScaledStdVector<Real>>(up,scale);
153 return makePtr<Bounds<Real>>(l,u);
154 }
155
156 Ptr<Constraint<Real>> getInequalityConstraint(void) const {
157 return makePtr<Constraint_Quartic<Real>>();
158 }
159
160 Ptr<Vector<Real>> getInequalityMultiplier(void) const {
161 Ptr<std::vector<Real>> scale = makePtr<std::vector<Real>>(2,static_cast<Real>(1.0));
162 Ptr<std::vector<Real>> lp = makePtr<std::vector<Real>>(2,static_cast<Real>(0.0));
163 return makePtr<DualScaledStdVector<Real>>(lp,scale);
164 }
165
166 Ptr<BoundConstraint<Real>> getSlackBoundConstraint(void) const {
167 Ptr<std::vector<Real>> scale = makePtr<std::vector<Real>>(2,static_cast<Real>(1.0));
168 Ptr<std::vector<Real>> up = makePtr<std::vector<Real>>(2,static_cast<Real>(0.0));
169 Ptr<Vector<Real>> u = makePtr<DualScaledStdVector<Real>>(up,scale);
170 return makePtr<Bounds<Real>>(*u,false);
171 }
172 };
173
174}// End ZOO Namespace
175}// End ROL Namespace
176
177#endif
Contains definitions of test objective functions.
Defines the equality constraint operator interface for StdVectors.
void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply the derivative of the adjoint of the constraint Jacobian at to vector in direction ,...
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector's.
virtual void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Definition: ROL_Quartic.hpp:93
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Definition: ROL_Quartic.hpp:99
Real value(const std::vector< Real > &x, Real &tol)
Definition: ROL_Quartic.hpp:69
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
Definition: ROL_Quartic.hpp:74
Ptr< Objective< Real > > getObjective(void) const
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Ptr< Vector< Real > > getSolution(const int i=0) const
Ptr< Vector< Real > > getInequalityMultiplier(void) const
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Ptr< Vector< Real > > getInitialGuess(void) const