Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
trac #15622: Immutable graphs must not be relabeled
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanncohen committed Jan 2, 2014
1 parent c441178 commit 0f57805
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/sage/graphs/base/static_sparse_backend.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,22 @@ class StaticSparseBackend(CGraphBackend):
"""
return v in self._vertex_to_int

def relabel(self, perm, directed):
r"""
Relabel the graphs' vertices. No way.
TEST::
sage: from sage.graphs.base.static_sparse_backend import StaticSparseCGraph
sage: g = StaticSparseCGraph(graphs.PetersenGraph())
sage: g.relabel([],True)
Traceback (most recent call last):
...
ValueError: Thou shalt not remove a vertex from an immutable graph
"""
raise ValueError("Thou shalt not relabel an immutable graph")

def get_edge_label(self, object u, object v):
"""
Returns the edge label for ``(u,v)``.
Expand Down
15 changes: 12 additions & 3 deletions src/sage/graphs/generic_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -16386,7 +16386,7 @@ def relabel(self, perm=None, inplace=True, return_map=False, check_input = True,
sage: G.get_pos()
{0: (0, 0), 1: (2, 0), 2: (3, 0), 3: (4, 0)}

Check that #12477 is fixed::
Check that :trac:`12477` is fixed::

sage: g = Graph({1:[2,3]})
sage: rel = {1:'a', 2:'b'}
Expand All @@ -16395,17 +16395,26 @@ def relabel(self, perm=None, inplace=True, return_map=False, check_input = True,
[3, 'a', 'b']
sage: rel
{1: 'a', 2: 'b'}

Immutable graphs cannot be relabeled::

sage: Graph(graphs.PetersenGraph(), immutable=True).relabel({})
Traceback (most recent call last):
...
ValueError: Thou shalt not relabel an immutable graph
"""
from sage.groups.perm_gps.permgroup_element import PermutationGroupElement

if not inplace:
from copy import copy
G = copy(self)
G = self.copy(immutable=False)
perm2 = G.relabel(perm,
return_map= return_map,
check_input = check_input,
complete_partial_function = complete_partial_function)

if getattr(self, "_immutable", False):
G = self.__class__(G, immutable = True)

if return_map:
return G, perm2
else:
Expand Down

0 comments on commit 0f57805

Please sign in to comment.