d2layouts/d2talalayout/internal/hierarchy/NETWORK_SIMPLEX.md
rankDAG solves the integer program
minimize sum(weight(e) * (rank(head(e)) - rank(tail(e))))
subject to rank(head(e)) - rank(tail(e)) >= 1
for a connected simple DAG. Authored hierarchy weights are retained as the objective coefficients.
The implementation follows the graphical network-simplex ranker in section 2.3 of Gansner, Koutsofios, North, and Vo, A Technique for Drawing Directed Graphs, IEEE Transactions on Software Engineering 19(3), 1993:
The optional crowd-balancing pass in the paper is not part of this ranker. It changes which optimum is selected without improving the weighted-span objective.
Nodes are ordered by stable node ID and pivot candidates by stable edge ID. For degenerate zero-shift exchanges, the smallest-ID negative-cut tree edge is chosen first and minimum-slack entering ties use the smallest edge ID. This is the finite pivot ordering from Robert G. Bland, New Finite Pivoting Rules for the Simplex Method, Mathematics of Operations Research 2(2), 1977. There is no topology-independent pivot cap; the shared optimization work guard bounds work and polls cancellation.
At termination, each tree cut value is the unique flow on that tight tree edge that satisfies the node supplies induced by all authored edge weights. The ranker verifies that these flows are nonnegative, recomputes every node balance, and compares the resulting dual value with an independently computed primal weighted-span value. Equality certifies exact optimality.
All rank, slack, cut, flow, and objective arithmetic uses checked int64
operations. Validation and result construction preserve the public error and
normalization contracts used by the hierarchy pipeline.