| Total Complexity | 4 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # Author: Simon Blanke |
||
| 2 | # Email: [email protected] |
||
| 3 | # License: MIT License |
||
| 4 | |||
| 5 | |||
| 6 | from . import HillClimbingOptimizer |
||
| 7 | from ...search import Search |
||
| 8 | |||
| 9 | |||
| 10 | class RepulsingHillClimbingOptimizer(HillClimbingOptimizer, Search): |
||
| 11 | name = "Repulsing Hill Climbing" |
||
| 12 | |||
| 13 | def __init__( |
||
| 14 | self, |
||
| 15 | *args, |
||
| 16 | repulsion_factor=5, |
||
| 17 | **kwargs, |
||
| 18 | ): |
||
| 19 | super().__init__(*args, **kwargs) |
||
| 20 | |||
| 21 | self.tabus = [] |
||
| 22 | self.repulsion_factor = repulsion_factor |
||
| 23 | self.epsilon_mod = 1 |
||
| 24 | |||
| 25 | @HillClimbingOptimizer.track_nth_iter |
||
| 26 | @HillClimbingOptimizer.random_restart |
||
| 27 | def iterate(self): |
||
| 28 | return self._move_climb(self.pos_current, epsilon_mod=self.epsilon_mod) |
||
| 29 | |||
| 30 | def evaluate(self, score_new): |
||
| 31 | super().evaluate(score_new) |
||
| 32 | |||
| 33 | if score_new <= self.score_current: |
||
| 34 | self.epsilon_mod = self.repulsion_factor |
||
| 35 | else: |
||
| 36 | self.epsilon_mod = 1 |
||
| 37 |