kirchhoff_cycle_basis.hpp file
Fundamental-cycle builder for the loop-flow KVL formulation.
Pure-graph utilities for the cycle-basis (loop-flow) Kirchhoff Voltage Law formulation. No LP / SystemContext / LineLP coupling — this module knows about edges and buses only. The PR 2b LP integration layer (kirchhoff::cycle_basis::add_kvl_rows, system- level dispatch in system_lp.cpp) consumes the output of build_fundamental_cycles and stamps the per-cycle KVL rows.
Algorithm: BFS spanning tree per connected component (island). Each non-tree (co-tree) edge closes exactly one fundamental cycle — the unique simple cycle obtained by adding that edge to the tree. For a connected graph with |B| buses and |L| edges, this yields |L| − |B| + 1 cycles; with k islands, |L| − |B| + k cycles.
The sign of each edge in a cycle is determined by traversal orientation: +1 if the cycle traversal direction matches the edge's bus_a → bus_b orientation, −1 otherwise. This matches PyPSA's find_cycles convention (pypsa/network/power_flow.py:find_cycles).
Parallel edges (two or more edges between the same pair of buses) are handled correctly: BFS picks one as a tree edge; each remaining parallel edge becomes a co-tree edge whose fundamental cycle is the 2-edge loop formed with the tree edge.
Reference: Hörsch, Hofmann, Schlachtberger, Brown, "PyPSA: Python for Power System Analysis", J. Open Research Software 6(1), 2018.
Namespaces
- namespace gtopt
- namespace gtopt::kirchhoff
- namespace gtopt::kirchhoff::cycle_basis