图论 - 色度指数

时间:2011-05-25 20:06:06

标签: algorithm graph-theory graph-algorithm

我必须制作一个程序,它会说图表是否可以着色 - 基本上我必须检查色度指数是d还是d + 1,其中d是所有顶点的最大度数(vizing定理)。我知道这个问题是NP完全的,基本上它必须是强制性的。我有一个想法,但不知道它是否正确 -

1)找到具有deg(v)= d的顶点,并用v与d区分颜色对所有边缘进行着色。

2)对于与v相邻的顶点入射的所有边,从d组颜色中应用一些颜色

3)重复2)“发现”边缘

如果所有边缘都用d颜色着色,则色度指数为d,我有一个图G的着色。

如果某些边缘无法使用d颜色设置的颜色进行着色,请使用d + 1-st颜色为颜色设置颜色,使用d + 1颜色设置颜色保留颜色 - 这是问题 - 使用此方案,如果我宣称该色度指数为d + 1,是否有可能与其他一些着色色度指数为d? (对于每个要着色的边缘,我选择一种可以使用的颜色)..

此外,哪个图形表示最适合此问题?在输入文件中,图形写在邻接矩阵中。我知道它可以通过递归来解决,但我不知道如何。我坚持一些过于复杂的想法:S(一些提示或伪代码将被赞赏)。

编辑:

刚刚发现我的想法,我觉得它应该没问题(纯粹的暴力)。我还没有尝试实现这个。如果你看错了,请评论。再说一遍 - 算法应检查图形是否可用d或d + 1颜色进行边缘着色,其中d是给定简单图形中所有顶点的最大度数,并找到一个着色...

colorEdge(edge, color, extra) {
    if (edge colored) return;  //if already colored, return
    if (can be colored in color) color it; //if color can be applied, apply it
    else {
        //else, 'd+1'-st color neded, so color it with that color, continue finding 
        //coloring with d+1 colors
        extra = true; 
        color it in color extra;
    }

    //recursivly try to color adjacent edges with available colors
    for each color c' from set of d colors {
        for each edge k adjacent to current {
            colorE(k, c', extra)
        }
    }
}

//main
bool extra = false;
for each color b from set of d colors {
    colorEdge(some starting edge, b, extra)
    if (!extra) break;
}

2 个答案:

答案 0 :(得分:2)

为每条边生成约束,为具有最多边的顶点的所有边指定不同的颜色,然后处理来自最受约束的边的每条边。

for each edge e1
for each edge e2
  if (e1 and e2 have a common vertex)
    e1.addConstaint(can't match e2's colour)
    e2.addConstaint(can't match e1's colour)

vertex v = vertex with most edges
if (v has more edges than colours we have available) STOP
assign each edge of v a different colour

Sort edges by number of constraints
Remove all edges connected to v (thus assigned a colour)

process(edge) :=
  while (haven't tried all colours within the constraints)
    edge.colour = next untried colour within the constraints
    process(next most constrained edge)

process(most constrained edge)

将最受约束的边缘定义为已经分配了颜色的边缘最多的边缘可能是一个好主意,但这可能会导致相当多的开销。

答案 1 :(得分:0)

转换图形以使用顶点着色算法非常简单:对于原始图形中的每条边(x,y),在变换后的图形中创建顶点 xy ,对于原始图形中的每个顶点 x ,在其名称中包含 x 的变换图形中的所有顶点之间创建边。

干杯