| Total Complexity | 5 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # Author: Simon Blanke |
||
| 2 | # Email: [email protected] |
||
| 3 | # License: MIT License |
||
| 4 | |||
| 5 | import random |
||
| 6 | import numpy as np |
||
| 7 | |||
| 8 | |||
| 9 | from . import HillClimbingOptimizer |
||
| 10 | from ...search import Search |
||
| 11 | from scipy.spatial.distance import euclidean |
||
| 12 | |||
| 13 | |||
| 14 | def gaussian(distance, sig, sigma_factor=1): |
||
| 15 | return ( |
||
| 16 | sigma_factor |
||
| 17 | * sig |
||
| 18 | * np.exp(-np.power(distance, 2.0) / (sigma_factor * np.power(sig, 2.0))) |
||
| 19 | ) |
||
| 20 | |||
| 21 | |||
| 22 | class TabuOptimizer(HillClimbingOptimizer, Search): |
||
| 23 | def __init__(self, search_space, tabu_factor=3): |
||
| 24 | super().__init__(search_space) |
||
| 25 | |||
| 26 | self.tabus = [] |
||
| 27 | self.tabu_factor = tabu_factor |
||
| 28 | self.epsilon_mod = 1 |
||
| 29 | |||
| 30 | def iterate(self): |
||
| 31 | return self._move_climb(self.pos_current) |
||
| 32 | |||
| 33 | def evaluate(self, score_new): |
||
| 34 | super().evaluate(score_new) |
||
| 35 | |||
| 36 | if score_new <= self.score_current: |
||
| 37 | self.epsilon_mod = self.tabu_factor |
||
| 38 | else: |
||
| 39 | self.epsilon_mod = 1 |
||
| 40 |