Debian Codegraph @

packages/rol/adapters/sacado/test/HS/HS_Problem_005.hpp

raw
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_005_HPP
11 #define HS_PROBLEM_005_HPP
12
13 #include "ROL_NonlinearProgram.hpp"
14
15 namespace HS {
16
17 namespace HS_005 {
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]+x[1];
24 ScalarT b = x[1]-x[0];
25 return std::sin(a) + b*b - 1.5*x[0] + 2.5*x[1] + 1.0;
26 }
27 };
28 }
29
30
31 template<class Real>
32 class Problem_005 : public ROL::NonlinearProgram<Real> {
33
34
35
36
37 typedef ROL::Vector<Real> V;
38 typedef ROL::Objective<Real> OBJ;
39 typedef ROL::NonlinearProgram<Real> NP;
40
41 const Real pi;
42
43 public:
44
45 Problem_005() : NP( dimension_x() ), pi(3.14159265459) {
46 Real l[] = {-1.5,-3.0};
47 Real u[] = {4.0,3.0};
48 NP::setLower(l); NP::setUpper(u);
49 }
50
51 int dimension_x() { return 2; }
52
53 const ROL::Ptr<OBJ> getObjective() {
54 return ROL::makePtr<ROL::Sacado_StdObjective<Real,HS_005::Obj>>();
55 }
56
57 const ROL::Ptr<const V> getInitialGuess() {
58 Real x[] = {0,0};
59 return NP::createOptVector(x);
60 };
61
62 bool initialGuessIsFeasible() { return true; }
63
64 Real getInitialObjectiveValue() {
65 return Real(1.0);
66 }
67
68 Real getSolutionObjectiveValue() {
69 return Real(-std::sqrt(3.0)/2.0-pi/3.0);
70 }
71
72 ROL::Ptr<const V> getSolutionSet() {
73 Real x[] = {-pi/3.0+0.5,-pi/3.0-0.5};
74 return ROL::CreatePartitionedVector(NP::createOptVector(x));
75 }
76
77 };
78
79 } // namespace HS
80
81 #endif // HS_PROBLEM_005_HPP