Debian Codegraph @

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