Collect iteration statistics. Parameters ---------- current The current solution. candidate The candidate solution. best The best solution. cost_evaluator CostEvaluator used to compute costs for
(
self,
current: Solution,
candidate: Solution,
best: Solution,
cost_evaluator: CostEvaluator,
)
| 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 |
| 82 | The best solution. |
| 83 | cost_evaluator |
| 84 | CostEvaluator used to compute costs for solutions. |
| 85 | """ |
| 86 | if not self._collect_stats: |
| 87 | return |
| 88 | |
| 89 | start = self._clock |
| 90 | self._clock = perf_counter() |
| 91 | |
| 92 | self.runtimes.append(self._clock - start) |
| 93 | self.num_iterations += 1 |
| 94 | |
| 95 | datum = _Datum( |
| 96 | cost_evaluator.penalised_cost(current), |
| 97 | current.is_feasible(), |
| 98 | cost_evaluator.penalised_cost(candidate), |
| 99 | candidate.is_feasible(), |
| 100 | cost_evaluator.penalised_cost(best), |
| 101 | best.is_feasible(), |
| 102 | ) |
| 103 | self.data.append(datum) |
| 104 | |
| 105 | @classmethod |
| 106 | def from_csv(cls, where: Path | str, delimiter: str = ",", **kwargs): |