Passed
Push — master ( c5e615...300275 )
by Simon
01:59 queued 13s
created

gradient_free_optimizers.optimizers.local.tabu_search   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A TabuOptimizer.__init__() 0 6 1
A TabuOptimizer.evaluate() 0 7 2
A TabuOptimizer.iterate() 0 3 1
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
class TabuOptimizer(HillClimbingOptimizer, Search):
15
    def __init__(self, search_space, tabu_factor=3):
16
        super().__init__(search_space)
17
18
        self.tabus = []
19
        self.tabu_factor = tabu_factor
20
        self.epsilon_mod = 1
21
22
    @HillClimbingOptimizer.iter_dec
23
    def iterate(self):
24
        return self._move_climb(self.pos_current)
25
26
    def evaluate(self, score_new):
27
        super().evaluate(score_new)
28
29
        if score_new <= self.score_current:
30
            self.epsilon_mod = self.tabu_factor
31
        else:
32
            self.epsilon_mod = 1
33
34