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

Griewank   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 24
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A evaluate() 0 14 2
A function() 0 18 3
A __init__() 0 3 1
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