| Total Complexity | 4 |
| Total Lines | 30 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 2 | Features | 0 |
| 1 | """Implementation of Ackley function.""" |
||
| 7 | class Ackley(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 | a = 20 # Recommended variable value |
||
| 18 | b = 0.2 # Recommended variable value |
||
| 19 | c = 2 * math.pi # Recommended variable value |
||
| 20 | |||
| 21 | val = 0.0 |
||
| 22 | val1 = 0.0 |
||
| 23 | val2 = 0.0 |
||
| 24 | |||
| 25 | for i in range(D): |
||
| 26 | val1 += math.pow(sol[i], 2) |
||
| 27 | val2 += math.cos(c * sol[i]) |
||
| 28 | |||
| 29 | temp1 = -b * math.sqrt(val1 / D) |
||
| 30 | temp2 = val2 / D |
||
| 31 | |||
| 32 | val = -a * math.exp(temp1) - math.exp(temp2) + a + math.exp(1) |
||
| 33 | |||
| 34 | return val |
||
| 35 | |||
| 36 | return evaluate |
||
| 37 |