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

Manages and dynamically adjusts penalty weights for constraint violations.

This is a direct port of PyVRP's PenaltyManager. It tracks the feasibility
of registered solutions and adjusts penalties to target a specific feasibility
rate (default 65%). This balances exploration between feasible and infeasible
solution space.

# `t`

```elixir
@type t() :: %ExVrp.PenaltyManager{
  dist_feas: [boolean()],
  dist_penalty: float(),
  load_feas: [[boolean()]],
  load_penalties: [float()],
  params: ExVrp.PenaltyManager.Params.t(),
  tw_feas: [boolean()],
  tw_penalty: float()
}
```

# `cost_evaluator`

```elixir
@spec cost_evaluator(t()) :: {:ok, reference()} | {:error, term()}
```

Creates a CostEvaluator using the current penalty values.

# `init_from`

```elixir
@spec init_from(reference(), ExVrp.PenaltyManager.Params.t()) :: t()
```

Creates a PenaltyManager with initial penalties computed from problem data.

This mirrors PyVRP's `PenaltyManager.init_from()` - it computes reasonable
initial penalty values based on the problem's cost structure.

# `max_cost_evaluator`

```elixir
@spec max_cost_evaluator(t()) :: {:ok, reference()} | {:error, term()}
```

Creates a CostEvaluator using maximum penalty values.
Used for final solution evaluation.

# `new`

```elixir
@spec new([float()], float(), float(), ExVrp.PenaltyManager.Params.t()) :: t()
```

Creates a new PenaltyManager with explicit initial penalties.

# `penalties`

```elixir
@spec penalties(t()) :: {[float()], float(), float()}
```

Returns the current penalties as a tuple.

# `register`

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

Registers a solution and updates penalties if needed.

Tracks the feasibility of the solution across load, time window, and distance
dimensions. After `solutions_between_updates` registrations, penalties are
adjusted to target the configured feasibility rate.

---

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