Debian Codegraph @

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