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

LinkGraph Class Reference

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

#include <linkgraph.h>

Inheritance diagram for LinkGraph:
Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_link_graph_pool >

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.
EdgeGetEdge (NodeID from, NodeID to)
 Get a reference to an edge.
const EdgeGetEdge (NodeID from, NodeID to) const
 Get a const reference to an edge.
NodeGetNode (NodeID num)
 Get a reference to a node with the specified id.
const NodeGetNode (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< EdgeEdgeMatrix

Friends

const SaveLoadGetLinkGraphDesc ()
 Get a SaveLoad array for a link graph.
const SaveLoadGetLinkGraphJobDesc ()
 Get a SaveLoad array for a link graph job.

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 130 of file linkgraph.h.


Constructor & Destructor Documentation

LinkGraph::LinkGraph (  )  [inline]

Bare contructur, only for save/load.

Definition at line 142 of file linkgraph.h.


Member Function Documentation

void LinkGraph::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 180 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.

Parameters:
st New node's station.
Returns:
New node's ID.

Definition at line 146 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.

Returns:
Cargo ID.

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.

Parameters:
from Origin node.
to Destination node.
Returns:
Edge between from and to.

Definition at line 173 of file linkgraph.h.

References edges.

Edge& LinkGraph::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 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.

Parameters:
from ID of the source node.
Returns:
ID of the destination 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.

Returns:
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.

Parameters:
from ID of source node.
to ID of current destination node.
Returns:
ID of next 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]
const Node& LinkGraph::GetNode ( NodeID  num  )  const [inline]

Get a const reference to a node with the specified id.

Parameters:
num ID of the node.
Returns:
the Requested node.

Definition at line 193 of file linkgraph.h.

References nodes.

void LinkGraph::RemoveNode ( NodeID  id  ) 

Remove a node from the link graph by overwriting it with the last node.

Parameters:
id ID of the node to be removed.

Definition at line 111 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(), 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 248 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.

Parameters:
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 221 of file linkgraph.cpp.

References _date, AddEdge(), Edge::capacity, edges, Edge::last_update, max(), and Edge::usage.

Referenced by IncreaseStats().


Friends And Related Function Documentation

const SaveLoad* GetLinkGraphDesc (  )  [friend]

Get a SaveLoad array for a link graph.

Returns:
SaveLoad array for 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.

Returns:
Array of SaveLoad structs.

Definition at line 43 of file linkgraph_sl.cpp.


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