Add sage code
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user