Debian Codegraph @

packages/rol/adapters/sacado/test/HS/HS_Problem_029.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_029_HPP
11 #define HS_PROBLEM_029_HPP
12
13 #include "ROL_NonlinearProgram.hpp"
14
15 namespace HS {
16
17 namespace HS_029 {
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 -x[0]*x[1]*x[2];
24 }
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 c[0] = -x[0]*x[0] -2*x[1]*x[1] -4*x[2]*x[2] + 48;
36 }
37 };
38 }
39
40
41 template<class Real>
42 class Problem_029 : public ROL::NonlinearProgram<Real> {
43
44
45
46 typedef ROL::NonlinearProgram<Real> NP;
47 typedef ROL::Vector<Real> V;
48 typedef ROL::Objective<Real> OBJ;
49 typedef ROL::Constraint<Real> CON;
50
51 public:
52
53 Problem_029() : NP( dimension_x() ) {
54 NP::noBound();
55 }
56
57 int dimension_x() { return 3; }
58 int dimension_ci() { return 1; }
59
60 const ROL::Ptr<OBJ> getObjective() {
61 return ROL::makePtr<ROL::Sacado_StdObjective<Real,HS_029::Obj>>();
62 }
63
64 const ROL::Ptr<CON> getInequalityConstraint() {
65 return ROL::makePtr<ROL::Sacado_StdConstraint<Real,HS_029::InCon>>();
66 }
67
68 const ROL::Ptr<const V> getInitialGuess() {
69 Real x[] = {1.0,1.0,1.0};
70 return NP::createOptVector(x);
71 };
72
73 bool initialGuessIsFeasible() { return true; }
74
75 Real getInitialObjectiveValue() {
76 return Real(-1.0);
77 }
78
79 Real getSolutionObjectiveValue() {
80 return Real(-16*std::sqrt(2));
81 }
82
83 ROL::Ptr<const V> getSolutionSet() {
84 Real a = 4; Real b = 2*std::sqrt(2); Real c = 2;
85
86 Real x1[] = { a, b, c};
87 Real x2[] = { a,-b,-c};
88 Real x3[] = {-a, b,-c};
89 Real x4[] = {-a,-b, c};
90
91 return ROL::CreatePartitionedVector(NP::createOptVector(x1),
92 NP::createOptVector(x2),
93 NP::createOptVector(x3),
94 NP::createOptVector(x4));
95 }
96
97 };
98
99 } // namespace HS
100
101 #endif // HS_PROBLEM_029_HPP