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

Rastrigin.__init__()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 3
rs 10
c 1
b 0
f 1
cc 1
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