| Total Complexity | 4 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # Author: Simon Blanke |
||
| 2 | # Email: [email protected] |
||
| 3 | # License: MIT License |
||
| 4 | |||
| 5 | |||
| 6 | from . import HillClimbingOptimizer |
||
| 7 | |||
| 8 | |||
| 9 | class RepulsingHillClimbingOptimizer(HillClimbingOptimizer): |
||
| 10 | name = "Repulsing Hill Climbing" |
||
| 11 | _name_ = "repulsing_hill_climbing" |
||
| 12 | __name__ = "RepulsingHillClimbingOptimizer" |
||
| 13 | |||
| 14 | optimizer_type = "local" |
||
| 15 | computationally_expensive = False |
||
| 16 | |||
| 17 | def __init__( |
||
| 18 | self, |
||
| 19 | search_space, |
||
| 20 | initialize={"grid": 4, "random": 2, "vertices": 4}, |
||
| 21 | constraints=[], |
||
| 22 | random_state=None, |
||
| 23 | rand_rest_p=0, |
||
| 24 | nth_process=None, |
||
| 25 | epsilon=0.03, |
||
| 26 | distribution="normal", |
||
| 27 | n_neighbours=3, |
||
| 28 | repulsion_factor=5, |
||
| 29 | ): |
||
| 30 | super().__init__( |
||
| 31 | search_space=search_space, |
||
| 32 | initialize=initialize, |
||
| 33 | constraints=constraints, |
||
| 34 | random_state=random_state, |
||
| 35 | rand_rest_p=rand_rest_p, |
||
| 36 | nth_process=nth_process, |
||
| 37 | epsilon=epsilon, |
||
| 38 | distribution=distribution, |
||
| 39 | n_neighbours=n_neighbours, |
||
| 40 | ) |
||
| 41 | |||
| 42 | self.tabus = [] |
||
| 43 | self.repulsion_factor = repulsion_factor |
||
| 44 | self.epsilon_mod = 1 |
||
| 45 | |||
| 46 | @HillClimbingOptimizer.track_new_pos |
||
| 47 | def iterate(self): |
||
| 48 | return self.move_climb( |
||
| 49 | self.pos_current, |
||
| 50 | epsilon=self.epsilon, |
||
| 51 | distribution=self.distribution, |
||
| 52 | epsilon_mod=self.epsilon_mod, |
||
| 53 | ) |
||
| 54 | |||
| 55 | def evaluate(self, score_new): |
||
| 56 | super().evaluate(score_new) |
||
| 57 | |||
| 58 | if score_new <= self.score_current: |
||
| 59 | self.epsilon_mod = self.repulsion_factor |
||
| 60 | else: |
||
| 61 | self.epsilon_mod = 1 |
||
| 62 |