Total Complexity | 4 |
Total Lines | 39 |
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 | def __init__( |
||
12 | self, |
||
13 | search_space, |
||
14 | epsilon=0.03, |
||
15 | distribution="normal", |
||
16 | n_neighbours=3, |
||
17 | repulsion_factor=5, |
||
18 | rand_rest_p=0.03, |
||
19 | ): |
||
20 | super().__init__(search_space, epsilon, distribution, n_neighbours) |
||
21 | |||
22 | self.tabus = [] |
||
23 | self.repulsion_factor = repulsion_factor |
||
24 | self.rand_rest_p = rand_rest_p |
||
25 | self.epsilon_mod = 1 |
||
26 | |||
27 | @HillClimbingOptimizer.track_nth_iter |
||
28 | @HillClimbingOptimizer.random_restart |
||
29 | def iterate(self): |
||
30 | return self._move_climb(self.pos_current, epsilon_mod=self.epsilon_mod) |
||
31 | |||
32 | def evaluate(self, score_new): |
||
33 | super().evaluate(score_new) |
||
34 | |||
35 | if score_new <= self.score_current: |
||
36 | self.epsilon_mod = self.repulsion_factor |
||
37 | else: |
||
38 | self.epsilon_mod = 1 |
||
39 | |||
40 |