1
|
|
|
"""Module which contains CumulatedCallsStage""" |
2
|
1 |
|
from grortir.main.model.stages.calls_stage import CallsStage |
3
|
|
|
|
4
|
|
|
|
5
|
1 |
|
class CumulatedCallsStage(CallsStage): |
6
|
|
|
"""In this class last coordinate of input vector is value which will |
7
|
|
|
be added to quality. Other mechanism is the same as in parent class. |
8
|
|
|
Simply in process we will put as last coordinate in output current quality |
9
|
|
|
and add this value to quality in children steps.""" |
10
|
|
|
|
11
|
1 |
|
def __init__(self, name, max_calls, input_vector=(), |
12
|
|
|
maximum_acceptable_quality=0.01): |
13
|
1 |
|
super().__init__(name, max_calls, input_vector, |
14
|
|
|
maximum_acceptable_quality) |
15
|
1 |
|
self.control_params = [0] * (len(self.input_vector) - 1) |
16
|
1 |
|
dimensions = len(self.control_params) |
17
|
1 |
|
self.lower_bounds = [-1] * dimensions |
18
|
1 |
|
self.upper_bounds = [1] * dimensions |
19
|
|
|
|
20
|
1 |
|
@staticmethod |
21
|
|
|
def calculate_quality(input_vector, control_params): |
22
|
|
|
"""Override Calls Stage method - here last coordinate of input is |
23
|
|
|
simply added to value calculated by remaining coordinates.""" |
24
|
1 |
|
assert len(input_vector) - 1 == len(control_params) |
25
|
1 |
|
return CallsStage.calculate_quality(input_vector[: -1], control_params) |
26
|
|
|
|
27
|
1 |
|
def get_output_of_stage(self, input_vector, control_params): |
28
|
|
|
"""We return here control params (as in CallsStage) and additionally |
29
|
|
|
in the last coordinate we put current quality.""" |
30
|
1 |
|
current_quality = self.calculate_quality(input_vector, control_params) |
31
|
1 |
|
function_output = CallsStage.get_output_of_stage(self, |
32
|
|
|
input_vector[:-1], |
33
|
|
|
control_params) |
34
|
|
|
return function_output + [current_quality] |
35
|
|
|
|