Shark machine learning library
Installation
Tutorials
Benchmarks
Documentation
Quick references
Class list
Global functions
include
shark
ObjectiveFunctions
Benchmarks
DTLZ5.h
Go to the documentation of this file.
1
//===========================================================================
2
/*!
3
*
4
*
5
* \brief Objective function DTLZ5
6
*
7
*
8
*
9
* \author T.Voss, T. Glasmachers, O.Krause
10
* \date 2010-2011
11
*
12
*
13
* \par Copyright 1995-2017 Shark Development Team
14
*
15
* <BR><HR>
16
* This file is part of Shark.
17
* <https://shark-ml.github.io/Shark/>
18
*
19
* Shark is free software: you can redistribute it and/or modify
20
* it under the terms of the GNU Lesser General Public License as published
21
* by the Free Software Foundation, either version 3 of the License, or
22
* (at your option) any later version.
23
*
24
* Shark is distributed in the hope that it will be useful,
25
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
* GNU Lesser General Public License for more details.
28
*
29
* You should have received a copy of the GNU Lesser General Public License
30
* along with Shark. If not, see <http://www.gnu.org/licenses/>.
31
*
32
*/
33
//===========================================================================
34
#ifndef SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_DTLZ5_H
35
#define SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_DTLZ5_H
36
37
#include <
shark/ObjectiveFunctions/AbstractObjectiveFunction.h
>
38
#include <
shark/ObjectiveFunctions/BoxConstraintHandler.h
>
39
40
namespace
shark
{
namespace
benchmarks{
41
/**
42
* \brief Implements the benchmark function DTLZ5.
43
*
44
* See: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.18.7531&rep=rep1&type=pdf
45
* The benchmark function exposes the following features:
46
* - Scalable w.r.t. the searchspace and w.r.t. the objective space.
47
* - Highly multi-modal.
48
* \ingroup benchmarks
49
*/
50
struct
DTLZ5
:
public
MultiObjectiveFunction
51
{
52
DTLZ5
(std::size_t numVariables = 0) : m_objectives(2), m_handler(
SearchPointType
(numVariables,0),
SearchPointType
(numVariables,1) ){
53
announceConstraintHandler
(&m_handler);
54
}
55
56
/// \brief From INameable: return the class name.
57
std::string
name
()
const
58
{
return
"DTLZ5"
; }
59
60
std::size_t
numberOfObjectives
()
const
{
61
return
m_objectives;
62
}
63
bool
hasScalableObjectives
()
const
{
64
return
true
;
65
}
66
void
setNumberOfObjectives
( std::size_t
numberOfObjectives
){
67
m_objectives =
numberOfObjectives
;
68
}
69
70
std::size_t
numberOfVariables
()
const
{
71
return
m_handler.
dimensions
();
72
}
73
74
bool
hasScalableDimensionality
()
const
{
75
return
true
;
76
}
77
78
/// \brief Adjusts the number of variables if the function is scalable.
79
/// \param [in] numberOfVariables The new dimension.
80
void
setNumberOfVariables
( std::size_t
numberOfVariables
){
81
m_handler.
setBounds
(
82
SearchPointType
(
numberOfVariables
,0),
83
SearchPointType
(
numberOfVariables
,1)
84
);
85
}
86
87
ResultType
eval
(
const
SearchPointType
& x )
const
{
88
m_evaluationCounter
++;
89
90
ResultType
value(
numberOfObjectives
() );
91
92
std::vector<double> phi(
numberOfObjectives
());
93
94
std::size_t k =
numberOfVariables
() -
numberOfObjectives
() + 1 ;
95
double
g = 0.0 ;
96
97
for
(std::size_t i =
numberOfVariables
() - k + 1; i <=
numberOfVariables
(); i++)
98
g +=
sqr
( x(i-1) - 0.5 );
99
100
double
t = M_PI / (4 * (1 + g));
101
102
phi[0] = x( 0 ) * M_PI / 2;
103
for
(std::size_t i = 2; i <= (
numberOfObjectives
() - 1); i++)
104
phi[i-1] = t * (1 + 2 * g * x( i-1 ) );
105
106
for
(std::size_t i = 1; i <=
numberOfObjectives
(); i++) {
107
double
f = (1 + g);
108
109
for
(std::size_t j =
numberOfObjectives
() - i; j >= 1; j--)
110
f *= std::cos(phi[j-1]);
111
112
if
(i > 1)
113
f *= std::sin(phi[(
numberOfObjectives
() - i + 1 ) - 1]);
114
115
value[i-1] = f ;
116
}
117
118
return
value;
119
}
120
121
private
:
122
std::size_t m_objectives;
123
BoxConstraintHandler<SearchPointType>
m_handler;
124
};
125
126
}}
127
#endif