Debian Codegraph @

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