Passed
Push — master ( 13bf8e...cbe766 )
by
unknown
01:03
created

Griewank.__init__()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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