Solves the given problem data instance. Parameters ---------- data Problem data instance to solve. stop Stopping criterion to use. seed Seed value to use for the random number stream. Default 0. collect_stats Whether to collect statistics
(
data: ProblemData,
stop: StoppingCriterion,
seed: int = 0,
collect_stats: bool = True,
display: bool = False,
params: SolveParams = SolveParams(),
initial_solution: Solution | None = None,
)
| 137 | |
| 138 | |
| 139 | def solve( |
| 140 | data: ProblemData, |
| 141 | stop: StoppingCriterion, |
| 142 | seed: int = 0, |
| 143 | collect_stats: bool = True, |
| 144 | display: bool = False, |
| 145 | params: SolveParams = SolveParams(), |
| 146 | initial_solution: Solution | None = None, |
| 147 | ) -> Result: |
| 148 | """ |
| 149 | Solves the given problem data instance. |
| 150 | |
| 151 | Parameters |
| 152 | ---------- |
| 153 | data |
| 154 | Problem data instance to solve. |
| 155 | stop |
| 156 | Stopping criterion to use. |
| 157 | seed |
| 158 | Seed value to use for the random number stream. Default 0. |
| 159 | collect_stats |
| 160 | Whether to collect statistics about the solver's progress. Default |
| 161 | ``True``. |
| 162 | display |
| 163 | Whether to display information about the solver progress. Default |
| 164 | ``False``. Progress information is only available when |
| 165 | ``collect_stats`` is also set, which it is by default. |
| 166 | params |
| 167 | Solver parameters to use. If not provided, a default will be used. |
| 168 | initial_solution |
| 169 | Optional solution to use as a warm start. The solver constructs a |
| 170 | (possibly poor) initial solution if this argument is not provided. |
| 171 | |
| 172 | Returns |
| 173 | ------- |
| 174 | Result |
| 175 | A Result object, containing statistics (if collected) and the best |
| 176 | found solution. |
| 177 | """ |
| 178 | rng = RandomNumberGenerator(seed=seed) |
| 179 | neighbours = compute_neighbours(data, params.neighbourhood) |
| 180 | perturbation = PerturbationManager(params.perturbation) |
| 181 | ls = LocalSearch(data, rng, neighbours, perturbation) |
| 182 | |
| 183 | for node_op in params.node_ops: |
| 184 | if node_op.supports(data): |
| 185 | ls.add_node_operator(node_op(data)) |
| 186 | |
| 187 | for route_op in params.route_ops: |
| 188 | if route_op.supports(data): |
| 189 | ls.add_route_operator(route_op(data)) |
| 190 | |
| 191 | pm = PenaltyManager.init_from(data, params.penalty) |
| 192 | |
| 193 | init = initial_solution |
| 194 | if init is None: |
| 195 | # Start from a random initial solution to ensure it's not completely |
| 196 | # empty (because starting from empty solutions can be a bit difficult). |