Add sage code

This commit is contained in:
2026-04-15 20:23:44 -04:00
parent c2298339ce
commit fc277760af
10 changed files with 273 additions and 1 deletions
+11
View File
@@ -0,0 +1,11 @@
"""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