ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
zoo
testproblems
ROL_Minimax1.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
#ifndef ROL_MINIMAX1_HPP
11
#define ROL_MINIMAX1_HPP
12
13
#include "
ROL_TestProblem.hpp
"
14
#include "
ROL_StdVector.hpp
"
15
#include "ROL_Ptr.hpp"
16
17
namespace
ROL
{
18
namespace
ZOO
{
19
20
template
<
class
Real>
21
class
Minimax1
:
public
Objective
<Real> {
22
23
typedef
std::vector<Real>
vector
;
24
typedef
Vector<Real>
V
;
25
typedef
StdVector<Real>
SV
;
26
27
private
:
28
29
Ptr<const vector>
getVector
(
const
V
& x ) {
30
return
dynamic_cast<
const
SV
&
>
(x).
getVector
();
31
}
32
33
Ptr<vector>
getVector
(
V
& x ) {
34
return
dynamic_cast<
SV
&
>
(x).
getVector
();
35
}
36
37
public
:
38
Minimax1
(
void
) {}
39
40
Real
value
(
const
Vector<Real>
&x, Real &tol) {
41
Ptr<const vector> xp =
getVector
(x);
42
Real f1 = std::pow((*xp)[0],2.0) + std::pow((*xp)[1],4.0);
43
Real f2 = std::pow(2.0-(*xp)[0],2.0) + std::pow(2.0-(*xp)[1],2.0);
44
Real f3 = 2.0*std::exp(-(*xp)[0] + (*xp)[1]);
45
return
std::max(f1,std::max(f2,f3));
46
}
47
48
void
gradient
(
Vector<Real>
&g,
const
Vector<Real>
&x, Real &tol) {
49
Ptr<const vector> xp =
getVector
(x);
50
Ptr<vector> gp =
getVector
(g);
51
Real f1 = std::pow((*xp)[0],2.0) + std::pow((*xp)[1],4.0);
52
Real f2 = std::pow(2.0-(*xp)[0],2.0) + std::pow(2.0-(*xp)[1],2.0);
53
Real f3 = 2.0*std::exp(-(*xp)[0] + (*xp)[1]);
54
55
//int ind = ((f1 >= f2) ? ((f1 < f3) ? 3 : 1) : ((f2 < f3) ? 3 : 2));
56
if
( f1 >= std::max(f2,f3) ) {
57
(*gp)[0] = 2.0*(*xp)[0];
58
(*gp)[1] = 4.0*std::pow((*xp)[1],3.0);
59
}
60
else
if
( f2 >= std::max(f1,f3) ) {
61
(*gp)[0] = 2.0*(*xp)[0]-4.0;
62
(*gp)[1] = 2.0*(*xp)[1]-4.0;
63
}
64
else
if
( f3 >= std::max(f1,f2) ) {
65
(*gp)[0] = -2.0*std::exp(-(*xp)[0]+(*xp)[1]);
66
(*gp)[1] = 2.0*std::exp(-(*xp)[0]+(*xp)[1]);
67
}
68
}
69
};
// class Minimax1
70
71
template
<
class
Real>
72
class
getMinimax1
:
public
TestProblem
<Real> {
73
public
:
74
getMinimax1
(
void
) {}
75
76
Ptr<Objective<Real>>
getObjective
(
void
)
const
{
77
return
makePtr<Minimax1<Real>>();
78
}
79
80
Ptr<Vector<Real>>
getInitialGuess
(
void
)
const
{
81
Ptr<std::vector<Real> > x_ptr = makePtr<std::vector<Real>>(2, 0.0);
82
(*x_ptr)[0] = 1.0; (*x_ptr)[1] = -0.1;
83
return
makePtr<StdVector<Real>>(x_ptr);
84
}
85
86
Ptr<Vector<Real>>
getSolution
(
const
int
i = 0)
const
{
87
Ptr<std::vector<Real> > z_ptr = makePtr<std::vector<Real>>(2, 0.0);
88
(*z_ptr)[0] = 1.13904; (*z_ptr)[1] = 0.89956;
89
return
makePtr<StdVector<Real>>(z_ptr);
90
}
91
};
92
93
}
// namespace ZOO
94
}
// namespace ROL
95
96
#endif
ROL_StdVector.hpp
ROL_TestProblem.hpp
Contains definitions of test objective functions.
ROL::ROL::Objective::Objective
Objective()
Definition
ROL_Constraint_SerialSimOpt.hpp:53
ROL::StdVector
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Definition
ROL_StdVector.hpp:27
ROL::TestProblem::TestProblem
TestProblem(void)
Definition
ROL_TestProblem.hpp:28
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL::ZOO::Minimax1::value
Real value(const Vector< Real > &x, Real &tol)
Definition
ROL_Minimax1.hpp:40
ROL::ZOO::Minimax1::gradient
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Definition
ROL_Minimax1.hpp:48
ROL::ZOO::Minimax1::SV
StdVector< Real > SV
Definition
ROL_Minimax1.hpp:25
ROL::ZOO::Minimax1::Minimax1
Minimax1(void)
Definition
ROL_Minimax1.hpp:38
ROL::ZOO::Minimax1::getVector
Ptr< const vector > getVector(const V &x)
Definition
ROL_Minimax1.hpp:29
ROL::ZOO::Minimax1::getVector
Ptr< vector > getVector(V &x)
Definition
ROL_Minimax1.hpp:33
ROL::ZOO::Minimax1::vector
std::vector< Real > vector
Definition
ROL_Minimax1.hpp:23
ROL::ZOO::Minimax1::V
Vector< Real > V
Definition
ROL_Minimax1.hpp:24
ROL::ZOO::getMinimax1::getSolution
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition
ROL_Minimax1.hpp:86
ROL::ZOO::getMinimax1::getMinimax1
getMinimax1(void)
Definition
ROL_Minimax1.hpp:74
ROL::ZOO::getMinimax1::getInitialGuess
Ptr< Vector< Real > > getInitialGuess(void) const
Definition
ROL_Minimax1.hpp:80
ROL::ZOO::getMinimax1::getObjective
Ptr< Objective< Real > > getObjective(void) const
Definition
ROL_Minimax1.hpp:76
ROL::ZOO
Definition
ROL_Beale.hpp:26
ROL
Definition
ROL_ElementwiseVector.hpp:27
Generated by
1.17.0