Passed
Pull Request — master (#32)
by
unknown
01:05
created

Sphere.__init__()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 1
c 4
b 0
f 0
dl 0
loc 3
rs 10
1
"""Implementation of Sphere functions.
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
Authors: Iztok Fister Jr.
6
7
License: MIT
8
9
Function: Sphere 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 ∈ [0, 10], for all i = 1, 2,..., D.
14
15
Global minimum:
16
    f(x*) = 0, at x* = (0,...,0)
17
18
LaTeX formats:
19
    Inline: $f(x) = \sum_{i=1}^D x_i^2$
20
    Equation: \begin{equation}f(x) = \sum_{i=1}^D x_i^2 \end{equation}
21
    Domain: $0 \leq x_i \leq 10$
22
23
Reference paper:
24
    Jamil, M., and Yang, X. S. (2013).
25
    A literature survey of benchmark functions for global optimisation problems.
26
    International Journal of Mathematical Modelling and Numerical Optimisation,
27
    4(2), 150-194.
28
"""
29
30
import math
31
32
__all__ = ['Sphere']
33
34
35
class Sphere(object):
36
    def __init__(self, Lower=-5.12, Upper=5.12):
37
        self.Lower = Lower
38
        self.Upper = Upper
39
40
    @classmethod
41
    def function(cls):
42
        def evaluate(D, sol):
43
            val = 0.0
44
            for i in range(D):
45
                val += math.pow(sol[i], 2)
46
            return val
47
48
        return evaluate
49