Skip to content

Variable Neighborhood Search (VNS)

A local search for combinatorial problems such as tours and assignments. It leaves a local optimum by jumping to farther and farther neighbors.

VNS

VNS(*, variant='basic', k_max=5, shaking='distinct', improvement='first', batch=10, step_min=1e-08, **kwargs)

Variable neighborhood search (Mladenović and Hansen 1997, Hansen and Mladenović 2003).

Each iteration shakes the current solution with k random moves of the basic move kind (the first kind of each variable) and improves the result with a local search. If the result is better, it becomes the current solution and k goes back to 1. Otherwise k grows by 1, and after k_max it starts again at 1. With shaking="distinct" the k moves change different elements (items, positions or components), so the shaken solution is k moves away.

Variants:

  • "basic" (default): the local search is hill climbing over all move kinds.
  • "general": the local search is variable neighborhood descent (VND). It tries the move kinds in order (moves sets the order, the default for permutations is swap, insertion, inversion) and goes back to the first kind after every improvement.
  • "reduced": no local search, only shaking.

The local search runs to a local optimum, with first or best improvement (improvement). With Real variables it then halves the step, down to step_min.

Parameters

  • variant: "basic" (default), "general" or "reduced"
  • k_max: largest number of shaking moves: an int (default 5) or "size" (the number of elements, items or components)
  • shaking: "distinct" (default) or "random" (k moves that may repeat elements)
  • improvement: "first" (default) or "best" improvement in the local search
  • batch: neighbors evaluated together with first improvement (default 10, see HillClimbing)
  • candidate_size, moves, real_moves, step, step_min: as in HillClimbing (default 1000, all kinds, "coordinate", 0.1, 1e-8)

References: N. Mladenović and P. Hansen, "Variable neighborhood search", Computers and Operations Research 24(11), 1997, 1097 to 1100. P. Hansen and N. Mladenović, "Variable neighborhood search", in Handbook of Metaheuristics, 2003, 145 to 184. P. Hansen and N. Mladenović, "Variable neighborhood search: principles and applications", European Journal of Operational Research 130, 2001, 449 to 467.

The moves of each variable type are listed in Neighborhoods.

Example

import ypea

problem = ypea.problems.random_tsp(50, seed=2)

alg = ypea.VNS(max_nfe=50_000)
result = alg.solve(problem, seed=1)
print(result.summary())
VNS on random_tsp50
  best objective value: 594.037
  feasible: True (violation 0)
  evaluations: 50000, iterations: 9, time: 2.52 s, stopped by: max_nfe

Differs from Python: MATLAB draws its own cities and random numbers, so the tour length differs from Python's.

problem = ypea.problems.random_tsp(50, seed=2);

alg = ypea.VNS(max_nfe=50000);
result = alg.solve(problem, seed=1);
disp(result.summary())
VNS on random_tsp50
  best objective value: 570.198
  feasible: true (violation 0)
  evaluations: 50000, iterations: 10, time: 15.7 s, stopped by: max_nfe