// @HEADER // ***************************************************************************** // Rapid Optimization Library (ROL) Package // // Copyright 2014 NTESS and the ROL contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER /** \file \brief Contains definitions for Rosenbrock's function. \author Created by D. Ridzal and D. Kouri. */ // Whether or not to use the exact Hessian-times-a-vector #ifndef USE_HESSVEC #define USE_HESSVEC 1 #endif #ifndef ROL_ROSENBROCK_HPP #define ROL_ROSENBROCK_HPP #include "ROL_StdVector.hpp" #include "ROL_TestProblem.hpp" namespace ROL { namespace ZOO { /** \brief Rosenbrock's function. */ template< class Real, class XPrim=StdVector, class XDual=StdVector > class Objective_Rosenbrock : public Objective { typedef std::vector vector; typedef Vector V; typedef typename vector::size_type uint; private: Real alpha_; Real const1_; Real const2_; template ROL::Ptr getVector( const V& x ) { return dynamic_cast((x)).getVector(); } template ROL::Ptr getVector( V& x ) { return dynamic_cast(x).getVector(); } public: Objective_Rosenbrock(Real alpha = 100.0) : alpha_(alpha), const1_(100.0), const2_(20.0) {} Real value( const Vector &x, Real &tol ) { ROL::Ptr xp = getVector(x); uint n = xp->size(); Real val = 0; for( uint i=0; iconst1_*error; return val; } void gradient( Vector &g, const Vector &x, Real &tol ) { ROL::Ptr xp = getVector(x); ROL::Ptr gp = getVector(g); uint n = xp->size(); for( uint i=0; iconst2_*error0/std::sqrt(n); //(*gp)[2*i+1] += this->const2_*error1/std::sqrt(n); } } #if USE_HESSVEC void hessVec( Vector &hv, const Vector &v, const Vector &x, Real &tol ) { ROL::Ptr xp = getVector(x); ROL::Ptr vp = getVector(v); ROL::Ptr hvp = getVector(hv); uint n = xp->size(); for( uint i=0; i &hv, const Vector &v, const Vector &x, Real &tol ) { ROL::Ptr xp = getVector(x); ROL::Ptr vp = getVector(v); ROL::Ptr hvp = getVector(hv); uint n = xp->size(); for( uint i=0; i class getRosenbrock : public TestProblem { public: getRosenbrock(void) {} Ptr> getObjective(void) const { // Instantiate Objective Function return ROL::makePtr>(); } Ptr> getInitialGuess(void) const { // Problem dimension int n = 100; // Get Initial Guess ROL::Ptr > x0p = ROL::makePtr>(n,0.0); for ( int i = 0; i < n/2; i++ ) { (*x0p)[2*i] = -1.2; (*x0p)[2*i+1] = 1.0; } return ROL::makePtr>(x0p); } Ptr> getSolution(const int i = 0) const { // Problem dimension int n = 100; // Get Solution ROL::Ptr > xp = ROL::makePtr>(n,0.0); for ( int i = 0; i < n; i++ ) { (*xp)[i] = 1.0; } return ROL::makePtr>(xp); } }; }// End ZOO Namespace }// End ROL Namespace #endif