Runs the iterated local search algorithm with the provided stopping criterion. The algorithm uses late acceptance hill-climbing as the acceptance criterion; see [1]_ for details. Parameters ---------- stop Stopping criterion to use. The a
(
self,
stop: StoppingCriterion,
collect_stats: bool = True,
display: bool = False,
display_interval: float = 5.0,
)
| 83 | self._params = params |
| 84 | |
| 85 | def run( |
| 86 | self, |
| 87 | stop: StoppingCriterion, |
| 88 | collect_stats: bool = True, |
| 89 | display: bool = False, |
| 90 | display_interval: float = 5.0, |
| 91 | ) -> Result: |
| 92 | """ |
| 93 | Runs the iterated local search algorithm with the provided stopping |
| 94 | criterion. The algorithm uses late acceptance hill-climbing as the |
| 95 | acceptance criterion; see [1]_ for details. |
| 96 | |
| 97 | Parameters |
| 98 | ---------- |
| 99 | stop |
| 100 | Stopping criterion to use. The algorithm runs until the first time |
| 101 | the stopping criterion returns ``True``. |
| 102 | collect_stats |
| 103 | Whether to collect statistics about the solver's progress. Default |
| 104 | ``True``. |
| 105 | display |
| 106 | Whether to display information about the solver progress. Default |
| 107 | ``False``. Progress information is only available when |
| 108 | ``collect_stats`` is also set. |
| 109 | display_interval |
| 110 | Time (in seconds) between iteration logs. Defaults to 5s. |
| 111 | |
| 112 | Returns |
| 113 | ------- |
| 114 | Result |
| 115 | A Result object, containing statistics (if collected) and the best |
| 116 | found solution. |
| 117 | |
| 118 | References |
| 119 | ---------- |
| 120 | .. [1] Burke, E.K., and Y. Bykov (2017). The Late Acceptance |
| 121 | Hill-Climbing Heuristic. *European Journal of Operational |
| 122 | Research*, 258(1): 70 - 78. |
| 123 | https://doi.org/10.1016/j.ejor.2016.07.012. |
| 124 | """ |
| 125 | print_progress = ProgressPrinter(display, display_interval) |
| 126 | print_progress.start(self._data) |
| 127 | |
| 128 | history: RingBuffer[Solution] = RingBuffer(self._params.history_length) |
| 129 | stats = Statistics(collect_stats=collect_stats) |
| 130 | |
| 131 | start = time.perf_counter() |
| 132 | iters = iters_no_improvement = 0 |
| 133 | best = curr = self._init |
| 134 | |
| 135 | cost_eval = self._pm.cost_evaluator() |
| 136 | while not stop(cost_eval.cost(best)): |
| 137 | iters += 1 |
| 138 | |
| 139 | if iters_no_improvement == self._params.num_iters_no_improvement: |
| 140 | print_progress.restart() |
| 141 | history.clear() |
| 142 |