Public Member Functions | Protected Attributes | Private Types

# LinkGraphComponent Class Reference

A connected component of a link graph. More...

`#include <linkgraph.h>`

Inheritance diagram for LinkGraphComponent:

## Public Member Functions
| LinkGraphComponent ()
| Create an empty component.
void | Init (LinkGraphComponentID id)
| (Re-)initialize this component with a new ID and a new copy of the settings.
Edge & | GetEdge (NodeID from, NodeID to)
| Get a reference to an edge.
Node & | GetNode (NodeID num)
| Get a reference to a node with the specified id.
uint | GetSize () const
| Get the current size of the component.
void | SetSize ()
| Resize the component and fill it with empty nodes and edges.
NodeID | AddNode (Station *st)
| Add a node to the component and create empty edges associated with it.
void | AddEdge (NodeID from, NodeID to, uint capacity)
| Fill an edge with values from a link.
LinkGraphComponentID | GetIndex () const
| Get the ID of this component.
CargoID | GetCargo () const
| Get the cargo ID this component's link graph refers to.
const LinkGraphSettings & | GetSettings () const
| Get the link graph settings for this component.
NodeID | GetFirstEdge (NodeID from)
| Get the first valid edge starting at the specified node.
void | Clear ()
| Set the number of nodes to 0 to mark this component as done.
## Protected Attributes
LinkGraphSettings | settings
| Copy of _settings_game.linkgraph at creation time.
CargoID | cargo
| Cargo of this component's link graph.
uint | num_nodes
| Number of nodes in the component.
LinkGraphComponentID | index
| ID of the component.
NodeVector | nodes
| Nodes in the component.
EdgeMatrix | edges
| Edges in the component.
## Private Types
typedef std::vector< Node > | NodeVector
typedef std::vector < std::vector< Edge > > | EdgeMatrix

## Detailed Description

A connected component of a link graph.

Contains a complete set of stations connected by links as nodes and edges. Each component also holds a copy of the link graph settings at the time of its creation. The global settings might change between the creation and join time so we can't rely on them.

Definition at line 83 of file linkgraph.h.

## Member Function Documentation

void LinkGraphComponent::AddEdge | ( | NodeID | from,
|  | NodeID | to,
|  | uint | capacity |
| ) |  |  | `[inline]`

Fill an edge with values from a link.

Parameters:

  | from | Source node of the link.
  | to | Destination node of the link.
  | capacity | Capacity of the link.

Definition at line 248 of file linkgraph.cpp.

References Edge::capacity, edges, and Edge::next_edge.

Referenced by LinkGraph::CreateComponent().

NodeID LinkGraphComponent::AddNode | ( | Station * | st | ) |

Add a node to the component and create empty edges associated with it.

Set the station's last_component to this component. Calculate the distances to all other nodes. The distances to _all_ nodes are important as the demand calculator relies on their availability.

Parameters:

  | st | New node's station.

Returns:
  New node's ID.

Definition at line 213 of file linkgraph.cpp.

References GoodsEntry::acceptance_pickup, cargo, DistanceManhattan(), edges, GoodsEntry::GES_ACCEPTANCE, SpecializedStation< Station, false >::Get(), Station::goods, HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, index, GoodsEntry::last_component, nodes, num_nodes, GoodsEntry::supply, and BaseStation::xy.

Referenced by LinkGraph::CreateComponent().

CargoID LinkGraphComponent::GetCargo | ( |  | ) | const`[inline]`

Get the cargo ID this component's link graph refers to.

Returns:
  Cargo ID.

Definition at line 142 of file linkgraph.h.

References cargo.

Referenced by DemandCalculator::DemandCalculator().

Edge& LinkGraphComponent::GetEdge | ( | NodeID | from,
|  | NodeID | to |
| ) |  |  | `[inline]`

Get a reference to an edge.

Parameters:

  | from | Origin node.
  | to | Destination node.

Returns:
  Edge between from and to.

Definition at line 99 of file linkgraph.h.

References edges.

Referenced by Path::AddFlow(), DemandCalculator::CalcDemand(), MultiCommodityFlow::Dijkstra(), MCF1stPass::EliminateCycle(), MCF1stPass::MCF1stPass(), MCF2ndPass::MCF2ndPass(), SaveLoad_LinkGraphComponent(), and Scaler::SetDemands().

NodeID LinkGraphComponent::GetFirstEdge | ( | NodeID | from | ) | `[inline]`

Get the first valid edge starting at the specified node.

Parameters:

  | from | ID of the source node

Returns:
  ID of the destination node

Definition at line 161 of file linkgraph.h.

References edges.

Referenced by MultiCommodityFlow::Dijkstra().

LinkGraphComponentID LinkGraphComponent::GetIndex | ( |  | ) | const`[inline]`

Get the ID of this component.

Returns:
  ID.

Definition at line 133 of file linkgraph.h.

References index.

Node& LinkGraphComponent::GetNode | ( | NodeID | num | ) | `[inline]`

Get a reference to a node with the specified id.

Parameters:

  | num | ID of the node.

Returns:
  the Requested node.

Definition at line 109 of file linkgraph.h.

References nodes.

Referenced by Path::AddFlow(), DemandCalculator::CalcDemand(), MultiCommodityFlow::Dijkstra(), MCF1stPass::EliminateCycles(), LinkGraph::Join(), Load_LGRP(), FlowMapper::Run(), SaveLoad_LinkGraphComponent(), Scaler::SetDemands(), and SymmetricScaler::SetDemands().

const LinkGraphSettings& LinkGraphComponent::GetSettings | ( |  | ) | const`[inline]`

Get the link graph settings for this component.

Returns:
  Settings.

Definition at line 151 of file linkgraph.h.

References settings.

Referenced by Path::AddFlow(), DemandCalculator::DemandCalculator(), MultiCommodityFlow::Dijkstra(), MCF1stPass::MCF1stPass(), and MCF2ndPass::MCF2ndPass().

uint LinkGraphComponent::GetSize | ( |  | ) | const`[inline]`

Get the current size of the component.

Returns:
  Size.

Definition at line 118 of file linkgraph.h.

References num_nodes.

Referenced by AfterLoadLinkGraphs(), DemandCalculator::CalcDemand(), MultiCommodityFlow::Dijkstra(), MCF1stPass::EliminateCycles(), LinkGraph::Join(), Load_LGRP(), MCF1stPass::MCF1stPass(), MCF2ndPass::MCF2ndPass(), LinkGraph::NextComponent(), FlowMapper::Run(), and SaveLoad_LinkGraphComponent().

void LinkGraphComponent::SetSize | ( |  | ) |

Resize the component and fill it with empty nodes and edges.

Used when loading from save games.

WARNING: The nodes and edges are expected to contain anything while num_nodes is expected to contain the desired size. Normally this is an invalid state, but just after loading the component's structure it is valid. This method should only be called from Load_LGRP.

Definition at line 267 of file linkgraph.cpp.

References edges, nodes, and num_nodes.

Referenced by Load_LGRP().

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

- src/linkgraph/linkgraph.h
- src/linkgraph/linkgraph.cpp