You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gh-40110: Fix "NotImplementedError: an immutable graph does not change name"
Certain methods related to TSP (Travelling salesman problem) fail on
immutable graphs:
```sage
sage: Graph('EJ~w', immutable=True).longest_cycle().order()
NotImplementedError: an immutable graph does not change name
sage: graphs.ChvatalGraph().copy(immutable=True).is_hamiltonian()
NotImplementedError: an immutable graph does not change name
```
This PR fixes this by setting the `_name` attribute directly instead of
setting it via [`name()`](https://doc-develop--sagemath.netlify.app/html
/en/reference/graphs/sage/graphs/generic_graph.html#sage.graphs.generic_
graph.GenericGraph.name).
Another fix would be to allow changing the name of immutable graphs by
removing these two lines from `name()`:
```py
if self.is_immutable():
raise NotImplementedError("an immutable graph does not change name")
```
This check was introduced in #15681 and [has bitten us in the past](http
s://github.com/sagemath/sage/commit/82f6e161dfedebdc31d09f507a0686f5bf15
c10a). While it seems counterintuitive for *immutable* graphs to have
mutable attributes, the `_embedding` attribute can already be mutated
via `set_embedding()`.
### 📝 Checklist
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.
URL: #40110
Reported by: Lennard Hofmann
Reviewer(s): David Coudert
0 commit comments