Skip to content

graphs: Return no path in edge_disjoint_paths when the target is unreachable - #42903

Merged
vbraun merged 3 commits into
sagemath:developfrom
ProfTR55:fix-edge-disjoint-paths
Oct 11, 2026
Merged

vbraun merged 3 commits into
sagemath:developfrom
ProfTR55:fix-edge-disjoint-paths

Conversation

@ProfTR55

@ProfTR55 ProfTR55 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

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 #42846.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

None.

@dcoudert dcoudert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 4, 2026
Release Manager
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
Release Manager
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
Release Manager
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
vbraun merged commit 07f00f4 into sagemath:develop Oct 11, 2026
22 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants