Replace plane_depth_labelling with plane_depth_sequencing paper and script, remove unused lib modules
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
"""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
|
||||
@@ -1,12 +0,0 @@
|
||||
"""Utilities for finding primal edges corresponding to dual edges."""
|
||||
from typing import Any, cast
|
||||
|
||||
def get_edge_for_dual_edge(dual_edge: Any) -> tuple[int, int, None]:
|
||||
"""Return the primal edge shared by both faces of the given dual edge."""
|
||||
edges: list[set[Any]] = []
|
||||
for e in (dual_edge[0] + dual_edge[1]):
|
||||
edge = set(e)
|
||||
if edge in edges:
|
||||
return cast(tuple[int, int, None], e)
|
||||
edges.append(edge)
|
||||
raise ValueError(f"Error finding edge for {dual_edge}")
|
||||
@@ -1,42 +0,0 @@
|
||||
"""Utilities for constructing edge graphs from planar graphs."""
|
||||
from typing import Any, cast
|
||||
from sage.all import Graph
|
||||
|
||||
|
||||
def get_edge_graph_pos(edge_graph: Graph, pos_src: dict[Any, Any]) -> dict[Any, tuple[Any, Any]]:
|
||||
"""Return a position dict for edge graph vertices, using midpoints of the source positions."""
|
||||
pos: dict[Any, tuple[Any, Any]] = {}
|
||||
for e in cast(list[Any], edge_graph.vertices()): # type: ignore
|
||||
pos[e] = (
|
||||
(pos_src[e[0]][0] + pos_src[e[1]][0]) / 2,
|
||||
(pos_src[e[0]][1] + pos_src[e[1]][1]) / 2
|
||||
)
|
||||
return pos
|
||||
|
||||
|
||||
def get_edge_graph(graph: Graph, set_pos: bool = True) -> Graph:
|
||||
"""Return the edge graph of the given graph, optionally setting vertex positions."""
|
||||
pos_src: dict[Any, Any] | None = None
|
||||
pos: dict[Any, tuple[Any, Any]] = {}
|
||||
if set_pos:
|
||||
pos_src = cast(dict[Any, Any], graph.get_pos()) # type: ignore
|
||||
|
||||
g = Graph()
|
||||
for e in cast(list[Any], graph.edges()): # type: ignore
|
||||
g.add_vertex(e) # type: ignore
|
||||
if pos_src:
|
||||
pos[e] = (
|
||||
(pos_src[e[0]][0] + pos_src[e[1]][0]) / 2,
|
||||
(pos_src[e[0]][1] + pos_src[e[1]][1]) / 2
|
||||
)
|
||||
|
||||
for v in cast(list[Any], graph.vertices()): # type: ignore
|
||||
incident_edges = cast(list[Any], graph.edges_incident(v)) # type: ignore
|
||||
if len(incident_edges) == 1:
|
||||
continue
|
||||
for i, e1 in enumerate(incident_edges):
|
||||
e2 = incident_edges[(i + 1) % len(incident_edges)]
|
||||
g.add_edge(e1, e2) # type: ignore
|
||||
if set_pos:
|
||||
g.set_pos(pos) # type: ignore
|
||||
return g
|
||||
@@ -1,18 +0,0 @@
|
||||
"""Utilities for computing Tait colorings from vertex colorings of the dual graph."""
|
||||
from typing import Any, cast
|
||||
from sage.all import Graph
|
||||
from lib.edge_for_dual_edge import get_edge_for_dual_edge
|
||||
|
||||
def get_tait_coloring(planar_dual: Graph, coloring: dict[Any, int]) -> dict[Any, int]:
|
||||
"""Return a Tait (edge 3-coloring) from a vertex 4-coloring of the dual graph."""
|
||||
tait_coloring: dict[Any, int] = {}
|
||||
for dual_edge in cast(list[Any], planar_dual.edges()): # type: ignore
|
||||
edge = get_edge_for_dual_edge(dual_edge)
|
||||
colors = {coloring[edge[0]], coloring[edge[1]]}
|
||||
if colors in ({0, 1}, {2, 3}):
|
||||
tait_coloring[dual_edge] = 0
|
||||
elif colors in ({1, 2}, {0, 3}):
|
||||
tait_coloring[dual_edge] = 1
|
||||
else:
|
||||
tait_coloring[dual_edge] = 2
|
||||
return tait_coloring
|
||||
@@ -1,11 +0,0 @@
|
||||
"""Utilities for verifying vertex colorings."""
|
||||
from typing import Any, cast
|
||||
from sage.all import Graph
|
||||
|
||||
def check_vertex_coloring(graph: Graph, vertex_coloring: dict[Any, int]) -> bool:
|
||||
"""Raise ValueError if any two adjacent vertices share a color."""
|
||||
for v in cast(list[Any], graph.vertices()): # type: ignore
|
||||
for nv in cast(list[Any], graph.neighbors(v)): # type: ignore
|
||||
if vertex_coloring[nv] == vertex_coloring[v]:
|
||||
raise ValueError(f"Color {nv} equal to color {v}")
|
||||
return True
|
||||
Reference in New Issue
Block a user