Repository navigation
graphs: pack arborescences beyond the edge connectivity - #42846
Merged
vbraun merged 6 commits intoSep 29, 2026
Merged
Conversation
…dges
[GKLP2021] initializes the forest T_k of the k-th iteration to a DFS
spanning forest of G \ T, that is, of the subgraph induced by the unused
edges. The implementation tested a boolean array T instead, which is only
ever given a value other than False in re_init, and always as
T[j] = (my_edge_state[j] != UNUSED)
so it holds nothing my_edge_state does not already hold. my_edge_state is
one of the arrays construct_trees swaps per direction; T was not, so the
DFS filtered on a copy made while exploring the other direction. On
digraphs with multiple edges that could return a wrong value, and on some
instances send the augmentation into an allocation loop, which is why the
initialization was disabled there.
Test my_edge_state directly. That is what the reference implementation
does, it is direction-correct by construction, and T, its allocation, its
initialisation and its maintenance in re_init can all go. The DFS is now
enabled for digraphs with multiple edges, where it is worth about 1.2x to
1.4x, and dropping two passes over m per call to re_init makes it faster
than before on large instances as well.
|
Documentation preview for this PR (built with commit 1b96595; changes) is ready! 🎉 |
Contributor
Author
|
Thanks for the review. I noticed this bug only later, while running some research experiments with the arborescence packing, and it did not occur to me to put the fix on the same branch as #42838. I can rebase this PR on top of #42838, or move the commit there and close this one, whichever you prefer. |
Collaborator
|
I think it should be on top of #42838 to ensure that all improvements/corrections are consistent |
GabowEdgeConnectivity.edge_disjoint_spanning_trees raised EmptySetError on valid inputs, and so did DiGraph.edge_disjoint_spanning_trees, which uses it by default since sagemathgh-42633: - when k exceeded the smallest indegree or outdegree over all vertices, as the per-tree data structures were sized by this bound; - when the digraph was not strongly connected, as __init__ returned before building the data structures. By Edmonds' branching theorem, the maximum number of arborescences rooted at r is the minimum r-cut, which is bounded by the outdegree of r and the indegrees of the other vertices only, and which requires every vertex to be reachable from r, not strong connectivity. The per-tree data structures are now sized by the largest such bound over all roots, the data structures are built for every nonempty digraph, and the packing checks the rooted degree bound and the reachability from the root. The output is unchanged on the inputs that were already supported.
ProfTR55
force-pushed
the
fix-gabow-arborescence-packing
branch
from
September 25, 2026 14:06
d6c0667 to
95c3448
Compare
Contributor
Author
|
Rebased on top of #42838, which is now listed as a dependency. |
dcoudert
approved these changes
Sep 26, 2026
4 of 5 tasks
vbraun
pushed a commit
to vbraun/sage
that referenced
this pull request
Oct 4, 2026
sagemathgh-42903: graphs: Return no path in edge_disjoint_paths when the target is unreachable `edge_disjoint_paths(s, t)` raises a misleading `ValueError` when `t` is not reachable from `s`: ``` sage: DiGraph([(0, 1)]).edge_disjoint_paths(1, 0) Traceback (most recent call last): ... ValueError: vertex '1' is not in the (di)graph ``` Vertex 1 is in the digraph, and the expected answer is `[]`. The flow graph returned by `flow(..., value_only=False)` only contains the edges carrying flow, so when the flow is 0 it does not contain `s`, and `shortest_path(s, t)` raises. This PR returns `[]` when the flow is 0, as `vertex_disjoint_paths` already does, and adds doctests for a digraph and for a disconnected graph. This was noticed in sagemath#42846. ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies None. URL: sagemath#42903 Reported by: Muhammet Doğukan Bingöl Reviewer(s): David Coudert
vbraun
pushed a commit
to vbraun/sage
that referenced
this pull request
Oct 6, 2026
sagemathgh-42903: graphs: Return no path in edge_disjoint_paths when the target is unreachable `edge_disjoint_paths(s, t)` raises a misleading `ValueError` when `t` is not reachable from `s`: ``` sage: DiGraph([(0, 1)]).edge_disjoint_paths(1, 0) Traceback (most recent call last): ... ValueError: vertex '1' is not in the (di)graph ``` Vertex 1 is in the digraph, and the expected answer is `[]`. The flow graph returned by `flow(..., value_only=False)` only contains the edges carrying flow, so when the flow is 0 it does not contain `s`, and `shortest_path(s, t)` raises. This PR returns `[]` when the flow is 0, as `vertex_disjoint_paths` already does, and adds doctests for a digraph and for a disconnected graph. This was noticed in sagemath#42846. ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies None. URL: sagemath#42903 Reported by: Muhammet Doğukan Bingöl Reviewer(s): David Coudert
vbraun
pushed a commit
to vbraun/sage
that referenced
this pull request
Oct 8, 2026
sagemathgh-42903: graphs: Return no path in edge_disjoint_paths when the target is unreachable `edge_disjoint_paths(s, t)` raises a misleading `ValueError` when `t` is not reachable from `s`: ``` sage: DiGraph([(0, 1)]).edge_disjoint_paths(1, 0) Traceback (most recent call last): ... ValueError: vertex '1' is not in the (di)graph ``` Vertex 1 is in the digraph, and the expected answer is `[]`. The flow graph returned by `flow(..., value_only=False)` only contains the edges carrying flow, so when the flow is 0 it does not contain `s`, and `shortest_path(s, t)` raises. This PR returns `[]` when the flow is 0, as `vertex_disjoint_paths` already does, and adds doctests for a digraph and for a disconnected graph. This was noticed in sagemath#42846. ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies None. URL: sagemath#42903 Reported by: Muhammet Doğukan Bingöl Reviewer(s): David Coudert
vbraun
pushed a commit
to vbraun/sage
that referenced
this pull request
Oct 11, 2026
sagemathgh-42903: graphs: Return no path in edge_disjoint_paths when the target is unreachable `edge_disjoint_paths(s, t)` raises a misleading `ValueError` when `t` is not reachable from `s`: ``` sage: DiGraph([(0, 1)]).edge_disjoint_paths(1, 0) Traceback (most recent call last): ... ValueError: vertex '1' is not in the (di)graph ``` Vertex 1 is in the digraph, and the expected answer is `[]`. The flow graph returned by `flow(..., value_only=False)` only contains the edges carrying flow, so when the flow is 0 it does not contain `s`, and `shortest_path(s, t)` raises. This PR returns `[]` when the flow is 0, as `vertex_disjoint_paths` already does, and adds doctests for a digraph and for a disconnected graph. This was noticed in sagemath#42846. ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies None. URL: sagemath#42903 Reported by: Muhammet Doğukan Bingöl Reviewer(s): David Coudert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GabowEdgeConnectivity.edge_disjoint_spanning_treesraisesEmptySetErroron digraphs that do contain the requested packing. Since #42633,DiGraph.edge_disjoint_spanning_treesuses this backend by default, so the public method is affected as well:The path itself is a spanning arborescence rooted at 0.
The complete digraph on
{0, ..., 4}packs 4 arborescences rooted at 0, and each one can take a distinct arc(i, 5).There are two causes:
max_ec, the smallest indegree or outdegree over all vertices, and anyk > max_ecwas rejected. By Edmonds' branching theorem, the maximum number of arborescences rooted atris the minimumr-cut. It is bounded only by the outdegree ofrand the indegrees of the other vertices, so it can exceedmax_ec: in the second example, vertex 5 has outdegree 1.__init__returned before building the data structures when the digraph is not strongly connected, whereas a packing only requires every vertex to be reachable from the root.This PR:
k=Nonestill returns that many arborescences;min_v len(D.edge_disjoint_paths(r, v))on random digraphs that need not be strongly connected.The output is unchanged on the inputs that were already supported. Besides the doctests, run with several random seeds, the change was checked on 1500 random digraphs, including multigraphs, digraphs with loops and digraphs that are not strongly connected. For every root, the packing reaches the minimum
r-cut and one more arborescence is rejected, and the packings are identical to those of the previous code wheneverkis at most the edge connectivity.Side note:
edge_disjoint_paths(s, t)raises aValueErrorinstead of returning[]whentis not reachable froms, so the randomized doctest calls it only when every vertex is reachable from the root. This can be fixed separately.📝 Checklist
⌛ Dependencies