A connected component of a link graph. More...
#include <linkgraph.h>
Public Member Functions | |
LinkGraph () | |
Bare contructur, only for save/load. | |
LinkGraph (CargoID cargo) | |
void | Compress () |
void | Merge (LinkGraph *other) |
Merge a link graph with another one. | |
Edge & | GetEdge (NodeID from, NodeID to) |
Get a reference to an edge. | |
const Edge & | GetEdge (NodeID from, NodeID to) const |
Get a const reference to an edge. | |
Node & | GetNode (NodeID num) |
Get a reference to a node with the specified id. | |
const Node & | GetNode (NodeID num) const |
Get a const reference to a node with the specified id. | |
uint | GetSize () const |
Get the current size of the component. | |
Date | GetLastCompression () const |
Get date of last compression. | |
CargoID | GetCargo () const |
Get the cargo ID this component's link graph refers to. | |
void | SetSize () |
Resize the component and fill it with empty nodes and edges. | |
NodeID | AddNode (const Station *st) |
Add a node to the component and create empty edges associated with it. | |
void | RemoveNode (NodeID id) |
Remove a node from the link graph by overwriting it with the last node. | |
void | AddEdge (NodeID from, NodeID to, uint capacity) |
Fill an edge with values from a link. | |
void | UpdateEdge (NodeID from, NodeID to, uint capacity, uint usage) |
Create a new edge or update an existing one. | |
void | RemoveEdge (NodeID from, NodeID to) |
NodeID | GetFirstEdge (NodeID from) const |
Get the first valid edge starting at the specified node. | |
NodeID | GetNextEdge (NodeID from, NodeID to) const |
Get the next edge after the given one. | |
Static Public Attributes | |
static const uint | COMPRESSION_TICK = 58 |
Protected Member Functions | |
void | ResizeNodes () |
Protected Attributes | |
CargoID | cargo |
Cargo of this component's link graph. | |
uint16 | num_nodes |
Number of nodes in the component. | |
Date | last_compression |
Last time the capacities and supplies were compressed. | |
NodeVector | nodes |
Nodes in the component. | |
EdgeMatrix | edges |
Edges in the component. | |
Private Types | |
typedef SmallVector< Node, 16 > | NodeVector |
typedef SmallMatrix< Edge > | EdgeMatrix |
Friends | |
const SaveLoad * | GetLinkGraphDesc () |
Get a SaveLoad array for a link graph. | |
const SaveLoad * | GetLinkGraphJobDesc () |
Get a SaveLoad array for a link graph job. |
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 130 of file linkgraph.h.
LinkGraph::LinkGraph | ( | ) | [inline] |
Bare contructur, only for save/load.
Definition at line 142 of file linkgraph.h.
void LinkGraph::AddEdge | ( | NodeID | from, | |
NodeID | to, | |||
uint | capacity | |||
) | [inline] |
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 177 of file linkgraph.cpp.
References _date, Edge::capacity, edges, Edge::last_update, and Edge::next_edge.
Referenced by UpdateEdge().
NodeID LinkGraph::AddNode | ( | const 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 | New node's station. |
Definition at line 143 of file linkgraph.cpp.
References GoodsEntry::acceptance_pickup, SmallVector< T, S >::Append(), 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, Edge::Init(), SmallVector< T, S >::Length(), max(), Edge::next_edge, nodes, SmallMatrix< T >::Resize(), and BaseStation::xy.
Referenced by IncreaseStats(), and Merge().
CargoID LinkGraph::GetCargo | ( | ) | const [inline] |
Get the cargo ID this component's link graph refers to.
Definition at line 220 of file linkgraph.h.
References cargo.
Referenced by DemandCalculator::DemandCalculator(), and LinkGraphJob::~LinkGraphJob().
const Edge& LinkGraph::GetEdge | ( | NodeID | from, | |
NodeID | to | |||
) | const [inline] |
Get a const reference to an edge.
from | Origin node. | |
to | Destination node. |
Definition at line 173 of file linkgraph.h.
References edges.
Edge& LinkGraph::GetEdge | ( | NodeID | from, | |
NodeID | to | |||
) | [inline] |
Get a reference to an edge.
from | Origin node. | |
to | Destination node. |
Definition at line 162 of file linkgraph.h.
References edges.
Referenced by Path::AddFlow(), LinkGraphOverlay::AddLinks(), DemandCalculator::CalcDemand(), DeleteStaleLinks(), MultiCommodityFlow::Dijkstra(), GraphEdgeIterator::Next(), LinkGraphOverlay::RebuildCache(), SaveLoad_LinkGraph(), and LinkGraphJob::~LinkGraphJob().
NodeID LinkGraph::GetFirstEdge | ( | NodeID | from | ) | const [inline] |
Get the first valid edge starting at the specified node.
from | ID of the source node. |
Definition at line 239 of file linkgraph.h.
References edges.
Referenced by LinkGraphOverlay::AddLinks(), LinkGraphOverlay::RebuildCache(), and RemoveNode().
Date LinkGraph::GetLastCompression | ( | ) | const [inline] |
Get date of last compression.
Definition at line 211 of file linkgraph.h.
References last_compression.
Referenced by LinkGraphOverlay::AddLinks(), StationViewWindow::DrawCargoRatings(), OnTick_LinkGraph(), LinkGraphOverlay::RebuildCache(), and FlowMapper::Run().
NodeID LinkGraph::GetNextEdge | ( | NodeID | from, | |
NodeID | to | |||
) | const [inline] |
Get the next edge after the given one.
from | ID of source node. | |
to | ID of current destination node. |
Definition at line 247 of file linkgraph.h.
References edges.
Referenced by LinkGraphOverlay::AddLinks(), and LinkGraphOverlay::RebuildCache().
Node& LinkGraph::GetNode | ( | NodeID | num | ) | [inline] |
Get a reference to a node with the specified id.
num | ID of the node. |
Definition at line 183 of file linkgraph.h.
References nodes.
Referenced by DemandCalculator::CalcDemand(), StationViewWindow::DrawCargoRatings(), FlowEdgeIterator::FlowEdgeIterator(), LinkGraphOverlay::RebuildCache(), InitHandler::Run(), FlowMapper::Run(), SaveLoad_LinkGraph(), SymmetricScaler::SetDemands(), FlowEdgeIterator::SetNode(), and LinkGraphJob::~LinkGraphJob().
const Node& LinkGraph::GetNode | ( | NodeID | num | ) | const [inline] |
Get a const reference to a node with the specified id.
num | ID of the node. |
Definition at line 193 of file linkgraph.h.
References nodes.
uint LinkGraph::GetSize | ( | ) | const [inline] |
Get the current size of the component.
Definition at line 202 of file linkgraph.h.
References num_nodes.
Referenced by DemandCalculator::CalcDemand(), MultiCommodityFlow::Dijkstra(), MCF1stPass::EliminateCycles(), FlowEdgeIterator::FlowEdgeIterator(), IncreaseStats(), MCF1stPass::MCF1stPass(), MCF2ndPass::MCF2ndPass(), InitHandler::Run(), FlowMapper::Run(), SaveLoad_LinkGraph(), LinkGraphJob::~LinkGraphJob(), and Station::~Station().
void LinkGraph::Merge | ( | LinkGraph * | other | ) |
Merge a link graph with another one.
other | LinkGraph to be merged into this one. |
Definition at line 77 of file linkgraph.cpp.
References _date, AddNode(), Edge::capacity, cargo, edges, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_link_graph_pool >::Get(), Station::goods, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_link_graph_pool >::index, last_compression, GoodsEntry::link_graph, Edge::next_edge, nodes, num_nodes, and Edge::usage.
Referenced by IncreaseStats().
void LinkGraph::RemoveNode | ( | NodeID | id | ) |
Remove a node from the link graph by overwriting it with the last node.
id | ID of the node to be removed. |
Definition at line 111 of file linkgraph.cpp.
References edges, SmallVector< T, S >::Erase(), SmallMatrix< T >::EraseColumn(), SmallVector< T, S >::Get(), GetFirstEdge(), and nodes.
Referenced by Station::~Station().
void LinkGraph::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 garbage 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 and Load_LGRJ.
Definition at line 245 of file linkgraph.cpp.
References edges, Edge::Init(), SmallVector< T, S >::Length(), nodes, SmallVector< T, S >::Resize(), and SmallMatrix< T >::Resize().
Referenced by Load_LGRJ(), and Load_LGRP().
void LinkGraph::UpdateEdge | ( | NodeID | from, | |
NodeID | to, | |||
uint | capacity, | |||
uint | usage | |||
) |
Create a new edge or update an existing one.
If usage is UINT_MAX refresh the edge to have at least the given capacity, otherwise add the capacity.
from | Start node of the edge. | |
to | End node of the edge. | |
capacity | Capacity to be added/updated. | |
usage | Usage to be added or UINT_MAX. |
Definition at line 218 of file linkgraph.cpp.
References _date, AddEdge(), Edge::capacity, edges, Edge::last_update, max(), and Edge::usage.
Referenced by IncreaseStats().
const SaveLoad* GetLinkGraphDesc | ( | ) | [friend] |
Get a SaveLoad array for a link graph.
Definition at line 23 of file linkgraph_sl.cpp.
const SaveLoad* GetLinkGraphJobDesc | ( | ) | [friend] |
Get a SaveLoad array for a link graph job.
The settings struct is derived from the global settings saveload array. The exact entries are calculated when the function is called the first time. It's necessary to keep a copy of the settings for each link graph job so that you can change the settings while in-game and still not mess with current link graph runs. Of course the settings have to be saved and loaded, too, to avoid desyncs.
Definition at line 43 of file linkgraph_sl.cpp.