Debian Codegraph @

packages/rol/adapters/sacado/test/HS/HS_Problem_030.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_030_HPP
11 #define HS_PROBLEM_030_HPP
12
13 #include "ROL_NonlinearProgram.hpp"
14
15 namespace HS {
16
17 namespace HS_030 {
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[0]+x[1]*x[1]+x[2]*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
36 c[0] = x[0]*x[0] + x[1]*x[1] - 1.0;
37
38 }
39 };
40 }
41
42
43 template<class Real>
44 class Problem_030 : 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_030() : NP( dimension_x() ) {
56 NP::setLower(0, 1.0);
57 NP::setUpper(0, 10.0);
58 NP::setLower(1,-10.0);
59 NP::setUpper(1, 10.0);
60 NP::setLower(2,-10.0);
61 NP::setUpper(2, 10.0);
62 }
63
64 int dimension_x() { return 3; }
65 int dimension_ci() { return 1; }
66
67 const ROL::Ptr<OBJ> getObjective() {
68 return ROL::makePtr<ROL::Sacado_StdObjective<Real,HS_030::Obj>>();
69 }
70
71 const ROL::Ptr<CON> getInequalityConstraint() {
72 return ROL::makePtr<ROL::Sacado_StdConstraint<Real,HS_030::InCon>>();
73 }
74
75 const ROL::Ptr<const V> getInitialGuess() {
76 Real x[] = {1.0,1.0,1.0};
77 return NP::createOptVector(x);
78 };
79
80 bool initialGuessIsFeasible() { return true; }
81
82 Real getInitialObjectiveValue() {
83 return Real(3);
84 }
85
86 Real getSolutionObjectiveValue() {
87 return Real(1);
88 }
89
90 ROL::Ptr<const V> getSolutionSet() {
91 Real x[] = { 1, 0, 0};
92
93 return ROL::CreatePartitionedVector(NP::createOptVector(x));
94 }
95
96 };
97
98 } // namespace HS
99
100 #endif // HS_PROBLEM_030_HPP