Statistics about the search progress. Parameters ---------- collect_stats Whether to collect statistics at all. This can be turned off to avoid excessive memory use on long runs.
| 22 | |
| 23 | |
| 24 | class Statistics: |
| 25 | """ |
| 26 | Statistics about the search progress. |
| 27 | |
| 28 | Parameters |
| 29 | ---------- |
| 30 | collect_stats |
| 31 | Whether to collect statistics at all. This can be turned off to avoid |
| 32 | excessive memory use on long runs. |
| 33 | """ |
| 34 | |
| 35 | runtimes: list[float] |
| 36 | num_iterations: int |
| 37 | data: list[_Datum] |
| 38 | |
| 39 | def __init__(self, collect_stats: bool = True): |
| 40 | self.runtimes = [] |
| 41 | self.num_iterations = 0 |
| 42 | self.data = [] |
| 43 | |
| 44 | self._clock = perf_counter() |
| 45 | self._collect_stats = collect_stats |
| 46 | |
| 47 | def __eq__(self, other: object) -> bool: |
| 48 | return ( |
| 49 | isinstance(other, Statistics) |
| 50 | and self._collect_stats == other._collect_stats |
| 51 | and self.runtimes == other.runtimes |
| 52 | and self.num_iterations == other.num_iterations |
| 53 | and self.data == other.data |
| 54 | ) |
| 55 | |
| 56 | def __iter__(self) -> Iterator[_Datum]: |
| 57 | """ |
| 58 | Iterates over the collected data points. |
| 59 | """ |
| 60 | yield from self.data |
| 61 | |
| 62 | def is_collecting(self) -> bool: |
| 63 | return self._collect_stats |
| 64 | |
| 65 | def collect( |
| 66 | self, |
| 67 | current: Solution, |
| 68 | candidate: Solution, |
| 69 | best: Solution, |
| 70 | cost_evaluator: CostEvaluator, |
| 71 | ): |
| 72 | """ |
| 73 | Collect iteration statistics. |
| 74 | |
| 75 | Parameters |
| 76 | ---------- |
| 77 | current |
| 78 | The current solution. |
| 79 | candidate |
| 80 | The candidate solution. |
| 81 | best |
no outgoing calls