ExVrp.PenaltyManager (ExVrp v0.4.2)

Copy Markdown View Source

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.

Summary

Functions

Creates a CostEvaluator using the current penalty values.

Creates a PenaltyManager with initial penalties computed from problem data.

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

Creates a new PenaltyManager with explicit initial penalties.

Returns the current penalties as a tuple.

Registers a solution and updates penalties if needed.

Types

t()

@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()
}

Functions

cost_evaluator(pm)

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

Creates a CostEvaluator using the current penalty values.

init_from(problem_data, params \\ %Params{})

@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(pm)

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

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

new(load_penalties, tw_penalty, dist_penalty, params \\ %Params{})

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

Creates a new PenaltyManager with explicit initial penalties.

penalties(pm)

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

Returns the current penalties as a tuple.

register(pm, solution_ref)

@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.