51 #ifndef ROL_SIMPLEEQCONSTRAINED_HPP
52 #define ROL_SIMPLEEQCONSTRAINED_HPP
56 #include "Teuchos_SerialDenseVector.hpp"
57 #include "Teuchos_SerialDenseSolver.hpp"
65 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real> >
76 template<
class VectorType>
79 return dynamic_cast<const VectorType&
>(x).
getVector();
82 template<
class VectorType>
85 return dynamic_cast<VectorType&
>(x).
getVector();
94 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
97 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, objective value): "
98 "Primal vector x must be of length 5.");
106 Real val = exp(x1*x2*x3*x4*x5) - 0.5 * pow( (pow(x1,3)+pow(x2,3)+1.0), 2);
114 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
115 ROL::Ptr<vector> gp = getVector<XDual>(g);
118 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, objective gradient): "
119 " Primal vector x must be of length 5.");
122 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, objective gradient): "
123 "Gradient vector g must be of length 5.");
131 Real expxi = exp(x1*x2*x3*x4*x5);
133 (*gp)[0] = x2*x3*x4*x5 * expxi - 3*pow(x1,2) * (pow(x1,3) + pow(x2,3) + 1);
134 (*gp)[1] = x1*x3*x4*x5 * expxi - 3*pow(x2,2) * (pow(x1,3) + pow(x2,3) + 1);
135 (*gp)[2] = x1*x2*x4*x5 * expxi;
136 (*gp)[3] = x1*x2*x3*x5 * expxi;
137 (*gp)[4] = x1*x2*x3*x4 * expxi;
143 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
144 ROL::Ptr<const vector> vp = getVector<XPrim>(v);
145 ROL::Ptr<vector> hvp = getVector<XDual>(hv);
148 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, objective hessVec): "
149 "Primal vector x must be of length 5.");
152 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, objective hessVec): "
153 "Input vector v must be of length 5.");
156 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, objective hessVec): "
157 "Output vector hv must be of length 5.");
171 Real expxi = exp(x1*x2*x3*x4*x5);
173 (*hvp)[0] = ( pow(x2,2)*pow(x3,2)*pow(x4,2)*pow(x5,2)*expxi-9.0*pow(x1,4)-6.0*(pow(x1,3)+pow(x2,3)+1.0)*x1 ) * v1 +
174 ( x3*x4*x5*expxi+x2*pow(x3,2)*pow(x4,2)*pow(x5,2)*x1*expxi-9.0*pow(x2,2)*pow(x1,2) ) * v2 +
175 ( x2*x4*x5*expxi+pow(x2,2)*x3*pow(x4,2)*pow(x5,2)*x1*expxi ) * v3 +
176 ( x2*x3*x5*expxi+pow(x2,2)*pow(x3,2)*x4*pow(x5,2)*x1*expxi ) * v4 +
177 ( x2*x3*x4*expxi+pow(x2,2)*pow(x3,2)*pow(x4,2)*x5*x1*expxi ) * v5;
179 (*hvp)[1] = ( x3*x4*x5*expxi+x2*pow(x3,2)*pow(x4,2)*pow(x5,2)*x1*expxi-9.0*pow(x2,2)*pow(x1,2) ) * v1 +
180 ( pow(x1,2)*pow(x3,2)*pow(x4,2)*pow(x5,2)*expxi-9.0*pow(x2,4)-6.0*(pow(x1,3)+pow(x2,3)+1.0)*x2 ) * v2 +
181 ( x1*x4*x5*expxi+pow(x1,2)*x3*pow(x4,2)*pow(x5,2)*x2*expxi ) * v3 +
182 ( x1*x3*x5*expxi+pow(x1,2)*pow(x3,2)*x4*pow(x5,2)*x2*expxi ) * v4 +
183 ( x1*x3*x4*expxi+pow(x1,2)*pow(x3,2)*pow(x4,2)*x5*x2*expxi ) * v5;
185 (*hvp)[2] = ( x2*x4*x5*expxi+pow(x2,2)*x3*pow(x4,2)*pow(x5,2)*x1*expxi ) * v1 +
186 ( x1*x4*x5*expxi+pow(x1,2)*x3*pow(x4,2)*pow(x5,2)*x2*expxi ) * v2 +
187 ( pow(x1,2)*pow(x2,2)*pow(x4,2)*pow(x5,2)*expxi ) * v3 +
188 ( x1*x2*x5*expxi+pow(x1,2)*pow(x2,2)*x4*pow(x5,2)*x3*expxi ) * v4 +
189 ( x1*x2*x4*expxi+pow(x1,2)*pow(x2,2)*pow(x4,2)*x5*x3*expxi ) * v5;
191 (*hvp)[3] = ( x2*x3*x5*expxi+pow(x2,2)*pow(x3,2)*x4*pow(x5,2)*x1*expxi ) * v1 +
192 ( x1*x3*x5*expxi+pow(x1,2)*pow(x3,2)*x4*pow(x5,2)*x2*expxi ) * v2 +
193 ( x1*x2*x5*expxi+pow(x1,2)*pow(x2,2)*x4*pow(x5,2)*x3*expxi ) * v3 +
194 ( pow(x1,2)*pow(x2,2)*pow(x3,2)*pow(x5,2)*expxi ) * v4 +
195 ( x1*x2*x3*expxi+pow(x1,2)*pow(x2,2)*pow(x3,2)*x5*x4*expxi ) * v5;
197 (*hvp)[4] = ( x2*x3*x4*expxi+pow(x2,2)*pow(x3,2)*pow(x4,2)*x5*x1*expxi ) * v1 +
198 ( x1*x3*x4*expxi+pow(x1,2)*pow(x3,2)*pow(x4,2)*x5*x2*expxi ) * v2 +
199 ( x1*x2*x4*expxi+pow(x1,2)*pow(x2,2)*pow(x4,2)*x5*x3*expxi ) * v3 +
200 ( x1*x2*x3*expxi+pow(x1,2)*pow(x2,2)*pow(x3,2)*x5*x4*expxi ) * v4 +
201 ( pow(x1,2)*pow(x2,2)*pow(x3,2)*pow(x4,2)*expxi ) * v5;
212 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real>,
class CPrim=StdVector<Real>,
class CDual=StdVector<Real> >
221 template<
class VectorType>
224 return dynamic_cast<const VectorType&
>(x).
getVector();
227 template<
class VectorType>
230 return dynamic_cast<VectorType&
>(x).
getVector();
239 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
240 ROL::Ptr<vector> cp = getVector<CPrim>(c);
243 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint value): "
244 "Primal vector x must be of length 5.");
247 ROL_TEST_FOR_EXCEPTION( (m != 3), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint value): "
248 "Constraint vector c must be of length 3.");
256 (*cp)[0] = x1*x1+x2*x2+x3*x3+x4*x4+x5*x5 - 10.0;
257 (*cp)[1] = x2*x3 - 5.0*x4*x5;
258 (*cp)[2] = x1*x1*x1 + x2*x2*x2 + 1.0;
264 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
265 ROL::Ptr<const vector> vp = getVector<XPrim>(v);
266 ROL::Ptr<vector> jvp = getVector<CPrim>(jv);
269 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyJacobian): "
270 "Primal vector x must be of length 5.");
273 ROL_TEST_FOR_EXCEPTION( (d != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyJacobian): "
274 "Input vector v must be of length 5.");
276 ROL_TEST_FOR_EXCEPTION( (d != 3), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyJacobian): "
277 "Output vector jv must be of length 3.");
291 (*jvp)[0] = 2.0*(x1*v1+x2*v2+x3*v3+x4*v4+x5*v5);
292 (*jvp)[1] = x3*v2+x2*v3-5.0*x5*v4-5.0*x4*v5;
293 (*jvp)[2] = 3.0*x1*x1*v1+3.0*x2*x2*v2;
300 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
301 ROL::Ptr<const vector> vp = getVector<CDual>(v);
302 ROL::Ptr<vector> ajvp = getVector<XDual>(ajv);
305 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyAdjointJacobian): "
306 "Primal vector x must be of length 5.");
309 ROL_TEST_FOR_EXCEPTION( (d != 3), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyAdjointJacobian): "
310 "Input vector v must be of length 3.");
313 ROL_TEST_FOR_EXCEPTION( (d != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyAdjointJacobian): "
314 "Output vector ajv must be of length 5.");
326 (*ajvp)[0] = 2.0*x1*v1+3.0*x1*x1*v3;
327 (*ajvp)[1] = 2.0*x2*v1+x3*v2+3.0*x2*x2*v3;
328 (*ajvp)[2] = 2.0*x3*v1+x2*v2;
329 (*ajvp)[3] = 2.0*x4*v1-5.0*x5*v2;
330 (*ajvp)[4] = 2.0*x5*v1-5.0*x4*v2;
336 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
337 ROL::Ptr<const vector> up = getVector<CDual>(u);
338 ROL::Ptr<const vector> vp = getVector<XPrim>(v);
339 ROL::Ptr<vector> ahuvp = getVector<XDual>(ahuv);
342 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyAdjointHessian): "
343 "Primal vector x must be of length 5.");
346 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyAdjointHessian): "
347 "Direction vector v must be of length 5.");
350 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyAdjointHessian): "
351 "Output vector ahuv must be of length 5.");
353 ROL_TEST_FOR_EXCEPTION( (d != 3), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyAdjointHessian): "
354 "Dual constraint vector u must be of length 3.");
369 (*ahuvp)[0] = 2.0*u1*v1 + 6.0*u3*x1*v1;
370 (*ahuvp)[1] = 2.0*u1*v2 + u2*v3 + 6.0*u3*x2*v2;
371 (*ahuvp)[2] = 2.0*u1*v3 + u2*v2;
372 (*ahuvp)[3] = 2.0*u1*v4 - 5.0*u2*v5;
373 (*ahuvp)[4] = 2.0*u1*v5 - 5.0*u2*v4;
438 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real>,
class CPrim=StdVector<Real>,
class CDual=StdVector<Real> >
447 return ROL::makePtr<Objective_SimpleEqConstrained<Real,XPrim,XDual>>();
453 Ptr<vector> x0p = makePtr<vector>(n,0);
459 return makePtr<XPrim>(x0p);
465 Ptr<vector> solp = makePtr<vector>(n,0);
466 (*solp)[0] = -1.717143570394391e+00;
467 (*solp)[1] = 1.595709690183565e+00;
468 (*solp)[2] = 1.827245752927178e+00;
469 (*solp)[3] = -7.636430781841294e-01;
470 (*solp)[4] = -7.636430781841294e-01;
471 return makePtr<XPrim>(solp);
476 return ROL::makePtr<EqualityConstraint_SimpleEqConstrained<Real,XPrim,XDual,CPrim,CDual>>();
480 Ptr<vector> lp = makePtr<vector>(3,0);
481 return makePtr<CDual>(lp);
Provides the interface to evaluate objective functions.
typename PV< Real >::size_type size_type
EqualityConstraint_SimpleEqConstrained()
Equality constraints c_i(x) = 0, where: c1(x) = x1^2+x2^2+x3^2+x4^2+x5^2 - 10 c2(x) = x2*x3-5*x4*x5 c...
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
Ptr< Constraint< Real > > getEqualityConstraint(void) const
ROL::Ptr< const vector > getVector(const V &x)
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Defines the linear algebra or vector space interface.
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 hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
ROL::Ptr< vector > getVector(V &x)
ROL::Ptr< const vector > getVector(const V &x)
Contains definitions of test objective functions.
Ptr< Objective< Real > > getObjective(void) const
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
std::vector< Real > vector
ROL::Ptr< vector > getVector(V &x)
Ptr< Vector< Real > > getSolution(const int i=0) const
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 ...
getSimpleEqConstrained(void)
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Objective_SimpleEqConstrained()
Ptr< Vector< Real > > getInitialGuess(void) const
Defines the general constraint operator interface.
Objective function: f(x) = exp(x1*x2*x3*x4*x5) + 0.5*(x1^3+x2^3+1)^2.
std::vector< Real > vector