Debian Codegraph @

packages/rol/adapters/sacado/test/HS/HS_Problem_040.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_040_HPP
11 #define HS_PROBLEM_040_HPP
12
13 #include "ROL_NonlinearProgram.hpp"
14
15 namespace HS {
16
17 namespace HS_040 {
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[1]*x[2]*x[3];
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]*x[0]*x[0] + x[1]*x[1] - 1.0;
35 c[1] = x[0]*x[0]*x[3] - x[2];
36 c[2] = x[3]*x[3] - x[1];
37 }
38 };
39 } // HS_040
40
41
42 template<class Real>
43 class Problem_040 : 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_040() : NP( dimension_x() ) {
55 NP::noBound();
56 }
57
58 int dimension_x() { return 4; }
59 int dimension_ce() { return 3; }
60
61 const ROL::Ptr<OBJ> getObjective() {
62 return ROL::makePtr<ROL::Sacado_StdObjective<Real,HS_040::Obj>>();
63 }
64
65 const ROL::Ptr<CON> getEqualityConstraint() {
66 return ROL::makePtr<ROL::Sacado_StdConstraint<Real,HS_040::EqCon>>();
67 }
68
69 const ROL::Ptr<const V> getInitialGuess() {
70 Real x[] = {0.8,0.8,0.8,0.8};
71 return NP::createOptVector(x);
72 };
73
74 bool initialGuessIsFeasible() { return false; }
75
76 Real getInitialObjectiveValue() {
77 return Real(-0.4096);
78 }
79
80 Real getSolutionObjectiveValue() {
81 return Real(-0.25);
82 }
83
84 ROL::Ptr<const V> getSolutionSet() {
85 Real a = -1.0/3.0;
86 Real b = -1.0/4.0;
87 Real c = -11.0/12.0;
88 Real x1[] = {std::pow(2.0,a),std::pow(2.0,2*b),-std::pow(2.0,c),-std::pow(2.0,b)};
89 Real x2[] = {std::pow(2.0,a),std::pow(2.0,2*b), std::pow(2.0,c), std::pow(2.0,b)};
90
91 return ROL::CreatePartitionedVector(NP::createOptVector(x1),
92 NP::createOptVector(x2));
93 }
94
95 };
96
97 } // namespace HS
98
99 #endif // HS_PROBLEM_040_HPP