ROL
sacado/example_02.hpp
Go to the documentation of this file.
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#include "ROL_StdVector.hpp"
11
12using namespace ROL;
13
14
18template<class Real>
20 public:
21 template<class ScalarT>
22 ScalarT value(const Vector<ScalarT> &x, Real &tol);
23
24};
25
26template <class Real>
27template <class ScalarT>
28ScalarT Example_Objective<Real>::value(const Vector<ScalarT>& x, Real &tol) {
29
30 ROL::Ptr<const std::vector<ScalarT> > xp =
31 (dynamic_cast<const StdVector<ScalarT>&>(x)).getVector();
32
33 ScalarT x1 = (*xp)[0];
34 ScalarT x2 = (*xp)[1];
35 ScalarT x3 = (*xp)[2];
36 ScalarT x4 = (*xp)[3];
37 ScalarT x5 = (*xp)[4];
38
39 ScalarT J = exp(x1*x2*x3*x4*x5) - 0.5 * pow( (pow(x1,3)+pow(x2,3)+1.0), 2);
40 return J;
41}
42
43
44
50template<class Real>
51class Example_Constraint {
52 public:
53 int dim;
54
55 template<class ScalarT>
56 void value(Vector<ScalarT> &c, const Vector<ScalarT> &x, Real &tol);
57};
58
59
60template<class Real>
61template<class ScalarT>
62void Example_Constraint<Real>::value(Vector<ScalarT> &c, const Vector<ScalarT> &x, Real &tol) {
63
64 typedef std::vector<ScalarT> vector;
65 typedef StdVector<ScalarT> SV;
66
67
68
69 ROL::Ptr<vector> cp = dynamic_cast<SV&>(c).getVector();
70 ROL::Ptr<const vector> xp = dynamic_cast<const SV&>(x).getVector();
71
72 ScalarT x1 = (*xp)[0];
73 ScalarT x2 = (*xp)[1];
74 ScalarT x3 = (*xp)[2];
75 ScalarT x4 = (*xp)[3];
76 ScalarT x5 = (*xp)[4];
77
78 (*cp)[0] = x1*x1+x2*x2+x3*x3+x4*x4+x5*x5 - 10.0;
79 (*cp)[1] = x2*x3 - 5.0*x4*x5;
80 (*cp)[2] = x1*x1*x1 + x2*x2*x2 + 1.0;
81
82}
83
Objective function:
ScalarT value(const Vector< ScalarT > &x, Real &tol)
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Defines the linear algebra or vector space interface.
ROL::Objective_SerialSimOpt Objective_SimOpt value(const V &u, const V &z, Real &tol) override
constexpr auto dim