Completed
Pull Request — master (#21)
by Grega
01:03
created

Griewank.__init__()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
1
"""Implementation of Griewank function."""
2
import math
3
4
__all__ = ['Griewank']
5
6
7
class Griewank(object):
8
9
    def __init__(self, Lower=-100, Upper=100):
10
        self.Lower = Lower
11
        self.Upper = Upper
12
13
    @classmethod
14
    def function(cls):
15
        def evaluate(D, sol):
16
17
            val = 0.0
18
            val1 = 0.0
19
            val2 = 1.0
20
21
            for i in range(D):
22
                val1 = val1 + math.pow(sol[i], 2)
23
                val2 = val2 + \
24
                    math.cos((((sol[i]) / math.sqrt(i + 1)) * math.pi) / 180)
25
26
            val = (1 / 4000) * val1 - val2 + 1
27
28
            return val
29
30
        return evaluate
31