Debian Codegraph @

packages/rol/adapters/sacado/test/HS/HS_Problem_032.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_032_HPP
11 #define HS_PROBLEM_032_HPP
12
13 #include "ROL_NonlinearProgram.hpp"
14
15 namespace HS {
16
17 namespace HS_032 {
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]+3*x[1]+x[2];
24 ScalarT b = x[0]-x[1];
25 return a*a + 4*b*b;
26 }
27 };
28
29
30 template<class Real>
31 class EqCon {
32 public:
33 template<class ScalarT>
34 void value( std::vector<ScalarT> &c,
35 const std::vector<ScalarT> &x,
36 Real &tol ) {
37
38 c[0] = 1.0 - x[0] - x[1] - x[2];
39
40 }
41 };
42
43
44
45 template<class Real>
46 class InCon {
47 public:
48 template<class ScalarT>
49 void value( std::vector<ScalarT> &c,
50 const std::vector<ScalarT> &x,
51 Real &tol ) {
52
53 c[0] = 6*x[1] + 4*x[2] - x[0]*x[0]*x[0] - 3.0;
54
55 }
56 };
57 } // namespace HS_032
58
59
60 template<class Real>
61 class Problem_032 : public ROL::NonlinearProgram<Real> {
62
63
64
65 typedef ROL::NonlinearProgram<Real> NP;
66 typedef ROL::Vector<Real> V;
67 typedef ROL::Objective<Real> OBJ;
68 typedef ROL::Constraint<Real> CON;
69
70 public:
71
72 Problem_032() : NP( dimension_x() ) {
73 NP::setLower(0, 0.0);
74 NP::setLower(1, 0.0);
75 NP::setLower(2, 0.0);
76 }
77
78 int dimension_x() { return 3; }
79 int dimension_ce() { return 1; }
80 int dimension_ci() { return 1; }
81
82 const ROL::Ptr<OBJ> getObjective() {
83 return ROL::makePtr<ROL::Sacado_StdObjective<Real,HS_032::Obj>>();
84 }
85
86 const ROL::Ptr<CON> getInequalityConstraint() {
87 return ROL::makePtr<ROL::Sacado_StdConstraint<Real,HS_032::InCon>>();
88 }
89
90 const ROL::Ptr<const V> getInitialGuess() {
91 Real x[] = {0.1,0.7,0.2};
92 return NP::createOptVector(x);
93 };
94
95 bool initialGuessIsFeasible() { return true; }
96
97 Real getInitialObjectiveValue() {
98 return Real(7.2);
99 }
100
101 Real getSolutionObjectiveValue() {
102 return Real(1.0);
103 }
104
105 ROL::Ptr<const V> getSolutionSet() {
106 Real x[] = { 0., 0., 1.0};
107
108 return ROL::CreatePartitionedVector(NP::createOptVector(x));
109 }
110
111 };
112
113 } // namespace HS
114
115 #endif // HS_PROBLEM_032_HPP