Debian Codegraph @

packages/rol/adapters/sacado/test/HS/HS_Problem_012.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_012_HPP
11 #define HS_PROBLEM_012_HPP
12
13 #include "ROL_NonlinearProgram.hpp"
14
15 namespace HS {
16
17 namespace HS_012 {
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.5*x[0]*x[0] + x[1]*x[1] - x[0]*x[1] - 7*x[0] - 7*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, const std::vector<ScalarT> &x, Real &tol ) {
32 c[0] = 25 - 4*x[0]*x[0] - x[1]*x[1];
33 }
34 };
35 }
36
37
38 template<class Real>
39 class Problem_012 : public ROL::NonlinearProgram<Real> {
40
41
42
43 typedef ROL::Vector<Real> V;
44 typedef ROL::PartitionedVector<Real> PV;
45 typedef ROL::Objective<Real> OBJ;
46 typedef ROL::Constraint<Real> CON;
47 typedef ROL::NonlinearProgram<Real> NP;
48
49
50 public:
51
52 Problem_012() : NP( dimension_x() ) {
53 NP::noBound();
54 }
55
56 int dimension_x() { return 2; }
57 int dimension_ci() { return 1; }
58
59 const ROL::Ptr<OBJ> getObjective() {
60 return ROL::makePtr<ROL::Sacado_StdObjective<Real,HS_012::Obj>>();
61 }
62
63 const ROL::Ptr<CON> getInequalityConstraint() {
64 return ROL::makePtr<ROL::Sacado_StdConstraint<Real,HS_012::InCon>>();
65 }
66
67 const ROL::Ptr<const V> getInitialGuess() {
68 Real x[] = {0,0};
69 return NP::createOptVector(x);
70 };
71
72 bool initialGuessIsFeasible() { return true; }
73
74 Real getInitialObjectiveValue() {
75 return Real(0);
76 }
77
78 Real getSolutionObjectiveValue() {
79 return Real(-30);
80 }
81
82 ROL::Ptr<const V> getSolutionSet() {
83 Real x[] = {2,3};
84 return ROL::CreatePartitionedVector(NP::createOptVector(x));
85 }
86
87 };
88
89 } // namespace HS
90
91 #endif // HS_PROBLEM_012_HPP