Computes granular neighbourhood for local search.
Uses Nx for efficient tensor operations, directly porting PyVRP's compute_neighbours algorithm from pyvrp/search/neighbourhood.py.
Example
# Get neighbours for a problem
{:ok, problem_data} = ExVrp.Native.create_problem_data(model)
params = ExVrp.NeighbourhoodParams.new(num_neighbours: 40)
neighbours = ExVrp.Neighbourhood.compute_neighbours(problem_data, params)
# neighbours is a list of lists:
# - neighbours[0..num_depots-1] are empty (depots have no neighbours)
# - neighbours[i] for clients contains the k nearest client indices
Summary
Functions
Computes neighbours for each location.
Functions
@spec compute_neighbours(reference(), ExVrp.NeighbourhoodParams.t()) :: [[integer()]]
Computes neighbours for each location.
Returns list of lists: neighbours[location] = [neighbour_indices...] Depots get empty lists.
Parameters
problem_data- Reference to ProblemData resourceparams- NeighbourhoodParams configuration
Returns
A list of lists where:
- The first
num_depotsentries are empty lists - Each client entry contains the indices of its k nearest neighbours