Skip to content

Commit

Permalink
Reduce renumbering/reorienting done by simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanDunfield committed Nov 25, 2024
1 parent d52c517 commit cb14c73
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 11 additions & 1 deletion spherogram_src/links/links_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,15 @@ def _build(self, start_orientations=None, component_starts=None):

def _rebuild(self, same_components_and_orientations=False):
if same_components_and_orientations:
start_css = [comp[0] for comp in self.link_components]
# Hopefully we have enough of the original components left
# to figure out what this is. Otherwise, new choices will
# be made as in the default algorithm.
start_css = []
for comp in self.link_components:
for cs in comp:
if cs.crossing in self.crossings:
start_css.append(cs)
break
self.link_components = None
for c in self.crossings:
c._clear()
Expand Down Expand Up @@ -758,6 +766,8 @@ def _orient_crossings(self, start_orientations=None):
return
if start_orientations is None:
start_orientations = list()
else: # copy as algorithm modifies this list
start_orientations = list(start_orientations)
remaining = OrderedSet(
[(c, i) for c in self.crossings for i in range(4) if c.sign == 0])
while len(remaining):
Expand Down
5 changes: 3 additions & 2 deletions spherogram_src/links/simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def simplify_via_level_type_III(link, max_consecutive_failures=100):
else:
failures += 1

link._build_components()
assert link.all_crossings_oriented()
link._rebuild(True)
return success


Expand Down Expand Up @@ -820,5 +821,5 @@ def pickup_simplify(link, type_III=0):
# twists. We check for this only once, at the end, for speed.
untwist_diagram(L)

L._rebuild()
L._rebuild(True)
return len(L.crossings) != init_num_crossings

0 comments on commit cb14c73

Please sign in to comment.