// @HEADER // ***************************************************************************** // Rapid Optimization Library (ROL) Package // // Copyright 2014 NTESS and the ROL contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER /*! \file obj.hpp \brief Provides the interface for local (cell-based) objective function computations. */ #ifndef BINARY_CON_STEFAN_BOLTZMANN_HPP #define BINARY_CON_STEFAN_BOLTZMANN_HPP #include "ROL_StdConstraint.hpp" #include "ROL_Bounds.hpp" template class BudgetConstraint : public ROL::StdConstraint { private: Real budget_; public: BudgetConstraint(ROL::ParameterList &pl) { budget_ = pl.sublist("Problem").get("Control Budget",8.0); } void value( std::vector &c, const std::vector &x, Real &tol ) override { c[0] = -budget_; for (const auto xv : x) c[0] += xv; } void applyJacobian( std::vector &jv, const std::vector &v, const std::vector &x, Real &tol ) override { jv[0] = static_cast(0); for (const auto vv : v) jv[0] += vv; } void applyAdjointJacobian( std::vector &ajv, const std::vector &v, const std::vector &x, Real &tol ) override { ajv.assign(ajv.size(),v[0]); } void applyAdjointHessian( std::vector &ahuv, const std::vector &u, const std::vector &v, const std::vector &x, Real &tol ) { ahuv.assign(ahuv.size(),static_cast(0)); } ROL::Ptr> createMultiplier(void) const { return ROL::makePtr>(1,static_cast(0)); } ROL::Ptr> createBounds(void) const { ROL::Ptr> l = createMultiplier(); l->setScalar(-budget_); ROL::Ptr> u = createMultiplier(); u->zero(); return ROL::makePtr>(l,u); } }; // BudgetConstraint #endif