MLRsearch: Support other than just two ratios
[csit.git] / resources / libraries / python / MLRsearch / ProgressState.py
1 # Copyright (c) 2021 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 """Module defining ProgressState class."""
15
16
17 class ProgressState:
18     """Structure containing data to be passed around in recursion.
19
20     This is basically a private class of MultipleRatioSearch,
21     but keeping it in a separate file makes things more readable.
22     """
23
24     def __init__(
25             self, database, phases, duration, width_goal, packet_loss_ratios,
26             min_rate, max_rate, stop_time):
27         """Convert and store the argument values.
28
29         Also initializa the stored width for external search.
30
31         :param result: Structure containing measured results.
32         :param phases: How many intermediate phases to perform
33             before the current one.
34         :param duration: Trial duration to use in the current phase [s].
35         :param width_goal: The goal relative width for the curreent phase.
36         :param packet_loss_ratios: List of ratios for the current search.
37         :param min_rate: Minimal target transmit rate available
38             for the current search [tps].
39         :param max_rate: Maximal target transmit rate available
40             for the current search [tps].
41         :param stop_time: Monotonic time [s] when we should fail on timeout.
42         :type result: MeasurementDatabase
43         :type phases: int
44         :type duration: float
45         :type width_goal: float
46         :type packet_loss_ratios: Iterable[float]
47         :type min_rate: float
48         :type max_rate: float
49         :type stop_time: float
50         """
51         self.database = database
52         self.phases = int(phases)
53         self.duration = float(duration)
54         self.width_goal = float(width_goal)
55         self.packet_loss_ratios = [
56             float(ratio) for ratio in packet_loss_ratios
57         ]
58         self.min_rate = float(min_rate)
59         self.max_rate = float(max_rate)
60         self.stop_time = float(stop_time)