Debian Codegraph @

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