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

Load segments for tracking capacity during optimization.

Load segments track delivery and pickup loads, and can be efficiently
concatenated to track capacity violations resulting from visiting clients
in the concatenated order.

This is a core data structure used by the local search operators to
efficiently evaluate moves.

## Example

    ls1 = ExVrp.LoadSegment.new(10, 0, 10, 0)
    ls2 = ExVrp.LoadSegment.new(0, 5, 5, 0)
    merged = ExVrp.LoadSegment.merge(ls1, ls2)
    ExVrp.LoadSegment.excess_load(merged, 12)

# `t`

```elixir
@type t() :: reference()
```

# `delivery`

```elixir
@spec delivery(t()) :: integer()
```

Returns the delivery amount, that is, the total amount of load delivered
to clients on this segment.

# `excess_load`

```elixir
@spec excess_load(t(), integer()) :: integer()
```

Returns the load violation on this segment.

## Parameters

- `segment` - The load segment
- `capacity` - Segment capacity

# `finalise`

```elixir
@spec finalise(t(), integer()) :: t()
```

Finalises the load on this segment.

Returns a new segment where any excess load has been moved to the
cumulative excess load field. This is useful with reloading, because
the finalised segment can be concatenated with load segments of
subsequent trips.

## Parameters

- `segment` - The load segment to finalise
- `capacity` - The capacity constraint

# `load`

```elixir
@spec load(t()) :: integer()
```

Returns the maximum load encountered on this segment.

# `merge`

```elixir
@spec merge(t(), t()) :: t()
```

Merges two load segments.

## Parameters

- `first` - First load segment
- `second` - Second load segment

## Returns

A new merged load segment.

# `new`

```elixir
@spec new(integer(), integer(), integer(), integer()) :: t()
```

Creates a new load segment.

## Parameters

- `delivery` - Total delivery amount on this segment
- `pickup` - Total pickup amount on this segment
- `load` - Maximum load on this segment
- `excess_load` - Cumulative excess load on this segment (default 0)

# `pickup`

```elixir
@spec pickup(t()) :: integer()
```

Returns the amount picked up from clients on this segment.

---

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