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

Rastrigin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 3 1
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
    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
            val = 0.0
17
18
            for i in range(D):
19
                val = val + \
20
                    math.pow(sol[i], 2) - 10 * math.cos(
21
                        2 * math.pi * sol[i]) + 10
22
23
            return val
24
25
        return evaluate
26