1 // @HEADER 2 // ************************************************************************ 3 // 4 // Rapid Optimization Library (ROL) Package 5 // Copyright (2014) Sandia Corporation 6 // 7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 8 // license for use of this work by or on behalf of the U.S. Government. 9 // 10 // Redistribution and use in source and binary forms, with or without 11 // modification, are permitted provided that the following conditions are 12 // met: 13 // 14 // 1. Redistributions of source code must retain the above copyright 15 // notice, this list of conditions and the following disclaimer. 16 // 17 // 2. Redistributions in binary form must reproduce the above copyright 18 // notice, this list of conditions and the following disclaimer in the 19 // documentation and/or other materials provided with the distribution. 20 // 21 // 3. Neither the name of the Corporation nor the names of the 22 // contributors may be used to endorse or promote products derived from 23 // this software without specific prior written permission. 24 // 25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 // 37 // Questions? Contact lead developers: 38 // Drew Kouri (dpkouri@sandia.gov) and 39 // Denis Ridzal (dridzal@sandia.gov) 40 // 41 // ************************************************************************ 42 // @HEADER 43 44 #ifndef HS_PROBLEM_024_HPP 45 #define HS_PROBLEM_024_HPP 46 47 #include "ROL_NonlinearProgram.hpp" 48 49 50 namespace HS { 51 52 namespace HS_024 { 53 template<class Real> 54 class Obj { 55 public: 56 template<class ScalarT> value(const std::vector<ScalarT> & x,Real & tol)57 ScalarT value( const std::vector<ScalarT> &x, Real &tol ) { 58 ScalarT a = x[0]-3; 59 return (a*a-9)*x[1]*x[1]*x[1]/(27*std::sqrt(3)); 60 } 61 }; 62 63 template<class Real> 64 class InCon { 65 public: 66 template<class ScalarT> value(std::vector<ScalarT> & c,const std::vector<ScalarT> & x,Real & tol)67 void value( std::vector<ScalarT> &c, 68 const std::vector<ScalarT> &x, 69 Real &tol ) { 70 Real q = std::sqrt(3); 71 c[0] = x[0]/q - x[1]; 72 c[1] = x[0] + q*x[1]; 73 c[2] = -x[0] - q*x[1] + 6; 74 } 75 }; 76 } 77 78 79 80 81 template<class Real> 82 class Problem_024 : public ROL::NonlinearProgram<Real> { 83 84 85 86 typedef ROL::NonlinearProgram<Real> NP; 87 typedef ROL::Vector<Real> V; 88 typedef ROL::Objective<Real> OBJ; 89 typedef ROL::Constraint<Real> CON; 90 91 private: 92 public: 93 Problem_024()94 Problem_024() : NP( dimension_x() ) { 95 NP::setLower(0,0.0); 96 NP::setLower(1,0.0); 97 } 98 dimension_x()99 int dimension_x() { return 2; } dimension_ci()100 int dimension_ci() { return 3; } 101 getObjective()102 const ROL::Ptr<OBJ> getObjective() { 103 return ROL::makePtr<ROL::Sacado_StdObjective<Real,HS_024::Obj>>(); 104 } 105 getInequalityConstraint()106 const ROL::Ptr<CON> getInequalityConstraint() { 107 return ROL::makePtr<ROL::Sacado_StdConstraint<Real,HS_024::InCon>>(); 108 } 109 getInitialGuess()110 const ROL::Ptr<const V> getInitialGuess() { 111 Real x[] = {1.0,0.5}; 112 return NP::createOptVector(x); 113 }; 114 initialGuessIsFeasible()115 bool initialGuessIsFeasible() { return true; } 116 getInitialObjectiveValue()117 Real getInitialObjectiveValue() { 118 return Real(-0.01336459); 119 } 120 getSolutionObjectiveValue()121 Real getSolutionObjectiveValue() { 122 return Real(-1.0); 123 } 124 getSolutionSet()125 ROL::Ptr<const V> getSolutionSet() { 126 const Real x[] = {3,std::sqrt(3)}; 127 return ROL::CreatePartitionedVector(NP::createOptVector(x)); 128 } 129 130 }; 131 132 } 133 134 #endif // HS_PROBLEM_024_HPP 135