Debian Codegraph @

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