Debian Codegraph @

packages/rol/adapters/sacado/test/HS/HS_Problem_028.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_028_HPP
11 #define HS_PROBLEM_028_HPP
12
13 #include "ROL_NonlinearProgram.hpp"
14
15 namespace HS {
16
17 namespace HS_028 {
18 template<class Real>
19 class Obj {
20 public:
21 template<class ScalarT>
22 ScalarT value( const std::vector<ScalarT> &x, Real &tol ) {
23 ScalarT a = (x[0]+x[1]);
24 ScalarT b = (x[1]+x[2]);
25 return a*a + b*b;
26 }
27 };
28
29
30 template<class Real>
31 class EqCon {
32 public:
33 template<class ScalarT>
34 void value( std::vector<ScalarT> &c,
35 const std::vector<ScalarT> &x,
36 Real &tol ) {
37 c[0] = x[0]+2*x[1]+3*x[2]-1.0;
38 }
39 };
40 }
41
42
43 template<class Real>
44 class Problem_028 : public ROL::NonlinearProgram<Real> {
45
46
47
48 typedef ROL::NonlinearProgram<Real> NP;
49 typedef ROL::Vector<Real> V;
50 typedef ROL::Objective<Real> OBJ;
51 typedef ROL::Constraint<Real> CON;
52
53 public:
54
55 Problem_028() : NP( dimension_x() ) {
56 NP::noBound();
57 }
58
59 int dimension_x() { return 3; }
60 int dimension_ce() { return 1; }
61
62 const ROL::Ptr<OBJ> getObjective() {
63 return ROL::makePtr<ROL::Sacado_StdObjective<Real,HS_028::Obj>>();
64 }
65
66 const ROL::Ptr<CON> getEqualityConstraint() {
67 return ROL::makePtr<ROL::Sacado_StdConstraint<Real,HS_028::EqCon>>();
68 }
69
70 const ROL::Ptr<const V> getInitialGuess() {
71 Real x[] = {-4.0,1.0,1.0};
72 return NP::createOptVector(x);
73 };
74
75 bool initialGuessIsFeasible() { return true; }
76
77 Real getInitialObjectiveValue() {
78 return Real(13.0);
79 }
80
81 Real getSolutionObjectiveValue() {
82 return Real(0);
83 }
84
85 ROL::Ptr<const V> getSolutionSet() {
86 Real x[] = {0.5,-0.5,0.5};
87 return ROL::CreatePartitionedVector(NP::createOptVector(x));
88 }
89
90 };
91
92 } // namespace HS
93
94 #endif // HS_PROBLEM_028_HPP