Total Complexity | 6 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Coverage | 100% |
1 | """Module contains class CallsStage.""" |
||
5 | 1 | class CallsStage(AbstractStage): |
|
6 | """Implementation of basic stage. |
||
7 | |||
8 | Cost is calculated by number of calls of cost function. |
||
9 | """ |
||
10 | |||
11 | 1 | def __init__(self, input_vector=()): |
|
12 | """Constructor.""" |
||
13 | 1 | super().__init__(input_vector) |
|
14 | 1 | self.control_params = [0] * len(self.input_vector) |
|
15 | 1 | self.cost = 0 |
|
16 | |||
17 | 1 | def get_quality(self): |
|
|
|||
18 | """ |
||
19 | Return quality of actual output. |
||
20 | |||
21 | :return: quality |
||
22 | """ |
||
23 | 1 | self.cost += 1 |
|
24 | 1 | return self.calculate_quality() |
|
25 | |||
26 | 1 | def calculate_quality(self): |
|
27 | """ |
||
28 | Function for calculating quality. |
||
29 | |||
30 | :return: |
||
31 | """ |
||
32 | 1 | assert len(self.control_params) == len(self.current_vector) |
|
33 | 1 | quality = 0 |
|
34 | 1 | for i in enumerate(self.control_params): |
|
35 | 1 | quality += (self.control_params[i[0]] - self.current_vector[ |
|
36 | i[0]]) ** 2 |
||
37 | 1 | return quality |
|
38 | |||
39 | 1 | def get_cost(self): |
|
40 | """ |
||
41 | Return actual cost of stage. |
||
42 | |||
43 | :return: cost |
||
44 | """ |
||
45 | return self.cost |
||
46 |