# `ExVrp.PerturbationManager`
[🔗](https://github.com/sephianl/ex_vrp/blob/v0.4.2/lib/ex_vrp/perturbation_manager.ex#L1)

Manages perturbation during local search.

In each iteration, it applies a random number of perturbations that
strengthen or weaken randomly selected neighbourhoods by inserting
or removing clients.

## Example

    pm = ExVrp.PerturbationManager.new(min: 1, max: 25)
    assert pm.min_perturbations == 1
    assert pm.max_perturbations == 25

    # Initially set to min_perturbations
    assert ExVrp.PerturbationManager.num_perturbations(pm) == 1

    # Shuffle to pick a new random number
    rng = ExVrp.RNG.new(42)
    pm = ExVrp.PerturbationManager.shuffle(pm, rng)
    num = ExVrp.PerturbationManager.num_perturbations(pm)
    assert num >= 1 and num <= 25

# `t`

```elixir
@type t() :: %ExVrp.PerturbationManager{
  max_perturbations: non_neg_integer(),
  min_perturbations: non_neg_integer(),
  ref: reference()
}
```

# `new`

```elixir
@spec new(keyword()) :: t()
```

Creates a new PerturbationManager.

## Options

- `:min` - Minimum number of perturbations (default: 1)
- `:max` - Maximum number of perturbations (default: 25)

## Examples

    iex> pm = ExVrp.PerturbationManager.new()
    iex> pm.min_perturbations
    1
    iex> pm.max_perturbations
    25

    iex> pm = ExVrp.PerturbationManager.new(min: 5, max: 10)
    iex> pm.min_perturbations
    5

# `num_perturbations`

```elixir
@spec num_perturbations(t()) :: non_neg_integer()
```

Returns the current number of perturbations to apply.

Initially this is set to `min_perturbations`. Call `shuffle/2` to
pick a new random value within the [min, max] range.

# `shuffle`

```elixir
@spec shuffle(t(), reference()) :: t()
```

Shuffles to pick a new random number of perturbations.

The new value is drawn uniformly from [min_perturbations, max_perturbations].

## Example

    pm = ExVrp.PerturbationManager.new(min: 1, max: 10)
    rng = ExVrp.RNG.new(42)
    pm = ExVrp.PerturbationManager.shuffle(pm, rng)
    num = ExVrp.PerturbationManager.num_perturbations(pm)
    assert num >= 1 and num <= 10

---

*Consult [api-reference.md](api-reference.md) for complete listing*
