Debian Codegraph @

packages/rol/adapters/sacado/test/HS/HS_Problem_035.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_035_HPP
11 #define HS_PROBLEM_035_HPP
12
13 #include "ROL_NonlinearProgram.hpp"
14
15 namespace HS {
16
17 namespace HS_035 {
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 9.0 - 8.0*x[0] - 6.0*x[1] - 4.0*x[2]
24 + 2.0*x[0]*x[0] + 2.0*x[1]*x[1] + x[2]*x[2]
25 + 2.0*x[0]*x[1] + 2.0*x[0]*x[2];
26 }
27 };
28
29 template<class Real>
30 class InCon {
31 public:
32 template<class ScalarT>
33 void value( std::vector<ScalarT> &c,
34 const std::vector<ScalarT> &x,
35 Real &tol ) {
36
37 c[0] = 3.0 - x[0] - x[1] - 2.0*x[2];
38
39 }
40 };
41 } // namspace HS_035
42
43
44 template<class Real>
45 class Problem_035 : public ROL::NonlinearProgram<Real> {
46
47
48
49 typedef ROL::NonlinearProgram<Real> NP;
50 typedef ROL::Vector<Real> V;
51 typedef ROL::Objective<Real> OBJ;
52 typedef ROL::Constraint<Real> CON;
53
54 public:
55
56 Problem_035() : NP( dimension_x() ) {
57 NP::setLower(0, 0.0);
58 NP::setLower(1, 0.0);
59 NP::setLower(2, 0.0);
60 }
61
62 int dimension_x() { return 3; }
63 int dimension_ci() { return 1; }
64
65 const ROL::Ptr<OBJ> getObjective() {
66 return ROL::makePtr<ROL::Sacado_StdObjective<Real,HS_035::Obj>>();
67 }
68
69 const ROL::Ptr<CON> getInequalityConstraint() {
70 return ROL::makePtr<ROL::Sacado_StdConstraint<Real,HS_035::InCon>>();
71 }
72
73 const ROL::Ptr<const V> getInitialGuess() {
74 Real x[] = {0.5,0.5,0.5};
75 return NP::createOptVector(x);
76 };
77
78 bool initialGuessIsFeasible() { return true; }
79
80 Real getInitialObjectiveValue() {
81 return Real(2.25);
82 }
83
84 Real getSolutionObjectiveValue() {
85 return Real(1.0/9.0);
86 }
87
88 ROL::Ptr<const V> getSolutionSet() {
89 Real x[] = { 4.0/3.0, 7.0/9.0, 4.0/9.0 };
90
91 return ROL::CreatePartitionedVector(NP::createOptVector(x));
92 }
93
94 };
95
96 } // namespace HS
97
98 #endif // HS_PROBLEM_035_HPP