OpenTTD Source  20240919-master-gdf0233f4c2
MCF1stPass Class Reference

First pass of the MCF calculation. More...

#include <mcf.h>

Inheritance diagram for MCF1stPass:
MultiCommodityFlow

Public Member Functions

 MCF1stPass (LinkGraphJob &job)
 Run the first pass of the MCF calculation. More...
 

Private Member Functions

bool EliminateCycles ()
 Eliminate all cycles in the graph. More...
 
bool EliminateCycles (PathVector &path, NodeID origin_id, NodeID next_id)
 Eliminate cycles for origin_id in the graph. More...
 
void EliminateCycle (PathVector &path, Path *cycle_begin, uint flow)
 Eliminate a cycle of the given flow in the given set of paths. More...
 
uint FindCycleFlow (const PathVector &path, const Path *cycle_begin)
 Find the flow along a cycle including cycle_begin in path. More...
 

Additional Inherited Members

- Protected Member Functions inherited from MultiCommodityFlow
 MultiCommodityFlow (LinkGraphJob &job)
 Constructor. More...
 
template<class Tannotation , class Tedge_iterator >
void Dijkstra (NodeID from, PathVector &paths)
 A slightly modified Dijkstra algorithm. More...
 
uint PushFlow (Node &node, NodeID to, Path *path, uint accuracy, uint max_saturation)
 Push flow along a path and update the unsatisfied_demand of the associated edge. More...
 
void CleanupPaths (NodeID source, PathVector &paths)
 Clean up paths that lead nowhere and the root path. More...
 
- Protected Attributes inherited from MultiCommodityFlow
LinkGraphJobjob
 Job we're working with.
 
uint max_saturation
 Maximum saturation for edges.
 

Detailed Description

First pass of the MCF calculation.

Saturates shortest paths first, creates new paths if needed, eliminates cycles. This calculation is of exponential complexity in the number of nodes but the constant factors are sufficiently small to make it usable for most real-life link graph components. You can deal with performance problems that might occur here in multiple ways:

  • The overall accuracy is used here to determine how much flow is assigned in each loop. The lower the accuracy, the more flow is assigned, the less loops it takes to assign all flow.
  • The short_path_saturation setting determines when this pass stops. The lower you set it, the less flow will be assigned in this pass, the less time it will take.
  • You can increase the recalculation interval to allow for longer running times without creating lags.

Definition at line 49 of file mcf.h.

Constructor & Destructor Documentation

◆ MCF1stPass()

MCF1stPass::MCF1stPass ( LinkGraphJob job)

Run the first pass of the MCF calculation.

Parameters
jobLink graph job to calculate.

Definition at line 499 of file mcf.cpp.

Member Function Documentation

◆ EliminateCycle()

void MCF1stPass::EliminateCycle ( PathVector &  path,
Path cycle_begin,
uint  flow 
)
private

Eliminate a cycle of the given flow in the given set of paths.

Parameters
pathSet of paths containing the cycle.
cycle_beginPart of the cycle to start at.
flowFlow along the cycle.

Definition at line 377 of file mcf.cpp.

References Path::GetFlow(), Path::GetNode(), Path::GetParent(), MultiCommodityFlow::job, and Path::ReduceFlow().

Referenced by EliminateCycles().

◆ EliminateCycles() [1/2]

bool MCF1stPass::EliminateCycles ( )
private

Eliminate all cycles in the graph.

Check paths starting at each node for potential cycles.

Returns
If any cycles have been found and eliminated.

Definition at line 481 of file mcf.cpp.

Referenced by EliminateCycles().

◆ EliminateCycles() [2/2]

bool MCF1stPass::EliminateCycles ( PathVector &  path,
NodeID  origin_id,
NodeID  next_id 
)
private

Eliminate cycles for origin_id in the graph.

Start searching at next_id and work recursively. Also "summarize" paths: Add up the flows along parallel paths in one.

Parameters
pathPaths checked in parent calls to this method.
origin_idOrigin of the paths to be checked.
next_idNext node to be checked.
Returns
If any cycles have been found and eliminated.

Definition at line 408 of file mcf.cpp.

References Path::AddFlow(), EliminateCycle(), EliminateCycles(), FindCycleFlow(), Path::GetFlow(), Path::GetNode(), Path::GetOrigin(), Path::invalid_path, MultiCommodityFlow::job, and Path::ReduceFlow().

◆ FindCycleFlow()

uint MCF1stPass::FindCycleFlow ( const PathVector &  path,
const Path cycle_begin 
)
private

Find the flow along a cycle including cycle_begin in path.

Parameters
pathSet of paths that form the cycle.
cycle_beginPath to start at.
Returns
Flow along the cycle.

Definition at line 360 of file mcf.cpp.

References Path::GetFlow(), and Path::GetNode().

Referenced by EliminateCycles().


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