53 #ifndef ROL_PARABOLOIDCIRCLE_HPP 54 #define ROL_PARABOLOIDCIRCLE_HPP 59 #include "Teuchos_SerialDenseVector.hpp" 60 #include "Teuchos_SerialDenseSolver.hpp" 68 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real> >
74 typedef typename vector::size_type
uint;
79 template<
class VectorType>
81 using Teuchos::dyn_cast;
82 return dyn_cast<
const VectorType>(x).
getVector();
85 template<
class VectorType>
87 using Teuchos::dyn_cast;
88 return dyn_cast<VectorType>(x).
getVector();
97 RCP<const vector> xp = getVector<XPrim>(x);
100 TEUCHOS_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective value): " 101 "Primal vector x must be of length 2.");
106 Real val = x1*x1 + x2*x2;
114 RCP<const vector> xp = getVector<XPrim>(x);
115 RCP<vector> gp = getVector<XDual>(g);
118 TEUCHOS_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective gradient): " 119 " Primal vector x must be of length 2.");
122 TEUCHOS_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective gradient): " 123 "Gradient vector g must be of length 2.");
137 RCP<const vector> xp = getVector<XPrim>(x);
138 RCP<const vector> vp = getVector<XPrim>(v);
139 RCP<vector> hvp = getVector<XDual>(hv);
142 TEUCHOS_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective hessVec): " 143 "Primal vector x must be of length 2.");
146 TEUCHOS_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective hessVec): " 147 "Input vector v must be of length 2.");
150 TEUCHOS_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, objective hessVec): " 151 "Output vector hv must be of length 2.");
167 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real>,
class CPrim=StdVector<Real>,
class CDual=StdVector<Real> >
173 typedef typename vector::size_type
uint;
176 template<
class VectorType>
178 using Teuchos::dyn_cast;
179 return dyn_cast<
const VectorType>(x).
getVector();
182 template<
class VectorType>
184 using Teuchos::dyn_cast;
185 return dyn_cast<VectorType>(x).
getVector();
194 RCP<const vector> xp = getVector<XPrim>(x);
195 RCP<vector> cp = getVector<CPrim>(c);
198 TEUCHOS_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint value): " 199 "Primal vector x must be of length 2.");
202 TEUCHOS_TEST_FOR_EXCEPTION( (m != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint value): " 203 "Constraint vector c must be of length 1.");
210 (*cp)[0] = (x1-two)*(x1-two) + x2*x2 - one;
216 RCP<const vector> xp = getVector<XPrim>(x);
217 RCP<const vector> vp = getVector<XPrim>(v);
218 RCP<vector> jvp = getVector<CPrim>(jv);
221 TEUCHOS_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyJacobian): " 222 "Primal vector x must be of length 2.");
225 TEUCHOS_TEST_FOR_EXCEPTION( (d != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyJacobian): " 226 "Input vector v must be of length 2.");
228 TEUCHOS_TEST_FOR_EXCEPTION( (d != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyJacobian): " 229 "Output vector jv must be of length 1.");
239 (*jvp)[0] = two*(x1-two)*v1 + two*x2*v2;
245 RCP<const vector> xp = getVector<XPrim>(x);
246 RCP<const vector> vp = getVector<CDual>(v);
247 RCP<vector> ajvp = getVector<XDual>(ajv);
250 TEUCHOS_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointJacobian): " 251 "Primal vector x must be of length 2.");
254 TEUCHOS_TEST_FOR_EXCEPTION( (d != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointJacobian): " 255 "Input vector v must be of length 1.");
258 TEUCHOS_TEST_FOR_EXCEPTION( (d != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointJacobian): " 259 "Output vector ajv must be of length 2.");
268 (*ajvp)[0] = two*(x1-two)*v1;
269 (*ajvp)[1] = two*x2*v1;
282 RCP<const vector> xp = getVector<XPrim>(x);
283 RCP<const vector> up = getVector<CDual>(u);
284 RCP<const vector> vp = getVector<XPrim>(v);
285 RCP<vector> ahuvp = getVector<XDual>(ahuv);
288 TEUCHOS_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): " 289 "Primal vector x must be of length 2.");
292 TEUCHOS_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): " 293 "Direction vector v must be of length 2.");
296 TEUCHOS_TEST_FOR_EXCEPTION( (n != 2), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): " 297 "Output vector ahuv must be of length 2.");
299 TEUCHOS_TEST_FOR_EXCEPTION( (d != 1), std::invalid_argument,
">>> ERROR (ROL_ParaboloidCircle, constraint applyAdjointHessian): " 300 "Dual constraint vector u must be of length 1.");
309 (*ahuvp)[0] = two*u1*v1;
310 (*ahuvp)[1] = two*u1*v2;
317 template<
class Real,
class XPrim,
class XDual,
class CPrim,
class CDual>
323 typedef std::vector<Real> vector;
325 typedef typename vector::size_type uint;
327 using Teuchos::RCP;
using Teuchos::rcp;
328 using Teuchos::dyn_cast;
331 RCP<vector> x0p = dyn_cast<XPrim>(x0).getVector();
332 RCP<vector> solp = dyn_cast<XPrim>(sol).getVector();
348 Real zero(0), one(1);
349 (*x0p)[0] =
static_cast<Real
>(rand())/static_cast<Real>(RAND_MAX);
350 (*x0p)[1] =
static_cast<Real
>(rand())/static_cast<Real>(RAND_MAX);
Provides the interface to evaluate objective functions.
Equality constraint c(x,y) = (x-2)^2 + y^2 - 1.
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
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 ...
Teuchos::RCP< vector > getVector(V &x)
Teuchos::RCP< const vector > getVector(const V &x)
Defines the linear algebra or vector space interface.
void getParaboloidCircle(Teuchos::RCP< Objective< Real > > &obj, Teuchos::RCP< EqualityConstraint< Real > > &constr, Vector< Real > &x0, Vector< Real > &sol)
Defines the equality constraint operator interface.
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
Objective_ParaboloidCircle()
EqualityConstraint_ParaboloidCircle()
Real value(const Vector< Real > &x, Real &tol)
Compute value.
std::vector< Real > vector
Teuchos::RCP< const vector > getVector(const V &x)
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.
Teuchos::RCP< vector > getVector(V &x)
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
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