| 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_008_HPP |
| 11 |
#define HS_PROBLEM_008_HPP |
| 12 |
|
| 13 |
#include "ROL_NonlinearProgram.hpp" |
| 14 |
|
| 15 |
namespace HS { |
| 16 |
|
| 17 |
namespace HS_008 { |
| 18 |
template<class Real> |
| 19 |
class Obj { |
| 20 |
public: |
| 21 |
template<class ScalarT> |
| 22 |
ScalarT value( const std::vector<ScalarT> &x, Real &tol ) { |
| 23 |
return ScalarT(-1.0); |
| 24 |
} |
| 25 |
}; |
| 26 |
|
| 27 |
template<class Real> |
| 28 |
class EqCon { |
| 29 |
public: |
| 30 |
template<class ScalarT> |
| 31 |
void value( std::vector<ScalarT> &c, |
| 32 |
const std::vector<ScalarT> &x, |
| 33 |
Real &tol ) { |
| 34 |
c[0] = x[0]*x[0] + x[1]*x[1] - 25.0; |
| 35 |
c[1] = x[0]*x[1] - 9.0; |
| 36 |
} |
| 37 |
}; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
template<class Real> |
| 42 |
class Problem_008 : public ROL::NonlinearProgram<Real> { |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
typedef ROL::Vector<Real> V; |
| 47 |
typedef ROL::Objective<Real> OBJ; |
| 48 |
typedef ROL::Constraint<Real> CON; |
| 49 |
typedef ROL::NonlinearProgram<Real> NP; |
| 50 |
|
| 51 |
public: |
| 52 |
|
| 53 |
Problem_008() : NP( dimension_x() ) { |
| 54 |
NP::noBound(); |
| 55 |
} |
| 56 |
|
| 57 |
int dimension_x() { return 2; } |
| 58 |
int dimension_ce() { return 2; } |
| 59 |
|
| 60 |
const ROL::Ptr<OBJ> getObjective() { |
| 61 |
return ROL::makePtr<ROL::Sacado_StdObjective<Real,HS_008::Obj>>(); |
| 62 |
} |
| 63 |
|
| 64 |
const ROL::Ptr<CON> getEqualityConstraint() { |
| 65 |
return ROL::makePtr<ROL::Sacado_StdConstraint<Real,HS_008::EqCon>>(); |
| 66 |
} |
| 67 |
|
| 68 |
const ROL::Ptr<const V> getInitialGuess() { |
| 69 |
Real x[] = {2,1}; |
| 70 |
return NP::createOptVector(x); |
| 71 |
}; |
| 72 |
|
| 73 |
bool initialGuessIsFeasible() { return false; } |
| 74 |
|
| 75 |
Real getInitialObjectiveValue() { |
| 76 |
return Real(-1.0); |
| 77 |
} |
| 78 |
|
| 79 |
Real getSolutionObjectiveValue() { |
| 80 |
return Real(-1.0); |
| 81 |
} |
| 82 |
|
| 83 |
ROL::Ptr<const V> getSolutionSet() { |
| 84 |
|
| 85 |
Real a = std::sqrt( (25.0 + std::sqrt(301.0))/2.0 ); |
| 86 |
Real b = std::sqrt( (25.0 - std::sqrt(301.0))/2.0 ); |
| 87 |
|
| 88 |
Real x1[] = { a, 9/a}; |
| 89 |
Real x2[] = {-a, -9/a}; |
| 90 |
Real x3[] = { b, 9/b}; |
| 91 |
Real x4[] = {-b, -9/b}; |
| 92 |
|
| 93 |
return ROL::CreatePartitionedVector(NP::createOptVector(x1), |
| 94 |
NP::createOptVector(x2), |
| 95 |
NP::createOptVector(x3), |
| 96 |
NP::createOptVector(x4)); |
| 97 |
} |
| 98 |
|
| 99 |
}; |
| 100 |
|
| 101 |
} // namespace HS |
| 102 |
|
| 103 |
#endif // HS_PROBLEM_008_HPP |