Debian Codegraph @

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