Commit cd6516b
fix: add max iteration cap to label_propagation to prevent infinite loop
The synchronous label propagation algorithm can oscillate indefinitely
on bipartite or near-bipartite subgraphs, causing build_communities()
to hang with 100% CPU usage and no indication of failure.
Add a configurable max_iterations parameter (default: 30) to guarantee
termination. In practice, label propagation converges within 5-15
iterations on real-world graphs — if it hasn't converged by 30, it is
oscillating and the current approximation is returned.
Also adds debug/warning logging for convergence status.
Fixes #402
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 9d509a2 commit cd6516b
1 file changed
+14
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
97 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
98 | 103 | | |
99 | 104 | | |
100 | 105 | | |
101 | | - | |
| 106 | + | |
102 | 107 | | |
103 | 108 | | |
104 | 109 | | |
| |||
125 | 130 | | |
126 | 131 | | |
127 | 132 | | |
| 133 | + | |
128 | 134 | | |
129 | 135 | | |
130 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
131 | 142 | | |
132 | 143 | | |
133 | 144 | | |
| |||
0 commit comments