Module

LayeredLayout.NetworkSimplex

Package
purescript-layered-layout
Repository
markgrafhq/purescript-layered-layout

Generic Gansner-Koutsofios-North-Vo network simplex algorithm, shared between layer assignment and the post-routing graph compactor.

Port of ELK's org.eclipse.elk.alg.common.networksimplex.NetworkSimplex.

The algorithm is parameterised over the node identifier type (any Ord n) and accepts per-edge delta (minimum span) and weight (importance for shortness). Cutvalues are stored as Number (mirroring ELK's double) and compared against fuzzyStZero to track ELK's tolerance for floating-point imprecision.

Connected-component splitting and layer balancing are left to callers.

#NEdge Source

type NEdge n = { delta :: Int, eid :: Int, src :: n, tgt :: n, weight :: Number }

An edge for the network simplex algorithm.

  • delta – the minimum span (target.layer − source.layer ≥ delta).
  • weight – contribution to the optimisation objective. Network simplex minimises the weighted sum of weight * (layer span) across all edges, so heavier edges are kept shorter.
  • eid – a per-edge integer index, unique within the input array; the algorithm uses it as a key into cutvalue / visited sets.

#runNetworkSimplex Source

runNetworkSimplex :: forall n. Ord n => Array n -> Array (NEdge n) -> Map n Int

Run the network simplex over the given nodes and edges.

The caller is responsible for ensuring the input is weakly- connected (split into components, or inject an artificial root that dominates all sources). When the input is disconnected the algorithm still terminates, but the layering of the unreached component(s) is not optimised.

#fuzzyStZero Source

fuzzyStZero :: Number

Tolerance for floating-point imprecision when checking whether a cut value is negative. Port of ELK's FUZZY_ST_ZERO = -1e-10.