Debian Codegraph @

packages/rol/adapters/sacado/test/HS/HS_Problem_009.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_009_HPP
11 #define HS_PROBLEM_009_HPP
12
13 #include "ROL_NonlinearProgram.hpp"
14
15 namespace HS {
16
17 namespace HS_009 {
18 template<class Real>
19 class Obj {
20 public:
21 template<class ScalarT>
22 ScalarT value( const std::vector<ScalarT> &x, Real &tol ) {
23 Real pi = 3.14159265359;
24 return std::sin(pi*x[0]/12.0)*std::cos(pi*x[1]/16.0);
25 }
26 };
27
28 template<class Real>
29 class EqCon {
30 public:
31 template<class ScalarT>
32 void value( std::vector<ScalarT> &c,
33 const std::vector<ScalarT> &x,
34 Real &tol ) {
35 c[0] = 4.0*x[0] - 3.0*x[1];
36 }
37 };
38 }
39
40
41 template<class Real>
42 class Problem_009 : 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_009() : NP( dimension_x() ) {
54 NP::noBound();
55 }
56
57 int dimension_x() { return 2; }
58 int dimension_ce() { return 1; }
59
60 const ROL::Ptr<OBJ> getObjective() {
61 return ROL::makePtr<ROL::Sacado_StdObjective<Real,HS_009::Obj>>();
62 }
63
64 const ROL::Ptr<CON> getEqualityConstraint() {
65 return ROL::makePtr<ROL::Sacado_StdConstraint<Real,HS_009::EqCon>>();
66 }
67
68 const ROL::Ptr<const V> getInitialGuess() {
69 Real x[] = {0,0};
70 return NP::createOptVector(x);
71 };
72
73 bool initialGuessIsFeasible() { return true; }
74
75 Real getInitialObjectiveValue() {
76 return Real(0.0);
77 }
78
79 Real getSolutionObjectiveValue() {
80 return Real(-0.5);
81 }
82
83 // x* = (12k-3,16k-4) for all integer k
84 ROL::Ptr<const V> getSolutionSet() {
85
86 Real x1[] = {-15,-20};
87 Real x2[] = {-3, -4};
88 Real x3[] = { 9, 12};
89
90 return ROL::CreatePartitionedVector(NP::createOptVector(x1),
91 NP::createOptVector(x2),
92 NP::createOptVector(x3));
93 }
94
95 };
96
97 } // namespace HS
98
99 #endif // HS_PROBLEM_009_HPP