Passed
Pull Request — master (#23)
by
unknown
01:10
created

Schwefel.evaluate()   A

Complexity

Conditions 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
1
"""Implementation of Schwefel function.
0 ignored issues
show
Bug introduced by
A suspicious escape sequence \s was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Bug introduced by
A suspicious escape sequence \e was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Bug introduced by
A suspicious escape sequence \l was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
2
3
Date: 2018
4
5
Author: Lucija Brezočnik
6
7
License: MIT
8
9
Function: Schwefel function
10
11
Input domain:
12
    The function can be defined on any input domain but it is usually
13
    evaluated on the hypercube x_i ∈ [-500, 500], for all i = 1, 2,..., D.
14
15
Global minimum:
16
    f(x*) = 0, at x* = (420.9687,...,420.9687)
17
18
LaTeX formats:
19
    Inline: $f(\textbf{x}) = 418.9829d - \sum_{i=1}^{D} x_i sin(\sqrt{|x_i|})$
20
    Equation: \begin{equation} f(\textbf{x}) =
21
              418.9829d - \sum_{i=1}^{D} x_i
22
              sin(\sqrt{|x_i|}) \end{equation}
23
    Domain: $-500 \leq x_i \leq 500$
24
25
Reference: https://www.sfu.ca/~ssurjano/schwef.html
26
"""
27
28
import math
29
30
__all__ = ['Schwefel']
31
32
33
class Schwefel(object):
34
35
    def __init__(self, Lower=-500, Upper=500):
36
        self.Lower = Lower
37
        self.Upper = Upper
38
39
    @classmethod
40
    def function(cls):
41
        def evaluate(D, sol):
42
43
            val = 0.0
44
            val1 = 0.0
45
46
            for i in range(D):
47
                val1 += (sol[i] * math.sin(math.sqrt(abs(sol[i]))))
48
49
            val = 418.9829 * D - val1
50
51
            return val
52
53
        return evaluate
54