| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Rapid Optimization Library (ROL) Package |
| 4 |
// |
| 5 |
// Copyright 2014 NTESS and the ROL contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#ifndef HS_PROBLEM_007_HPP |
| 11 |
#define HS_PROBLEM_007_HPP |
| 12 |
|
| 13 |
#include "ROL_NonlinearProgram.hpp" |
| 14 |
|
| 15 |
namespace HS { |
| 16 |
|
| 17 |
namespace HS_007 { |
| 18 |
|
| 19 |
template<class Real> |
| 20 |
class Obj { |
| 21 |
public: |
| 22 |
template<class ScalarT> |
| 23 |
ScalarT value( const std::vector<ScalarT> &x, Real &tol ) { |
| 24 |
ScalarT a = 1.0+x[0]*x[0]; |
| 25 |
return std::log(a) - x[1]; |
| 26 |
} |
| 27 |
}; |
| 28 |
|
| 29 |
template<class Real> |
| 30 |
class EqCon { |
| 31 |
public: |
| 32 |
template<class ScalarT> |
| 33 |
void value( std::vector<ScalarT> &c, |
| 34 |
const std::vector<ScalarT> &x, |
| 35 |
Real &tol ) { |
| 36 |
ScalarT a = 1.0 + x[0]*x[0]; |
| 37 |
c[0] = a*a + x[1]*x[1] - 4; |
| 38 |
} |
| 39 |
}; |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
template<class Real> |
| 44 |
class Problem_007 : public ROL::NonlinearProgram<Real> { |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
typedef ROL::Vector<Real> V; |
| 49 |
typedef ROL::Objective<Real> OBJ; |
| 50 |
typedef ROL::Constraint<Real> CON; |
| 51 |
typedef ROL::NonlinearProgram<Real> NP; |
| 52 |
|
| 53 |
public: |
| 54 |
|
| 55 |
Problem_007() : NP( dimension_x() ) { |
| 56 |
NP::noBound(); |
| 57 |
} |
| 58 |
|
| 59 |
int dimension_x() { return 2; } |
| 60 |
int dimension_ce() { return 1; } |
| 61 |
|
| 62 |
const ROL::Ptr<OBJ> getObjective() { |
| 63 |
return ROL::makePtr<ROL::Sacado_StdObjective<Real,HS_007::Obj>>(); |
| 64 |
} |
| 65 |
|
| 66 |
const ROL::Ptr<CON> getEqualityConstraint() { |
| 67 |
return ROL::makePtr<ROL::Sacado_StdConstraint<Real,HS_007::EqCon>>(); |
| 68 |
} |
| 69 |
|
| 70 |
const ROL::Ptr<const V> getInitialGuess() { |
| 71 |
Real x[] = {2,2}; |
| 72 |
return NP::createOptVector(x); |
| 73 |
}; |
| 74 |
|
| 75 |
bool initialGuessIsFeasible() { return false; } |
| 76 |
|
| 77 |
Real getInitialObjectiveValue() { |
| 78 |
return std::log(5.0)-2.0; |
| 79 |
} |
| 80 |
|
| 81 |
Real getSolutionObjectiveValue() { |
| 82 |
return Real(-std::sqrt(3.0)); |
| 83 |
} |
| 84 |
|
| 85 |
ROL::Ptr<const V> getSolutionSet() { |
| 86 |
Real x[] = {0.0, std::sqrt(3)}; |
| 87 |
return ROL::CreatePartitionedVector(NP::createOptVector(x)); |
| 88 |
} |
| 89 |
|
| 90 |
}; |
| 91 |
|
| 92 |
} // namespace HS |
| 93 |
|
| 94 |
#endif // HS_PROBLEM_007_HPP |