A connected component of a link graph. More...
#include <linkgraph.h>
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. | |
FORCEINLINE Edge & | GetEdge (NodeID from, NodeID to) |
Get a reference to an edge. | |
FORCEINLINE Node & | GetNode (NodeID num) |
Get a reference to a node with the specified id. | |
FORCEINLINE 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. | |
FORCEINLINE void | AddEdge (NodeID from, NodeID to, uint capacity) |
Fill an edge with values from a link. | |
FORCEINLINE LinkGraphComponentID | GetIndex () const |
Get the ID of this component. | |
FORCEINLINE CargoID | GetCargo () const |
Get the cargo ID this component's link graph refers to. | |
FORCEINLINE const LinkGraphSettings & | GetSettings () const |
Get the link graph settings for this component. | |
FORCEINLINE NodeID | GetFirstEdge (NodeID from) |
Get the first valid edge starting at the specified node. | |
FORCEINLINE 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 |
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 84 of file linkgraph.h.
FORCEINLINE void LinkGraphComponent::AddEdge | ( | NodeID | from, | |
NodeID | to, | |||
uint | capacity | |||
) |
Fill an edge with values from a link.
from | source node of the link | |
to | destination node of the link | |
capacity | capacity of the link |
Definition at line 247 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.
st | the new node's station |
Definition at line 212 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().
FORCEINLINE CargoID LinkGraphComponent::GetCargo | ( | ) | const [inline] |
Get the cargo ID this component's link graph refers to.
Definition at line 143 of file linkgraph.h.
References cargo.
Referenced by DemandCalculator::DemandCalculator(), and LinkGraph::Join().
FORCEINLINE Edge& LinkGraphComponent::GetEdge | ( | NodeID | from, | |
NodeID | to | |||
) | [inline] |
Get a reference to an edge.
from | the origin node | |
the | destination node |
Definition at line 100 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().
FORCEINLINE NodeID LinkGraphComponent::GetFirstEdge | ( | NodeID | from | ) | [inline] |
Get the first valid edge starting at the specified node.
from | ID of the source node |
Definition at line 162 of file linkgraph.h.
References edges.
Referenced by MultiCommodityFlow::Dijkstra().
FORCEINLINE LinkGraphComponentID LinkGraphComponent::GetIndex | ( | ) | const [inline] |
Get the ID of this component.
Definition at line 134 of file linkgraph.h.
References index.
FORCEINLINE Node& LinkGraphComponent::GetNode | ( | NodeID | num | ) | [inline] |
Get a reference to a node with the specified id.
num | ID of the node |
Definition at line 110 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().
FORCEINLINE const LinkGraphSettings& LinkGraphComponent::GetSettings | ( | ) | const [inline] |
Get the link graph settings for this component.
Definition at line 152 of file linkgraph.h.
References settings.
Referenced by Path::AddFlow(), DemandCalculator::DemandCalculator(), MultiCommodityFlow::Dijkstra(), MCF1stPass::MCF1stPass(), and MCF2ndPass::MCF2ndPass().
FORCEINLINE uint LinkGraphComponent::GetSize | ( | ) | const [inline] |
Get the current size of the component.
Definition at line 119 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 266 of file linkgraph.cpp.
References edges, nodes, and num_nodes.
Referenced by Load_LGRP().