Add sage code
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"""Utilities for working with planar dual graphs."""
|
||||
from typing import Any
|
||||
from sage.all import Graph
|
||||
|
||||
|
||||
def find_vertex_for_dual_face(dual_face: Any) -> Any | None:
|
||||
"""Return the primal vertex shared by all faces in the dual face, or None."""
|
||||
shared_vertices = None
|
||||
for dual_edge in dual_face:
|
||||
vertices = set(map(lambda e: e[0], dual_edge[0]))
|
||||
if shared_vertices:
|
||||
shared_vertices.intersection_update(vertices)
|
||||
else:
|
||||
shared_vertices = vertices
|
||||
if len(shared_vertices) == 1:
|
||||
return shared_vertices.pop()
|
||||
return None
|
||||
|
||||
|
||||
def _dual_edge_has_vertex(dual_edge: Any, vertex: Any) -> bool:
|
||||
return any(vertex in edge for dual_vertex in dual_edge for edge in dual_vertex)
|
||||
|
||||
|
||||
def find_dual_face_for_removed_vertex(planar_dual: Graph, vertex: Any) -> Any | None:
|
||||
"""Return the dual face of length 5 whose every dual edge contains the given vertex."""
|
||||
for dual_face in list[Any](planar_dual.faces()): # type: ignore[call-arg]
|
||||
if len(dual_face) == 5 and all(_dual_edge_has_vertex(de, vertex) for de in dual_face):
|
||||
return dual_face
|
||||
return None
|
||||
Reference in New Issue
Block a user