Используя сервер ограничений MiniZin c, вы можете express довольно легко решить такую проблему:
% Petersen Graph
set of int: Colors = 1..3;
set of int: Nodes = 1..10;
set of int: Edges = 1..15;
array[Edges] of Nodes: aFrom = [ 1, 2, 3, 4, 1, 1, 2, 3, 4, 5, 6, 7, 7, 8, 6 ];
array[Edges] of Nodes: aTo = [ 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 8, 10, 9, 10, 9 ];
array[int] of string: colorName = [ "red", "green", "blue", "purple", "yellow", "brown", "black" ];
array[Nodes] of var Colors: nodeColor;
constraint
forall(e in Edges) (
nodeColor[aFrom[e]] != nodeColor[aTo[e]]
);
solve satisfy;
output [ show(colorName[nodeColor[n]]) ++ "\n" | n in Nodes ];
Чтобы определить минимальное количество цветов, вы можете уменьшить Colors
пока решение не найдено.