Completed
Push — master ( 71dc45...9b6f89 )
by Grega
9s
created

Rosenbrock   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 19
rs 10
wmc 4
1
# encoding=utf8
2
# pylint: disable=anomalous-backslash-in-string
3
"""Implementation of Rosenbrock benchmark function.
4
5
Date: 2018
6
7
Authors: Iztok Fister Jr. and Lucija Brezočnik
8
9
License: MIT
10
11
Function: Rosenbrock function
12
13
Input domain:
14
    The function can be defined on any input domain but it is usually
15
    evaluated on the hypercube x_i ∈ [-30, 30], for all i = 1, 2,..., D.
16
17
Global minimum:
18
    f(x*) = 0, at x* = (1,...,1)
19
20
LaTeX formats:
21
    Inline: $f(x) = \sum_{i=1}^{D-1} (100 (x_{i+1} - x_i^2)^2 + (x_i - 1)^2)$
22
    Equation: \begin{equation}
23
              f(x) = \sum_{i=1}^{D-1} (100 (x_{i+1} - x_i^2)^2 + (x_i - 1)^2)
24
              \end{equation}
25
    Domain: $-30 \leq x_i \leq 30$
26
27
Reference paper:
28
    Jamil, M., and Yang, X. S. (2013).
29
    A literature survey of benchmark functions for global optimisation problems.
30
    International Journal of Mathematical Modelling and Numerical Optimisation,
31
    4(2), 150-194.
32
"""
33
34
import math
35
36
__all__ = ['Rosenbrock']
37
38
39
class Rosenbrock(object):
40
41
    def __init__(self, Lower=-30, Upper=30):
42
        self.Lower = Lower
43
        self.Upper = Upper
44
45
    @classmethod
46
    def function(cls):
47
        def evaluate(D, sol):
48
49
            val = 0.0
50
51
            for i in range(D - 1):
52
                val += 100 * math.pow(sol[i + 1] - math.pow((sol[i]), 2), 2) + math.pow((sol[i] - 1), 2)
53
54
            return val
55
56
        return evaluate
57