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 arg = x1*x2*x3*x4*x5;
107 Real val = -0.5*pow(pow(x1,3)+pow(x2,3)+1.0,2);
108 if (std::abs(arg) < 1e5) val += exp(x1*x2*x3*x4*x5);
109 else if (arg > 1e5) val += 1e10;
118 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
119 ROL::Ptr<vector> gp = getVector<XDual>(g);
122 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, objective gradient): "
123 " Primal vector x must be of length 5.");
126 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, objective gradient): "
127 "Gradient vector g must be of length 5.");
135 Real expxi = exp(x1*x2*x3*x4*x5);
137 (*gp)[0] = x2*x3*x4*x5 * expxi - 3*pow(x1,2) * (pow(x1,3) + pow(x2,3) + 1);
138 (*gp)[1] = x1*x3*x4*x5 * expxi - 3*pow(x2,2) * (pow(x1,3) + pow(x2,3) + 1);
139 (*gp)[2] = x1*x2*x4*x5 * expxi;
140 (*gp)[3] = x1*x2*x3*x5 * expxi;
141 (*gp)[4] = x1*x2*x3*x4 * expxi;
147 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
148 ROL::Ptr<const vector> vp = getVector<XPrim>(v);
149 ROL::Ptr<vector> hvp = getVector<XDual>(hv);
152 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, objective hessVec): "
153 "Primal vector x must be of length 5.");
156 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, objective hessVec): "
157 "Input vector v must be of length 5.");
160 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, objective hessVec): "
161 "Output vector hv must be of length 5.");
175 Real expxi = exp(x1*x2*x3*x4*x5);
177 (*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 +
178 ( 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 +
179 ( x2*x4*x5*expxi+pow(x2,2)*x3*pow(x4,2)*pow(x5,2)*x1*expxi ) * v3 +
180 ( x2*x3*x5*expxi+pow(x2,2)*pow(x3,2)*x4*pow(x5,2)*x1*expxi ) * v4 +
181 ( x2*x3*x4*expxi+pow(x2,2)*pow(x3,2)*pow(x4,2)*x5*x1*expxi ) * v5;
183 (*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 +
184 ( 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 +
185 ( x1*x4*x5*expxi+pow(x1,2)*x3*pow(x4,2)*pow(x5,2)*x2*expxi ) * v3 +
186 ( x1*x3*x5*expxi+pow(x1,2)*pow(x3,2)*x4*pow(x5,2)*x2*expxi ) * v4 +
187 ( x1*x3*x4*expxi+pow(x1,2)*pow(x3,2)*pow(x4,2)*x5*x2*expxi ) * v5;
189 (*hvp)[2] = ( x2*x4*x5*expxi+pow(x2,2)*x3*pow(x4,2)*pow(x5,2)*x1*expxi ) * v1 +
190 ( x1*x4*x5*expxi+pow(x1,2)*x3*pow(x4,2)*pow(x5,2)*x2*expxi ) * v2 +
191 ( pow(x1,2)*pow(x2,2)*pow(x4,2)*pow(x5,2)*expxi ) * v3 +
192 ( x1*x2*x5*expxi+pow(x1,2)*pow(x2,2)*x4*pow(x5,2)*x3*expxi ) * v4 +
193 ( x1*x2*x4*expxi+pow(x1,2)*pow(x2,2)*pow(x4,2)*x5*x3*expxi ) * v5;
195 (*hvp)[3] = ( x2*x3*x5*expxi+pow(x2,2)*pow(x3,2)*x4*pow(x5,2)*x1*expxi ) * v1 +
196 ( x1*x3*x5*expxi+pow(x1,2)*pow(x3,2)*x4*pow(x5,2)*x2*expxi ) * v2 +
197 ( x1*x2*x5*expxi+pow(x1,2)*pow(x2,2)*x4*pow(x5,2)*x3*expxi ) * v3 +
198 ( pow(x1,2)*pow(x2,2)*pow(x3,2)*pow(x5,2)*expxi ) * v4 +
199 ( x1*x2*x3*expxi+pow(x1,2)*pow(x2,2)*pow(x3,2)*x5*x4*expxi ) * v5;
201 (*hvp)[4] = ( x2*x3*x4*expxi+pow(x2,2)*pow(x3,2)*pow(x4,2)*x5*x1*expxi ) * v1 +
202 ( x1*x3*x4*expxi+pow(x1,2)*pow(x3,2)*pow(x4,2)*x5*x2*expxi ) * v2 +
203 ( x1*x2*x4*expxi+pow(x1,2)*pow(x2,2)*pow(x4,2)*x5*x3*expxi ) * v3 +
204 ( x1*x2*x3*expxi+pow(x1,2)*pow(x2,2)*pow(x3,2)*x5*x4*expxi ) * v4 +
205 ( pow(x1,2)*pow(x2,2)*pow(x3,2)*pow(x4,2)*expxi ) * v5;
216 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real>,
class CPrim=StdVector<Real>,
class CDual=StdVector<Real> >
225 template<
class VectorType>
228 return dynamic_cast<const VectorType&
>(x).
getVector();
231 template<
class VectorType>
234 return dynamic_cast<VectorType&
>(x).
getVector();
243 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
244 ROL::Ptr<vector> cp = getVector<CPrim>(c);
247 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint value): "
248 "Primal vector x must be of length 5.");
251 ROL_TEST_FOR_EXCEPTION( (m != 3), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint value): "
252 "Constraint vector c must be of length 3.");
260 (*cp)[0] = x1*x1+x2*x2+x3*x3+x4*x4+x5*x5 - 10.0;
261 (*cp)[1] = x2*x3 - 5.0*x4*x5;
262 (*cp)[2] = x1*x1*x1 + x2*x2*x2 + 1.0;
268 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
269 ROL::Ptr<const vector> vp = getVector<XPrim>(v);
270 ROL::Ptr<vector> jvp = getVector<CPrim>(jv);
273 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyJacobian): "
274 "Primal vector x must be of length 5.");
277 ROL_TEST_FOR_EXCEPTION( (d != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyJacobian): "
278 "Input vector v must be of length 5.");
280 ROL_TEST_FOR_EXCEPTION( (d != 3), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyJacobian): "
281 "Output vector jv must be of length 3.");
295 (*jvp)[0] = 2.0*(x1*v1+x2*v2+x3*v3+x4*v4+x5*v5);
296 (*jvp)[1] = x3*v2+x2*v3-5.0*x5*v4-5.0*x4*v5;
297 (*jvp)[2] = 3.0*x1*x1*v1+3.0*x2*x2*v2;
304 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
305 ROL::Ptr<const vector> vp = getVector<CDual>(v);
306 ROL::Ptr<vector> ajvp = getVector<XDual>(ajv);
309 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyAdjointJacobian): "
310 "Primal vector x must be of length 5.");
313 ROL_TEST_FOR_EXCEPTION( (d != 3), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyAdjointJacobian): "
314 "Input vector v must be of length 3.");
317 ROL_TEST_FOR_EXCEPTION( (d != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyAdjointJacobian): "
318 "Output vector ajv must be of length 5.");
330 (*ajvp)[0] = 2.0*x1*v1+3.0*x1*x1*v3;
331 (*ajvp)[1] = 2.0*x2*v1+x3*v2+3.0*x2*x2*v3;
332 (*ajvp)[2] = 2.0*x3*v1+x2*v2;
333 (*ajvp)[3] = 2.0*x4*v1-5.0*x5*v2;
334 (*ajvp)[4] = 2.0*x5*v1-5.0*x4*v2;
340 ROL::Ptr<const vector> xp = getVector<XPrim>(x);
341 ROL::Ptr<const vector> up = getVector<CDual>(u);
342 ROL::Ptr<const vector> vp = getVector<XPrim>(v);
343 ROL::Ptr<vector> ahuvp = getVector<XDual>(ahuv);
346 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyAdjointHessian): "
347 "Primal vector x must be of length 5.");
350 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyAdjointHessian): "
351 "Direction vector v must be of length 5.");
354 ROL_TEST_FOR_EXCEPTION( (n != 5), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyAdjointHessian): "
355 "Output vector ahuv must be of length 5.");
357 ROL_TEST_FOR_EXCEPTION( (d != 3), std::invalid_argument,
">>> ERROR (ROL_SimpleEqConstrained, constraint applyAdjointHessian): "
358 "Dual constraint vector u must be of length 3.");
373 (*ahuvp)[0] = 2.0*u1*v1 + 6.0*u3*x1*v1;
374 (*ahuvp)[1] = 2.0*u1*v2 + u2*v3 + 6.0*u3*x2*v2;
375 (*ahuvp)[2] = 2.0*u1*v3 + u2*v2;
376 (*ahuvp)[3] = 2.0*u1*v4 - 5.0*u2*v5;
377 (*ahuvp)[4] = 2.0*u1*v5 - 5.0*u2*v4;
442 template<
class Real,
class XPrim=StdVector<Real>,
class XDual=StdVector<Real>,
class CPrim=StdVector<Real>,
class CDual=StdVector<Real> >
451 return ROL::makePtr<Objective_SimpleEqConstrained<Real,XPrim,XDual>>();
457 Ptr<vector> x0p = makePtr<vector>(n,0);
463 return makePtr<XPrim>(x0p);
469 Ptr<vector> solp = makePtr<vector>(n,0);
470 (*solp)[0] = -1.717143570394391e+00;
471 (*solp)[1] = 1.595709690183565e+00;
472 (*solp)[2] = 1.827245752927178e+00;
473 (*solp)[3] = -7.636430781841294e-01;
474 (*solp)[4] = -7.636430781841294e-01;
475 return makePtr<XPrim>(solp);
480 return ROL::makePtr<EqualityConstraint_SimpleEqConstrained<Real,XPrim,XDual,CPrim,CDual>>();
484 Ptr<vector> lp = makePtr<vector>(3,0);
485 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