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

Rastrigin.evaluate()   A

Complexity

Conditions 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
dl 0
loc 9
rs 9.6666
c 2
b 0
f 2
cc 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