19#ifndef ROL_PARABOLOIDCIRCLE_HPP
20#define ROL_PARABOLOIDCIRCLE_HPP
24#include "ROL_LinearAlgebra.hpp"
32 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real> >
38 typedef typename vector::size_type
uint;
43 template<
class VectorType>
46 return dynamic_cast<const VectorType&
>(x).
getVector();
49 template<
class VectorType>
52 return dynamic_cast<VectorType&
>(x).
getVector();
61 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
64 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective value): "
65 "Primal vector x must be of length 2.");
70 Real val = x1*x1 + x2*x2;
78 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
79 ROL::Ptr<vector> gp = getVector<XDual>(g);
82 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective gradient): "
83 " Primal vector x must be of length 2.");
86 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective gradient): "
87 "Gradient vector g must be of length 2.");
101 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
102 ROL::Ptr<const vector> vp = getVector<XPrim>(v);
103 ROL::Ptr<vector> hvp = getVector<XDual>(hv);
106 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective hessVec): "
107 "Primal vector x must be of length 2.");
110 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective hessVec): "
111 "Input vector v must be of length 2.");
114 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective hessVec): "
115 "Output vector hv must be of length 2.");
131 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real>,
class CPrim=StdVector<Real>,
class CDual=StdVector<Real> >
137 typedef typename vector::size_type
uint;
140 template<
class VectorType>
143 return dynamic_cast<const VectorType&
>(x).
getVector();
146 template<
class VectorType>
149 return dynamic_cast<VectorType&
>(x).
getVector();
158 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
159 ROL::Ptr<vector> cp = getVector<CPrim>(c);
162 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint value): "
163 "Primal vector x must be of length 2.");
166 ROL_TEST_FOR_EXCEPTION( (m != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint value): "
167 "Constraint vector c must be of length 1.");
174 (*cp)[0] = (x1-two)*(x1-two) + x2*x2 - one;
180 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
181 ROL::Ptr<const vector> vp = getVector<XPrim>(v);
182 ROL::Ptr<vector> jvp = getVector<CPrim>(jv);
185 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyJacobian): "
186 "Primal vector x must be of length 2.");
189 ROL_TEST_FOR_EXCEPTION( (d != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyJacobian): "
190 "Input vector v must be of length 2.");
192 ROL_TEST_FOR_EXCEPTION( (d != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyJacobian): "
193 "Output vector jv must be of length 1.");
203 (*jvp)[0] = two*(x1-two)*v1 + two*x2*v2;
209 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
210 ROL::Ptr<const vector> vp = getVector<CDual>(v);
211 ROL::Ptr<vector> ajvp = getVector<XDual>(ajv);
214 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointJacobian): "
215 "Primal vector x must be of length 2.");
218 ROL_TEST_FOR_EXCEPTION( (d != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointJacobian): "
219 "Input vector v must be of length 1.");
222 ROL_TEST_FOR_EXCEPTION( (d != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointJacobian): "
223 "Output vector ajv must be of length 2.");
232 (*ajvp)[0] = two*(x1-two)*v1;
233 (*ajvp)[1] = two*x2*v1;
246 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
247 ROL::Ptr<const vector> up = getVector<CDual>(u);
248 ROL::Ptr<const vector> vp = getVector<XPrim>(v);
249 ROL::Ptr<vector> ahuvp = getVector<XDual>(ahuv);
252 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): "
253 "Primal vector x must be of length 2.");
256 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): "
257 "Direction vector v must be of length 2.");
260 ROL_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): "
261 "Output vector ahuv must be of length 2.");
263 ROL_TEST_FOR_EXCEPTION( (d != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): "
264 "Dual constraint vector u must be of length 1.");
273 (*ahuvp)[0] = two*u1*v1;
274 (*ahuvp)[1] = two*u1*v2;
281 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real>,
class CPrim=StdVector<Real>,
class CDual=StdVector<Real> >
284 typedef typename vector::size_type
uint;
290 return ROL::makePtr<Objective_ParaboloidCircle<Real,XPrim,XDual>>();
296 ROL::Ptr<vector> x0p = makePtr<vector>(n,0.0);
297 (*x0p)[0] =
static_cast<Real
>(rand())/
static_cast<Real
>(RAND_MAX);
298 (*x0p)[1] =
static_cast<Real
>(rand())/
static_cast<Real
>(RAND_MAX);
299 return makePtr<XPrim>(x0p);
305 Real
zero(0), one(1);
306 ROL::Ptr<vector> solp = makePtr<vector>(n,0.0);
309 return makePtr<XPrim>(solp);
314 return ROL::makePtr<Constraint_ParaboloidCircle<Real,XPrim,XDual,CPrim,CDual>>();
318 ROL::Ptr<vector> lp = makePtr<vector>(1,0.0);
319 return makePtr<CDual>(lp);
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Contains definitions of test objective functions.
Defines the general constraint operator interface.
virtual void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the derivative of the adjoint of the constraint Jacobian at to vector in direction ,...
Provides the interface to evaluate objective functions.
Defines the linear algebra or vector space interface.
constraint c(x,y) = (x-2)^2 + y^2 - 1.
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
Constraint_ParaboloidCircle()
ROL::Ptr< vector > getVector(V &x)
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
ROL::Ptr< const vector > getVector(const V &x)
void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the adjoint of the the constraint Jacobian at , , to vector .
std::vector< Real > vector
void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the derivative of the adjoint of the constraint Jacobian at to vector in direction ,...
Objective function: f(x,y) = x^2 + y^2.
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Objective_ParaboloidCircle()
std::vector< Real > vector
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
ROL::Ptr< vector > getVector(V &x)
Real value(const Vector< Real > &x, Real &tol)
Compute value.
ROL::Ptr< const vector > getVector(const V &x)
Ptr< Vector< Real > > getSolution(const int i=0) const
Ptr< Constraint< Real > > getEqualityConstraint(void) const
getParaboloidCircle(void)
Ptr< Objective< Real > > getObjective(void) const
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Ptr< Vector< Real > > getInitialGuess(void) const
std::vector< Real > vector