Skip to content
Snippets Groups Projects
Commit c6614ea0 authored by Radek Hušek's avatar Radek Hušek
Browse files

Add Gadget::swap and Gadget::permute

parent d683616e
Branches
No related tags found
No related merge requests found
......@@ -105,6 +105,22 @@ def _init_():
def is_graph(self):
return self._size == 0
def permute(self, p):
"""Permute the half-edges according to p."""
assert sorted(p) == list(range(1, self.size() + 1)), \
"p must be permutation of 1 .. size"
return Gadget.join([ self ], [], [ (1, i) for i in p ])
def swap(self, e1, e2):
"""Swap the half-edges e1 and e2."""
assert 1 <= e1 <= self.size() and 1 <= e2 <= self.size()
p = list(range(1, self.size() + 1))
p[e1 - 1] = e2
p[e2 - 1] = e1
return self.permute(p)
def __str__(self):
return "Gadget{%i}" % (self._size,)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment