OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
openswmm::toposort Namespace Reference

Functions

int sortLinks (const int *node1, const int *node2, int n_links, int n_nodes, std::vector< int > &sorted_links, const int *divert_link=nullptr)
 Sort links in topological (upstream→downstream) order.
 

Function Documentation

◆ sortLinks()

int openswmm::toposort::sortLinks ( const int * node1,
const int * node2,
int n_links,
int n_nodes,
std::vector< int > & sorted_links,
const int * divert_link = nullptr )

Sort links in topological (upstream→downstream) order.

Uses Kahn's algorithm with CSR adjacency from node1/node2. Returns the number of sorted links. If < n_links, a cycle exists.

Parameters
node1[in] Upstream node index per link.
node2[in] Downstream node index per link.
n_linksNumber of links.
n_nodesNumber of nodes.
sorted_links[out] Topologically sorted link indices.
divert_link[in] Optional, per node: the index of that node's DIVERSION link when the node is a 2-outlet divider, else -1. Legacy adjustAdjList (toposort.c:191-217) swaps a divider's two outgoing links so the NON-diversion one is routed first — divider_getOutflow gives the diversion link qIn - Node.outflow, i.e. only what the other link left behind, so the wrong order sends the node's whole inflow down BOTH links. Pass nullptr to skip the adjustment.
Returns
Number of sorted links (< n_links indicates cycle).
Here is the caller graph for this function: