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

Statistics about the search progress.

Collects data about solution costs and feasibility during optimization,
allowing analysis of the search trajectory.

## Example

    stats = ExVrp.Statistics.new()
    stats = ExVrp.Statistics.collect(stats, current, candidate, best, cost_evaluator)
    Enum.each(stats, fn datum -> IO.inspect(datum) end)

# `datum`

```elixir
@type datum() :: %{
  current_cost: integer(),
  current_feas: boolean(),
  candidate_cost: integer(),
  candidate_feas: boolean(),
  best_cost: integer(),
  best_feas: boolean()
}
```

# `t`

```elixir
@type t() :: %ExVrp.Statistics{
  clock: integer(),
  collect_stats: boolean(),
  data: [datum()],
  num_iterations: non_neg_integer(),
  runtimes: [float()]
}
```

# `collect`

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

Collects iteration statistics.

## Parameters

- `stats` - The Statistics object
- `current` - The current solution reference
- `candidate` - The candidate solution reference
- `best` - The best solution reference
- `cost_evaluator` - CostEvaluator reference used to compute costs

# `collecting?`

```elixir
@spec collecting?(t()) :: boolean()
```

Returns whether this Statistics object is collecting data.

# `from_csv`

```elixir
@spec from_csv(
  Path.t(),
  keyword()
) :: {:ok, t()} | {:error, term()}
```

Reads a Statistics object from a CSV file.

## Parameters

- `path` - File path to read from
- `opts` - Options (`:delimiter` defaults to `,`)

# `new`

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

Creates a new Statistics object.

## Options

- `:collect_stats` - Whether to collect statistics. Can be turned off to
  avoid excessive memory use on long runs. Defaults to `true`.

# `to_csv`

```elixir
@spec to_csv(t(), Path.t(), keyword()) :: :ok | {:error, term()}
```

Writes this Statistics object to a CSV file.

## Parameters

- `stats` - The Statistics object
- `path` - File path to write to
- `opts` - Options (`:delimiter` defaults to `,`)

---

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