BaseOptimizer.evaluate()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
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 .core_optimizer import CoreOptimizer
7
8
9
class BaseOptimizer(CoreOptimizer):
10
    def __init__(
11
        self,
12
        search_space,
13
        initialize={"grid": 4, "random": 2, "vertices": 4},
14
        constraints=[],
15
        random_state=None,
16
        rand_rest_p=0,
17
        nth_process=None,
18
    ):
19
        super().__init__(
20
            search_space=search_space,
21
            initialize=initialize,
22
            constraints=constraints,
23
            random_state=random_state,
24
            rand_rest_p=rand_rest_p,
25
            nth_process=nth_process,
26
        )
27
28
        self.optimizers = [self]
29
30
    def finish_initialization(self):
31
        self.search_state = "iter"
32
33
    def evaluate(self, score_new):
34
        if self.pos_best is None:
35
            self.pos_best = self.pos_new
36
            self.pos_current = self.pos_new
37
38
            self.score_best = score_new
39
            self.score_current = score_new
40