| 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_013_HPP |
| 11 |
#define HS_PROBLEM_013_HPP |
| 12 |
|
| 13 |
#include "ROL_NonlinearProgram.hpp" |
| 14 |
|
| 15 |
namespace HS { |
| 16 |
|
| 17 |
namespace HS_013 { |
| 18 |
template<class Real> |
| 19 |
class Obj { |
| 20 |
public: |
| 21 |
template<class ScalarT> |
| 22 |
ScalarT value( const std::vector<ScalarT> &x, Real &tol ) { |
| 23 |
ScalarT a = x[0]-2.0; |
| 24 |
return a*a + x[1]*x[1]; |
| 25 |
} |
| 26 |
}; |
| 27 |
|
| 28 |
template<class Real> |
| 29 |
class InCon { |
| 30 |
public: |
| 31 |
template<class ScalarT> |
| 32 |
void value( std::vector<ScalarT> &c, |
| 33 |
const std::vector<ScalarT> &x, |
| 34 |
Real &tol ) { |
| 35 |
ScalarT a = 1-x[0]; |
| 36 |
c[0] = a*a*a - x[1]; |
| 37 |
} |
| 38 |
}; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
template<class Real> |
| 43 |
class Problem_013 : public ROL::NonlinearProgram<Real> { |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
typedef ROL::Vector<Real> V; |
| 48 |
typedef ROL::Objective<Real> OBJ; |
| 49 |
typedef ROL::Constraint<Real> CON; |
| 50 |
typedef ROL::NonlinearProgram<Real> NP; |
| 51 |
|
| 52 |
public: |
| 53 |
|
| 54 |
Problem_013() : NP( dimension_x() ) { |
| 55 |
NP::setLower(0,0); |
| 56 |
NP::setLower(1,0); |
| 57 |
} |
| 58 |
|
| 59 |
int dimension_x() { return 2; } |
| 60 |
int dimension_ci() { return 1; } |
| 61 |
|
| 62 |
const ROL::Ptr<OBJ> getObjective() { |
| 63 |
return ROL::makePtr<ROL::Sacado_StdObjective<Real,HS_013::Obj>>(); |
| 64 |
} |
| 65 |
|
| 66 |
const ROL::Ptr<CON> getInequalityConstraint() { |
| 67 |
return ROL::makePtr<ROL::Sacado_StdConstraint<Real,HS_013::InCon>>(); |
| 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 Real(20); |
| 79 |
} |
| 80 |
|
| 81 |
Real getSolutionObjectiveValue() { |
| 82 |
return Real(1); |
| 83 |
} |
| 84 |
|
| 85 |
ROL::Ptr<const V> getSolutionSet() { |
| 86 |
Real x[] = {1,0}; |
| 87 |
return ROL::CreatePartitionedVector(NP::createOptVector(x)); |
| 88 |
} |
| 89 |
|
| 90 |
}; |
| 91 |
|
| 92 |
} // namespace HS |
| 93 |
|
| 94 |
#endif // HS_PROBLEM_013_HPP |