OpenTTD
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Protected Attributes
Path Class Reference

A leg of a path in the link graph. More...

#include <linkgraphjob.h>

Inheritance diagram for Path:
CapacityAnnotation DistanceAnnotation

Public Member Functions

 Path (NodeID n, bool source=false)
 Create a leg of a path in the link graph.
NodeID GetNode () const
 Get the node this leg passes.
NodeID GetOrigin () const
 Get the overall origin of the path.
PathGetParent ()
 Get the parent leg of this one.
uint GetCapacity () const
 Get the overall capacity of the path.
int GetFreeCapacity () const
 Get the free capacity of the path.
int GetCapacityRatio () const
 Get capacity ratio of this path.
uint GetDistance () const
 Get the overall distance of the path.
void ReduceFlow (uint f)
 Reduce the flow on this leg only by the specified amount.
void AddFlow (uint f)
 Increase the flow on this leg only by the specified amount.
uint GetFlow () const
 Get the flow on this leg.
uint GetNumChildren () const
 Get the number of "forked off" child legs of this one.
void Detach ()
 Detach this path from its parent.
uint AddFlow (uint f, LinkGraphJob &job, uint max_saturation)
 Push some flow along a path and register the path in the nodes it passes if successful.
void Fork (Path *base, uint cap, int free_cap, uint dist)
 Add this path as a new child to the given base path, thus making this path a "fork" of the base path.

Static Public Member Functions

static int GetCapacityRatio (int free, uint total)
 Get ratio of free * 16 (so that we get fewer 0) / max(total capacity, 1) (so that we don't divide by 0).

Static Public Attributes

static Pathinvalid_path = new Path(INVALID_NODE, true)
 Static instance of an invalid path.

Protected Types

enum  PathCapacityBoundaries { PATH_CAP_MULTIPLIER = 16, PATH_CAP_MIN_FREE = (INT_MIN + 1) / PATH_CAP_MULTIPLIER, PATH_CAP_MAX_FREE = (INT_MAX - 1) / PATH_CAP_MULTIPLIER }
 Some boundaries to clamp agains in order to avoid integer overflows.

Protected Attributes

uint distance
 Sum(distance of all legs up to this one).
uint capacity
 This capacity is min(capacity) fom all edges.
int free_capacity
 This capacity is min(edge.capacity - edge.flow) for the current run of Dijkstra.
uint flow
 Flow the current run of the mcf solver assigns.
NodeID node
 Link graph node this leg passes.
NodeID origin
 Link graph node this path originates from.
uint num_children
 Number of child legs that have been forked from this path.
Pathparent
 Parent leg of this one.

Detailed Description

A leg of a path in the link graph.

Paths can form trees by being "forked".

Definition at line 344 of file linkgraphjob.h.

Constructor & Destructor Documentation

Path::Path ( NodeID  n,
bool  source = false 
)

Create a leg of a path in the link graph.

Parameters
nId of the link graph node this path passes.
sourceIf true, this is the first leg of the path.

Definition at line 272 of file linkgraphjob.cpp.

Member Function Documentation

void Path::AddFlow ( uint  f)
inline

Increase the flow on this leg only by the specified amount.

Definition at line 393 of file linkgraphjob.h.

References flow.

Referenced by MCF1stPass::EliminateCycles(), and MultiCommodityFlow::PushFlow().

uint Path::AddFlow ( uint  new_flow,
LinkGraphJob job,
uint  max_saturation 
)

Push some flow along a path and register the path in the nodes it passes if successful.

Parameters
new_flowAmount of flow to push.
jobLink graph job this node belongs to.
max_saturationMaximum saturation of edges.
Returns
Amount of flow actually pushed.

Definition at line 245 of file linkgraphjob.cpp.

References LinkGraphJob::Edge::AddFlow(), LinkGraph::EdgeWrapper< Tedge >::Capacity(), LinkGraphJob::Edge::Flow(), and min().

void Path::Fork ( Path base,
uint  cap,
int  free_cap,
uint  dist 
)

Add this path as a new child to the given base path, thus making this path a "fork" of the base path.

Parameters
basePath to fork from.
capMaximum capacity of the new leg.
free_capRemaining free capacity of the new leg.
distDistance of the new leg.

Definition at line 223 of file linkgraphjob.cpp.

References capacity, distance, free_capacity, min(), num_children, and origin.

uint Path::GetCapacity ( ) const
inline

Get the overall capacity of the path.

Definition at line 360 of file linkgraphjob.h.

References capacity.

static int Path::GetCapacityRatio ( int  free,
uint  total 
)
inlinestatic

Get ratio of free * 16 (so that we get fewer 0) / max(total capacity, 1) (so that we don't divide by 0).

Parameters
freeFree capacity.
totalTotal capacity.
Returns
free * 16 / max(total, 1).

Definition at line 372 of file linkgraphjob.h.

References Clamp(), and max().

int Path::GetCapacityRatio ( ) const
inline

Get capacity ratio of this path.

Returns
free capacity * 16 / (total capacity + 1).

Definition at line 381 of file linkgraphjob.h.

References capacity, and free_capacity.

Referenced by CapacityAnnotation::GetAnnotation(), and CapacityAnnotation::IsBetter().

uint Path::GetDistance ( ) const
inline

Get the overall distance of the path.

Definition at line 387 of file linkgraphjob.h.

References distance.

uint Path::GetFlow ( ) const
inline
int Path::GetFreeCapacity ( ) const
inline

Get the free capacity of the path.

Definition at line 363 of file linkgraphjob.h.

References free_capacity.

Referenced by MCF1stPass::MCF1stPass(), and MCF2ndPass::MCF2ndPass().

NodeID Path::GetNode ( ) const
inline
uint Path::GetNumChildren ( ) const
inline

Get the number of "forked off" child legs of this one.

Definition at line 399 of file linkgraphjob.h.

References num_children.

Referenced by MultiCommodityFlow::CleanupPaths().

NodeID Path::GetOrigin ( ) const
inline

Get the overall origin of the path.

Definition at line 354 of file linkgraphjob.h.

References origin.

Referenced by MCF1stPass::EliminateCycles(), and FlowMapper::Run().

Path* Path::GetParent ( )
inline

Get the parent leg of this one.

Definition at line 357 of file linkgraphjob.h.

References parent.

Referenced by MultiCommodityFlow::CleanupPaths(), and MCF1stPass::EliminateCycle().

void Path::ReduceFlow ( uint  f)
inline

Reduce the flow on this leg only by the specified amount.

Definition at line 390 of file linkgraphjob.h.

References flow.

Referenced by MCF1stPass::EliminateCycle(), and MCF1stPass::EliminateCycles().

Field Documentation

Path * Path::invalid_path = new Path(INVALID_NODE, true)
static

Static instance of an invalid path.

Note: This instance is created on task start. Lazy creation on first usage results in a data race between the CDist threads.

Definition at line 346 of file linkgraphjob.h.

Referenced by MCF1stPass::EliminateCycles().


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