# Variable Neighborhood Search

Confidence: Not an expert, but I've read a bunch of papers and written an implementation. I assume a passing familiarity with terminology around gradient descent.

There are some old notes I've cleaned up a little and copied here in preparation for maybe writing a longer article.

Variable Neighborhood Search (VNS) is an approximation algorithm based on three observations.

- A local minimum with respect to one neighborhood structure is not necessarily so for another.
- A global minimum is a local minimum with respect to all possible neighborhood structures.
- For many problems, local minima with respect to one or several neighborhoods are relatively close to each other.

A "neighborhood" is simply a function that takes in the state and returns a modified version of that state.

# Initalization Choices π

- /f/ - the scoring function
- X - The set of possibilities
- N(x) - the neighborhood structure
- x - the initial solution

# Algorithms π

The overall algorithm is made up of a few different subalgorithms, which combine to create a few different variations on the technique.

## Variable Neighborhood Descent (VND) π

A standard way to search through a space is the steepest descent heuristic. This is most well-known from training neural nets though the technique predates it.

The steps for basic Steepest Descent are:

- Given an existing state x of the data, find xβ = the smallest value of f(x) for all perturbations in N(x).
- If f(xβ) < f(x), set x = xβ and repeat step 1. Otherwise stop.

Since it may not be feasible to iterate over every possible neighborhood perturbation in every iteration, an alternative is to stop after you find the first perturbation that results in a score reduction.

VND is based on fact 1. Since a local optimum for one type of move may not be a local optimum for another type of move, we can combine descent heuristics to get closer to the global optimum.

### Steps for VND π

- Initialize: Choose set of neighborhoods that will be used and find the initial solution x.
- Start with the first neighborhood.
*Local Search*: Find the best neighbor xβ of x using the steepest descent method with the current neighborhood.- If xβ is better than x, then x' becomes the new value of x, and go back to step 1. Otherwise go to the next neighborhood and go to step 2.

This brings up a number of questions.

- What is the complexity of the different neighborhoods? β Moves that take too many operations may be very slow to converge and actually require more time than the exact solution in some cases.
- What is the best order to apply them? β Often moves are ordered by the complexity of their application. Some variants apply all the moves at once, so long as descent is made for some neighborhood in the series.
- Are these moves sufficient to throughly explore the region? β Too-simple moves may not leave a βnarrow valleyβ
- How precise a solution do we need?

As an example of VND for placing facilities in a region, we might have two neighborhood structures. The first does a greedy search for placing a new facility and the other does an interchange, moving an existing facility elsewhere. These two would be applied in turn until the algorithm halts.

## Reduced Variable Neighborhood Search π

Assume weβve found a local minimum. We want to leave this valley and find a deeper one, if it exists.

### Motivations π

- Which direction to go? β Simplest answer is to choose randomly
- How far? β Since local minima tend to be close together, we should start with small steps.
- If the moves donβt get us out of the valley, how do we modify them? β Go farther! Usually this takes the form of each of the neighborhood structures building upon the previous one to create a larger or more complex move (this is called nesting).

### Steps π

- Init: Select a set of neighborhood structures, find initial solution, choose stopping condition, etc.
- Select neighborhood 1
*Shaking*: Take a randomly selected change from the current neighborhood.- If itβs better, use it and go back to step 1
- Otherwise, check the stopping condition, and then go to the next structure and go to step 2.

## Basic Variable Neighborhood Search π

This combines the VND and RVNS methods above into a single method so that we have systematic movement around the current local minimum and also the possibility of a random jump into a better minimum.

- Init: Select neighborhoods N (1 to kmax), initial solution x, stopping condition.
- Set k = 1
- Shaking: xβ = a random move in Nk.
- Local Search: xββ = the result of the local search from xβ
- If xββ is better than x, set x = xββ and jump to step 1.
- Otherwise increment k. If k = kmax, check the stopping condition and jump back to step 1.

## General Variable Neighborhood Search π

This is the general one to use when you donβt have a specific reason to do otherwise. It is similar to the basic VNS, but uses VND as the local search step. We may use different neighborhood selections for the shaking step and the VND step, but it is not required.

### Neighborhood Selection π

- What properties of the neighborhoods are mandatory to be able to find a near-optimal solution β The union of all the neighborhoods should cover the entire set of feasible solutions to guarantee this.
- What properties are helpful for finding a near-optimal solution?
- Should neighborhoods be nested, and if not, how should they be ordered? β Nesting can easily be done by performing a type of move, and then having the next neighborhood make a similar move
- What are desirable properties of neighborhood size? β Size should go up as we iterate through neighborhoods.

## Skewed VNS π

- Some problems have local minima that are spaced far apart, and so if we happen to jump into one we probably want to explore around there.
- With an extremely large neighborhood, we might jump into one of these other minima, and so it can be desirable to try out a not-quite-the-best solution if itβs sufficiently far away from the current best solution.
- In this method, after we move we check if the candidate solution is better than or worse-but-within-a-tolerance of the best solution, and if it is then we move the search space to it.
- Throughout the process, we remember the best solution even if weβre not currently looking at it.
- Should we do this? β The easiest way to answer the question is to run VNS for a short period of time from a bunch of different starting conditions and see if they end up in very different states with good solutions.

## Variable Neighborhood Decomposition Search π

This scheme changes the local search option to select a subset of the space relating to the space modified by the neighborhood and optimize just that region. The optimization process used can be VNS again, applied to just that region.

# Further Research for Approaching a Problem with VNS π

- Initialization Conditions β VNS results tend to not be too dependent on the initialization conditions, so long as the neighborhoods are defined well, and so simpler conditions are better.
- Neighborhood Selection β Do research on the neighborhoods used by other approaches to the problem. They tend to be reusable in VNS.
- Distribution of Neighborhoods β Should neighborhoods be assigned to the local search phase, the shaking phase, or both?
- Ancillary Tests β Some additional logic can be used to make the βrandomβ selection less random, if we know some useful things about the problem that can help with selection.

Thanks for reading! If you have any questions or comments, please send me a note on Twitter.