Debian Codegraph @

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