OpenTTD Source 20250312-master-gcdcc6b491d
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 Attributes

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

Static Protected Attributes

static constexpr int PATH_CAP_MULTIPLIER = 16
 
static constexpr int PATH_CAP_MIN_FREE = (INT_MIN + 1) / PATH_CAP_MULTIPLIER
 
static constexpr int PATH_CAP_MAX_FREE = (INT_MAX - 1) / PATH_CAP_MULTIPLIER
 

Detailed Description

A leg of a path in the link graph.

Paths can form trees by being "forked".

Definition at line 273 of file linkgraphjob.h.

Constructor & Destructor Documentation

◆ Path()

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 248 of file linkgraphjob.cpp.

Member Function Documentation

◆ AddFlow() [1/2]

void Path::AddFlow ( uint  f)
inline

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

Definition at line 323 of file linkgraphjob.h.

References flow.

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

◆ AddFlow() [2/2]

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 221 of file linkgraphjob.cpp.

References AddFlow(), LinkGraphJob::EdgeAnnotation::AddFlow(), LinkGraphJob::EdgeAnnotation::base, LinkGraph::BaseEdge::capacity, LinkGraphJob::EdgeAnnotation::Flow(), flow, node, and parent.

◆ Detach()

void Path::Detach ( )
inline

Detach this path from its parent.

Definition at line 334 of file linkgraphjob.h.

References num_children, and parent.

Referenced by MultiCommodityFlow::CleanupPaths(), and Fork().

◆ Fork()

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 199 of file linkgraphjob.cpp.

References capacity, Detach(), distance, free_capacity, num_children, origin, and parent.

◆ GetCapacity()

uint Path::GetCapacity ( ) const
inline

Get the overall capacity of the path.

Definition at line 290 of file linkgraphjob.h.

References capacity.

◆ GetCapacityRatio() [1/2]

int Path::GetCapacityRatio ( ) const
inline

Get capacity ratio of this path.

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

Definition at line 311 of file linkgraphjob.h.

References capacity, free_capacity, and GetCapacityRatio().

Referenced by GetCapacityRatio(), CapacityAnnotation::IsBetter(), and CapacityAnnotation::UpdateAnnotation().

◆ GetCapacityRatio() [2/2]

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 302 of file linkgraphjob.h.

References Clamp().

◆ GetDistance()

uint Path::GetDistance ( ) const
inline

Get the overall distance of the path.

Definition at line 317 of file linkgraphjob.h.

References distance.

◆ GetFlow()

uint Path::GetFlow ( ) const
inline

Get the flow on this leg.

Definition at line 326 of file linkgraphjob.h.

References flow.

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

◆ GetFreeCapacity()

int Path::GetFreeCapacity ( ) const
inline

Get the free capacity of the path.

Definition at line 293 of file linkgraphjob.h.

References free_capacity.

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

◆ GetNode()

NodeID Path::GetNode ( ) const
inline

Get the node this leg passes.

Definition at line 281 of file linkgraphjob.h.

References node.

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

◆ GetNumChildren()

uint Path::GetNumChildren ( ) const
inline

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

Definition at line 329 of file linkgraphjob.h.

References num_children.

Referenced by MultiCommodityFlow::CleanupPaths().

◆ GetOrigin()

NodeID Path::GetOrigin ( ) const
inline

Get the overall origin of the path.

Definition at line 284 of file linkgraphjob.h.

References origin.

Referenced by MCF1stPass::EliminateCycles().

◆ GetParent()

Path * Path::GetParent ( )
inline

Get the parent leg of this one.

Definition at line 287 of file linkgraphjob.h.

References parent.

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

◆ ReduceFlow()

void Path::ReduceFlow ( uint  f)
inline

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

Definition at line 320 of file linkgraphjob.h.

References flow.

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

Field Documentation

◆ capacity

uint Path::capacity = 0
protected

This capacity is min(capacity) fom all edges.

Definition at line 355 of file linkgraphjob.h.

Referenced by Fork(), GetCapacity(), GetCapacityRatio(), and CapacityAnnotation::IsBetter().

◆ distance

uint Path::distance = 0
protected

Sum(distance of all legs up to this one).

Definition at line 354 of file linkgraphjob.h.

Referenced by Fork(), DistanceAnnotation::GetAnnotation(), GetDistance(), CapacityAnnotation::IsBetter(), and DistanceAnnotation::IsBetter().

◆ flow

uint Path::flow = 0
protected

Flow the current run of the mcf solver assigns.

Definition at line 357 of file linkgraphjob.h.

Referenced by AddFlow(), AddFlow(), GetFlow(), and ReduceFlow().

◆ free_capacity

int Path::free_capacity = 0
protected

This capacity is min(edge.capacity - edge.flow) for the current run of Dijkstra.

Definition at line 356 of file linkgraphjob.h.

Referenced by Fork(), GetCapacityRatio(), GetFreeCapacity(), CapacityAnnotation::IsBetter(), and DistanceAnnotation::IsBetter().

◆ invalid_path

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 275 of file linkgraphjob.h.

Referenced by MCF1stPass::EliminateCycles().

◆ node

NodeID Path::node = INVALID_NODE
protected

Link graph node this leg passes.

Definition at line 358 of file linkgraphjob.h.

Referenced by AddFlow(), and GetNode().

◆ num_children

uint Path::num_children = 0
protected

Number of child legs that have been forked from this path.

Definition at line 360 of file linkgraphjob.h.

Referenced by Detach(), Fork(), and GetNumChildren().

◆ origin

NodeID Path::origin = INVALID_NODE
protected

Link graph node this path originates from.

Definition at line 359 of file linkgraphjob.h.

Referenced by Fork(), and GetOrigin().

◆ parent

Path* Path::parent = nullptr
protected

Parent leg of this one.

Definition at line 361 of file linkgraphjob.h.

Referenced by AddFlow(), Detach(), Fork(), and GetParent().

◆ PATH_CAP_MAX_FREE

constexpr int Path::PATH_CAP_MAX_FREE = (INT_MAX - 1) / PATH_CAP_MULTIPLIER
staticconstexprprotected

Definition at line 352 of file linkgraphjob.h.

◆ PATH_CAP_MIN_FREE

constexpr int Path::PATH_CAP_MIN_FREE = (INT_MIN + 1) / PATH_CAP_MULTIPLIER
staticconstexprprotected

Definition at line 351 of file linkgraphjob.h.

◆ PATH_CAP_MULTIPLIER

constexpr int Path::PATH_CAP_MULTIPLIER = 16
staticconstexprprotected

Definition at line 350 of file linkgraphjob.h.


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