ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
example
sacado
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
12
using namespace
ROL
;
13
14
18
template
<
class
Real>
19
class
Example_Objective
{
20
public
:
21
template
<
class
ScalarT>
22
ScalarT
value
(
const
Vector<ScalarT>
&x, Real &tol);
23
24
};
25
26
template
<
class
Real>
27
template
<
class
ScalarT>
28
ScalarT
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
50
template
<
class
Real>
51
class
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
60
template
<
class
Real>
61
template
<
class
ScalarT>
62
void
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
ROL_StdVector.hpp
Example_Objective
Objective function:
Definition
sacado/example_02.hpp:19
Example_Objective::value
ScalarT value(const Vector< ScalarT > &x, Real &tol)
Definition
sacado/example_02.hpp:28
ROL::StdVector
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Definition
ROL_StdVector.hpp:27
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::value
ROL::Objective_SerialSimOpt Objective_SimOpt value(const V &u, const V &z, Real &tol) override
Definition
ROL_Objective_SerialSimOpt.hpp:50
dim
constexpr auto dim
Definition
vector/test_11.cpp:23
Generated by
1.17.0