Debian Codegraph @

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