Skip to content

Commit

Permalink
sagemathgh-38842: fix issue sagemath#38832 about canonical_label in…
Browse files Browse the repository at this point in the history
… bipartite graphs

    
Fixes sagemath#38832.

We fix call to `canonical_label` on `BipartiteGraph` when parameter
`partition` is `None`.
```py
sage: G = BipartiteGraph(matrix([[1, 1], [1, 1]]))
sage: C = G.canonical_label()
sage: C.left, C.right
({0, 1}, {2, 3})
```


### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [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.
- [x] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#38842
Reported by: David Coudert
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed Nov 2, 2024
2 parents 2eb694c + ddad107 commit f2780d8
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/sage/graphs/bipartite_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2633,11 +2633,26 @@ class by some canonization function `c`. If `G` and `H` are graphs,
sage: C.right
{4, 5, 6}
TESTS:
Check that :issue:`38832` is fixed::
sage: B = BipartiteGraph(matrix([[1, 1], [1, 1]]))
sage: B.canonical_label()
Bipartite graph on 4 vertices
sage: B.canonical_label(certificate=True)[0]
Bipartite graph on 4 vertices
sage: B.canonical_label(edge_labels=True)
Bipartite graph on 4 vertices
sage: B.allow_multiple_edges(True)
sage: B.add_edges(B.edges())
sage: B.canonical_label()
Bipartite multi-graph on 4 vertices
.. SEEALSO::
:meth:`~sage.graphs.generic_graph.GenericGraph.canonical_label()`
"""

if certificate:
C, cert = GenericGraph.canonical_label(self, partition=partition,
certificate=certificate,
Expand Down Expand Up @@ -2669,6 +2684,8 @@ class by some canonization function `c`. If `G` and `H` are graphs,
cert = {v: c[G_to[relabeling[v]]] for v in self}

else:
if partition is None:
partition = self.bipartition()
G_vertices = list(chain(*partition))
G_to = {u: i for i, u in enumerate(G_vertices)}
H = Graph(len(G_vertices))
Expand Down

0 comments on commit f2780d8

Please sign in to comment.