图论-色指数

发布于 2024-11-09 21:12:37 字数 1413 浏览 0 评论 0原文

我必须编写一个程序来说明图形是否可着色 - 基本上我必须检查色索引是 d 还是 d+1,其中 d 是所有顶点的最大度数(维辛定理)。我知道这个问题是 NP 完全问题,基本上必须通过暴力破解。我有一个想法,但不知道它是否正确 -

1)找到 deg(v) = d 的顶点,并将与 v 相关的所有边用 d 不同的颜色着色。

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

3) 对于“发现的”边重复 2)

如果所有边都用 d 种颜色着色,则色度索引为 d 并且 i 有一种着色图 G 的。

如果某些边不能用 d 组颜色中的颜色着色,则用 d+1 种颜色为他着色,并用 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;
}

I have to make a program which will say if graph is d colorable or not - basically i have to check if chromatic index is d or d+1, where d is max degree of all vertices (vizing's theorem). I know this problem is NP-complete and basically it has to be bruteforced. I had an idea but don't know if it is correct -

1) find vertex with deg(v) = d and color all edges incident with v with d distnict colors.

2) for all edges incident with vertices which are adjacent to v, apply some color from set of d colors

3) repeat 2) for "discovered" edges

If all edges are colored with d colors, chromatic index is d and i have one coloring of graph G.

If some edge can't be colored with color from set of d colors, color him with d+1-st color and color remaining edges with colors from set of d+1 colors - here is the question - using this scheme, if i proclaim that chromatic index to be d+1, is there a chance that with some other coloring chromatic index would be d? (for every edge that is going to be colored I'm choosing one color which can be used)..

Also, which graph representation would be best for this problem? In input file graph is written in adjacency matrix. i know it can be solved with recursion, but I don't have an idea how. I'm stuck with some too complicated ideas :S (some hint or pseudocode would be appreciated).

Edit:

Just came across my mind, I think it should be ok (pure bruteforce). I didnt try to implement this yet. Please comment if you see something wrong. Just to say again - algorithm should check whether graph is edge colorable with d or d+1 colors where d is max degree of all vertices in given simple graph, and to find one coloring...

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

┾廆蒐ゝ 2024-11-16 21:12:37

为每条边生成约束,为具有最多边的顶点的所有边分配不同的颜色,然后从受约束最多的边开始处理每条边。

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)

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

Generate constraints for each edge, assign different colours to all edges of the vertex with the most edges and then process each edges from the most constrained edge.

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)

It may be a good idea to defined the most constrained edge as the one with the most surrounding edges that have already been assigned colours, but this could cause quite a bit of overhead.

浮生面具三千个 2024-11-16 21:12:37

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

干杯

transforming your graph to use the vertex coloring algorithm is quite straightforward: for each edge (x,y) in the original graph create a vertex xy in the transformed graph, and for each vertex x in the original graph create edges between all vertices in the transformed graph containing x in their name.

Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文