Passed
Push — master ( 626f23...be3b1e )
by Simon
01:48
created

RepulsingHillClimbingOptimizer.evaluate()   A

Complexity

Conditions 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 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