Public Member Functions | Static Public Attributes | Private Attributes | Friends

# LinkStat Class Reference

Link statistics. More...

`#include <station_base.h>`

## Public Member Functions
| LinkStat ()
| We don't allow creating a link stat without a timeout/length.
| LinkStat (uint distance, uint capacity=1, uint usage=0)
| Create a link stat with at least a distance.
void | Clear ()
| Reset everything to 0.
void | Decrease ()
| Apply the moving averages to usage and capacity.
uint | Capacity () const
| Get an estimate of the current the capacity by calculating the moving average.
uint | Usage () const
| Get an estimage of the current usage by calculating the moving average.
void | Increase (uint capacity, uint usage)
| Add some capacity and usage.
void | Refresh (uint min_capacity)
| Reset the timeout and make sure there is at least a minimum capacity.
bool | IsValid () const
| Check if the timeout has hit.
## Static Public Attributes
static const uint | MIN_DISTANCE = 48
| Minimum distance for moving averages.
static const uint | MOVING_AVERAGE_LENGTH = 30
| Length of moving average in days.
## Private Attributes
uint | distance
| Manhattan distance between end points of the link.
uint | capacity
| Capacity of the link.
uint | timeout
| Time until the link is removed.
uint | usage
| Usage of the link.
## Friends
const SaveLoad * | GetLinkStatDesc ()
| Wrapper function to get the LinkStat's internal structure while some of the variables are private.

## Detailed Description

Link statistics.

They include figures for capacity and usage of a link. Both are moving averages which are increased for every vehicle arriving at the destination station and decreased by <current value>="">/(distance + 1) once a game day. The timeout is decreased by 1/49th once a game day. When a vehicle arrives it gets reset to the value of distance. When it reaches 0 the link is considered dead. As long as the link is not dead the capacity is kept at a minimum of 1. This is so that the death of a link is not dependent on its capacity but only on its distance. Otherwise some infrequently visited long distance links would be impossible to keep alive. Additionally while a vehicle is loading at the source station part of the capacity is frozen and prevented from being further decreased. This is done so that the link won't break down all the time when the typical "full load" order is used.

Definition at line 44 of file station_base.h.

## Constructor & Destructor Documentation

LinkStat::LinkStat | ( | uint | distance,
|  | uint | capacity = `1`,
|  | uint | usage = `0` |
| ) |  |  | `[inline]`

Create a link stat with at least a distance.

Parameters:

  | distance | Length for the moving average and link timeout.
  | capacity | Initial capacity of the link.
  | usage | Initial usage of the link.

Definition at line 85 of file station_base.h.

References capacity.

## Member Function Documentation

uint LinkStat::Capacity | ( |  | ) | const`[inline]`

Get an estimate of the current the capacity by calculating the moving average.

Returns:
  Capacity.

Definition at line 117 of file station_base.h.

References capacity, distance, and MOVING_AVERAGE_LENGTH.

Referenced by LinkGraphOverlay::AddStats().

void LinkStat::Increase | ( | uint | capacity,
|  | uint | usage |
| ) |  |  | `[inline]`

Add some capacity and usage.

Parameters:

  | capacity | Additional capacity.
  | usage | Additional usage.

Definition at line 136 of file station_base.h.

References distance, and timeout.

bool LinkStat::IsValid | ( |  | ) | const`[inline]`

Check if the timeout has hit.

Returns:
  If timeout is > 0.

Definition at line 157 of file station_base.h.

References timeout.

uint LinkStat::Usage | ( |  | ) | const`[inline]`

Get an estimage of the current usage by calculating the moving average.

Returns:
  Usage.

Definition at line 126 of file station_base.h.

References distance, MOVING_AVERAGE_LENGTH, and usage.

Referenced by LinkGraphOverlay::AddStats().

## Friends And Related Function Documentation

const SaveLoad* GetLinkStatDesc | ( |  | ) | `[friend]`

Wrapper function to get the LinkStat's internal structure while some of the variables are private.

Returns:
  Saveload description for LinkStat.

Definition at line 248 of file station_sl.cpp.

## Field Documentation

uint LinkStat::capacity`[private]`

Capacity of the link.

This is a moving average. Use Capacity() to get a meaningful value.

Definition at line 55 of file station_base.h.

Referenced by Capacity(), Clear(), Decrease(), LinkStat(), and Refresh().

uint LinkStat::timeout`[private]`

Time until the link is removed.

Decreases exponentially.

Definition at line 60 of file station_base.h.

Referenced by Clear(), Decrease(), Increase(), IsValid(), and Refresh().

uint LinkStat::usage`[private]`

Usage of the link.

This is a moving average. Use Usage() to get a meaningful value.

Definition at line 66 of file station_base.h.

Referenced by Clear(), Decrease(), and Usage().

The documentation for this class was generated from the following file:

- src/station_base.h