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

Sphere   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

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