12 lines
534 B
Python
12 lines
534 B
Python
"""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
|