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

Rastrigin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

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

2 Methods

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