A connected component of a link graph. More...
#include <linkgraph.h>
Data Structures | |
struct | BaseEdge |
An edge in the link graph. More... | |
class | BaseEdgeIterator |
Base class for iterating across outgoing edges of a node. More... | |
struct | BaseNode |
Node of the link graph. More... | |
class | ConstEdgeIterator |
An iterator for const edges. More... | |
class | ConstNode |
Constant node class. More... | |
class | Edge |
An updatable edge class. More... | |
class | EdgeIterator |
An iterator for non-const edges. More... | |
class | EdgeWrapper |
Wrapper for an edge (const or not) allowing retrieval, but no modification. More... | |
class | Node |
Updatable node class. More... | |
class | NodeWrapper |
Wrapper for a node (const or not) allowing retrieval, but no modification. More... | |
Public Types | |
enum | UpdateMode { REFRESH_RESTRICTED = UINT_MAX - 1, REFRESH_UNRESTRICTED = UINT_MAX } |
Special modes for updating links. More... | |
typedef EdgeWrapper< const BaseEdge > | ConstEdge |
A constant edge class. | |
typedef SmallVector< BaseNode, 16 > | NodeVector |
typedef SmallMatrix< BaseEdge > | EdgeMatrix |
Public Member Functions | |
LinkGraph () | |
Bare constructor, only for save/load. | |
LinkGraph (CargoID cargo) | |
Real constructor. | |
void | Init (uint size) |
Resize the component and fill it with empty nodes and edges. | |
void | ShiftDates (int interval) |
Shift all dates by given interval. | |
void | Compress () |
void | Merge (LinkGraph *other) |
Merge a link graph with another one. | |
Node | operator[] (NodeID num) |
Get a node with the specified id. | |
ConstNode | operator[] (NodeID num) const |
Get a const reference to a node with the specified id. | |
uint | Size () const |
Get the current size of the component. | |
Date | LastCompression () const |
Get date of last compression. | |
CargoID | Cargo () const |
Get the cargo ID this component's link graph refers to. | |
uint | Monthly (uint base) const |
Scale a value to its monthly equivalent, based on last compression. | |
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. | |
Static Public Member Functions | |
static uint | Scale (uint val, uint target_age, uint orig_age) |
Scale a value from a link graph of age orig_age for usage in one of age target_age. | |
Static Public Attributes | |
static const uint | MIN_TIMEOUT_DISTANCE = 32 |
Minimum effective distance for timeout calculation. | |
static const uint | COMPRESSION_INTERVAL = 256 |
Minimum number of days between subsequent compressions of a LG. | |
Protected Attributes | |
CargoID | cargo |
Cargo of this component's link graph. | |
Date | last_compression |
Last time the capacities and supplies were compressed. | |
NodeVector | nodes |
Nodes in the component. | |
EdgeMatrix | edges |
Edges in the component. | |
Friends | |
class | LinkGraph::ConstNode |
class | LinkGraph::Node |
const SaveLoad * | GetLinkGraphDesc () |
Get a SaveLoad array for a link graph. | |
const SaveLoad * | GetLinkGraphJobDesc () |
Get a SaveLoad array for a link graph job. | |
void | SaveLoad_LinkGraph (LinkGraph &lg) |
Save/load a link graph. |
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 40 of file linkgraph.h.
Special modes for updating links.
'Restricted' means that vehicles with 'no loading' orders are serving the link. If a link is only served by such vehicles it's 'fully restricted'. This means the link can be used by cargo arriving in such vehicles, but not by cargo generated or transferring at the source station of the link. In order to find out about this condition we keep two update timestamps in each link, one for the restricted and one for the unrestricted part of it. If either one times out while the other is still valid the link becomes fully restricted or fully unrestricted, respectively.
REFRESH_RESTRICTED |
Refresh restricted link. |
REFRESH_UNRESTRICTED |
Refresh unrestricted link. |
Definition at line 54 of file linkgraph.h.
LinkGraph::LinkGraph | ( | ) | [inline] |
Bare constructor, only for save/load.
Definition at line 468 of file linkgraph.h.
LinkGraph::LinkGraph | ( | CargoID | cargo | ) | [inline] |
Real constructor.
cargo | Cargo the link graph is about. |
Definition at line 473 of file linkgraph.h.
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 155 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, LinkGraph::BaseEdge::Init(), max(), LinkGraph::BaseEdge::next_edge, nodes, SmallMatrix< T >::Resize(), Size(), and BaseStation::xy.
Referenced by IncreaseStats(), and Merge().
CargoID LinkGraph::Cargo | ( | ) | const [inline] |
Get the cargo ID this component's link graph refers to.
Definition at line 518 of file linkgraph.h.
References cargo.
Referenced by LinkGraphJob::Cargo().
void LinkGraph::Init | ( | uint | size | ) |
Resize the component and fill it with empty nodes and edges.
Used when loading from save games. The component is expected to be empty before.
size | New size of the component. |
Definition at line 291 of file linkgraph.cpp.
References edges, nodes, SmallVector< T, S >::Resize(), SmallMatrix< T >::Resize(), and Size().
Referenced by Load_LGRJ(), and Load_LGRP().
Date LinkGraph::LastCompression | ( | ) | const [inline] |
Get date of last compression.
Definition at line 512 of file linkgraph.h.
References last_compression.
Referenced by DeleteStaleLinks(), and LinkGraphJob::LastCompression().
void LinkGraph::Merge | ( | LinkGraph * | other | ) |
Merge a link graph with another one.
other | LinkGraph to be merged into this one. |
Definition at line 85 of file linkgraph.cpp.
References _date, AddNode(), LinkGraph::BaseEdge::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, LinkGraph::BaseEdge::next_edge, GoodsEntry::node, nodes, Scale(), Size(), and LinkGraph::BaseEdge::usage.
Referenced by IncreaseStats().
uint LinkGraph::Monthly | ( | uint | base | ) | const [inline] |
Scale a value to its monthly equivalent, based on last compression.
base | Value to be scaled. |
Definition at line 525 of file linkgraph.h.
References _date, and last_compression.
Referenced by LinkGraphOverlay::AddLinks(), StationViewWindow::DrawCargoRatings(), and LinkGraphOverlay::RebuildCache().
ConstNode LinkGraph::operator[] | ( | NodeID | num | ) | const [inline] |
Get a const reference to a node with the specified id.
num | ID of the node. |
Definition at line 500 of file linkgraph.h.
Node LinkGraph::operator[] | ( | NodeID | num | ) | [inline] |
Get a node with the specified id.
num | ID of the node. |
Definition at line 493 of file linkgraph.h.
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 119 of file linkgraph.cpp.
References cargo, edges, SmallVector< T, S >::Erase(), SmallMatrix< T >::EraseColumn(), SmallVector< T, S >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_link_graph_pool >::Get(), LinkGraph::BaseEdge::next_edge, nodes, and Size().
Referenced by Station::~Station().
static uint LinkGraph::Scale | ( | uint | val, | |
uint | target_age, | |||
uint | orig_age | |||
) | [inline, static] |
Scale a value from a link graph of age orig_age for usage in one of age target_age.
Make sure that the value stays > 0 if it was > 0 before.
val | Value to be scaled. | |
target_age | Age of the target link graph. | |
orig_age | Age of the original link graph. |
Definition at line 462 of file linkgraph.h.
References max().
Referenced by Merge().
void LinkGraph::ShiftDates | ( | int | interval | ) |
Shift all dates by given interval.
This is useful if the date has been modified with the cheat menu.
interval | Number of days to be added or subtracted. |
Definition at line 52 of file linkgraph.cpp.
References edges, INVALID_DATE, last_compression, LinkGraph::BaseEdge::last_restricted_update, LinkGraph::BaseEdge::last_unrestricted_update, LinkGraph::BaseNode::last_update, nodes, and Size().
Referenced by OnNewYear(), and LinkGraphSchedule::ShiftDates().
uint LinkGraph::Size | ( | ) | const [inline] |
Get the current size of the component.
Definition at line 506 of file linkgraph.h.
References SmallVector< T, S >::Length(), and nodes.
Referenced by AddNode(), DoSave_LGRP(), IncreaseStats(), Init(), Merge(), RemoveNode(), SaveLoad_LinkGraph(), ShiftDates(), LinkGraphJob::Size(), LinkGraphSchedule::SpawnNext(), and Station::~Station().
const SaveLoad* GetLinkGraphDesc | ( | ) | [friend] |
Get a SaveLoad array for a link graph.
Definition at line 30 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 50 of file linkgraph_sl.cpp.
void SaveLoad_LinkGraph | ( | LinkGraph & | lg | ) | [friend] |
Save/load a link graph.
comp | Link graph to be saved or loaded. |
Definition at line 134 of file linkgraph_sl.cpp.
const uint LinkGraph::COMPRESSION_INTERVAL = 256 [static] |
Minimum number of days between subsequent compressions of a LG.
Definition at line 452 of file linkgraph.h.
Referenced by DeleteStaleLinks().
const uint LinkGraph::MIN_TIMEOUT_DISTANCE = 32 [static] |
Minimum effective distance for timeout calculation.
Definition at line 449 of file linkgraph.h.
Referenced by DeleteStaleLinks().