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

Griewank.function()   A

Complexity

Conditions 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 18
rs 9.4285
c 1
b 0
f 1
cc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A Griewank.evaluate() 0 14 2
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