MCPcopy Index your code
hub / github.com/PyVRP/PyVRP / solve

Function solve

pyvrp/solve.py:139–201  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

137
138
139def 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).

Callers 6

solveMethod · 0.90
_solveFunction · 0.90
minimise_fleetFunction · 0.90
test_solve_same_seedFunction · 0.90
test_solve_custom_paramsFunction · 0.90

Calls 11

add_node_operatorMethod · 0.95
add_route_operatorMethod · 0.95
runMethod · 0.95
compute_neighboursFunction · 0.90
PerturbationManagerClass · 0.90
LocalSearchClass · 0.90
IteratedLocalSearchClass · 0.90
SolveParamsClass · 0.85
init_fromMethod · 0.80
max_cost_evaluatorMethod · 0.80

Tested by 3

test_solve_same_seedFunction · 0.72
test_solve_custom_paramsFunction · 0.72