LinkGraphComponent Class Reference

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

#include <linkgraph.h>

Inheritance diagram for LinkGraphComponent:
LinkGraphJob LinkGraph

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 EdgeGetEdge (NodeID from, NodeID to)
 Get a reference to an edge.
FORCEINLINE NodeGetNode (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.
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< NodeNodeVector
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

FORCEINLINE void LinkGraphComponent::AddEdge ( NodeID  from,
NodeID  to,
uint  capacity 
)

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 237 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 202 of file linkgraph.cpp.

References cargo, DistanceManhattan(), edges, 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.

Returns:
Cargo ID.

Definition at line 142 of file linkgraph.h.

References cargo.

Referenced by DemandCalculator::DemandCalculator().

FORCEINLINE 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().

FORCEINLINE 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().

FORCEINLINE LinkGraphComponentID LinkGraphComponent::GetIndex (  )  const [inline]

Get the ID of this component.

Returns:
ID.

Definition at line 133 of file linkgraph.h.

References index.

FORCEINLINE 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().

FORCEINLINE 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().

FORCEINLINE uint LinkGraphComponent::GetSize (  )  const [inline]
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 256 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:

Generated on Fri May 27 04:20:48 2011 for OpenTTD by  doxygen 1.6.1