Passed
Pull Request — master (#23)
by Grega
01:00
created

Schwefel   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 4
1
# encoding=utf8
2
# pylint: disable=anomalous-backslash-in-string
3
"""Implementation of Schwefel function.
4
5
Date: 2018
6
7
Author: Lucija Brezočnik
8
9
License: MIT
10
11
Function: Schwefel 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 ∈ [-500, 500], for all i = 1, 2,..., D.
16
17
Global minimum:
18
    f(x*) = 0, at x* = (420.9687,...,420.9687)
19
20
LaTeX formats:
21
    Inline: $f(\textbf{x}) = 418.9829d - \sum_{i=1}^{D} x_i sin(\sqrt{|x_i|})$
22
    Equation: \begin{equation} f(\textbf{x}) =
23
              418.9829d - \sum_{i=1}^{D} x_i
24
              sin(\sqrt{|x_i|}) \end{equation}
25
    Domain: $-500 \leq x_i \leq 500$
26
27
Reference: https://www.sfu.ca/~ssurjano/schwef.html
28
"""
29
30
import math
31
32
__all__ = ['Schwefel']
33
34
35
class Schwefel(object):
36
37
    def __init__(self, Lower=-500, Upper=500):
38
        self.Lower = Lower
39
        self.Upper = Upper
40
41
    @classmethod
42
    def function(cls):
43
        def evaluate(D, sol):
44
45
            val = 0.0
46
            val1 = 0.0
47
48
            for i in range(D):
49
                val1 += (sol[i] * math.sin(math.sqrt(abs(sol[i]))))
50
51
            val = 418.9829 * D - val1
52
53
            return val
54
55
        return evaluate
56