图着色算法的实现

时间:2017-02-25 11:28:50

标签: algorithm graph graph-coloring

我开始知道图形着色算法是NP-Complete问题。不过,我想知道是否可以使用启发式方法实现任何实现,尤其是区分图着色?如果可能,那么有没有合适的资源来了解这一点?

1 个答案:

答案 0 :(得分:1)

正如有些related post所述:

MiniZinc这样的约束求解器能够解决各种图形着色问题。

MiniZinc示例演示了Petersen graph的着色:

%  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 ];