Passed
Push — master ( 90fac4...b39ade )
by Grega
51s
created

Griewank   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A evaluate() 0 14 2
A function() 0 18 3
1
"""Implementation of Griewank function."""
2
import math
3
4
__all__ = ['Griewank']
5
6
7
class Griewank(object):
8
9
    @classmethod
10
    def function(cls):
11
        def evaluate(D, sol):
12
13
            val = 0.0
14
            val1 = 0.0
15
            val2 = 1.0
16
17
            for i in range(D):
18
                val1 = val1 + math.pow(sol[i], 2)
19
                val2 = val2 + \
20
                    math.cos((((sol[i]) / math.sqrt(i + 1)) * math.pi) / 180)
21
22
            val = (1 / 4000) * val1 - val2 + 1
23
24
            return val
25
26
        return evaluate
27