回溯法求解地图着色问题_使用回溯算法的图着色问题的解决方案

回溯法求解地图着色问题

图形着色 (Graph coloring)

The graph coloring problem is to discover whether the nodes of the graph G can be covered in such a way, that no two adjacent nodes have the same color yet only m colors are used. This graph coloring problem is also known as M-colorability decision problem.

图形着色问题是发现图形G的节点是否可以这样覆盖,即没有两个相邻节点具有相同的颜色,而仅使用m种颜色。 该图形着色问题也称为M可着色性决策问题。

The M – colorability optimization problem deals with the smallest integer m for which the graph G can be colored. The integer is known as a chromatic number of the graph.

M –可着色性优化问题涉及可对图形G进行着色的最小整数m。 该整数称为图的色数。

Here, it can also be noticed that if d is the degree of the given graph, then it can be colored with d+ 1 color.

在这里,还可以注意到,如果d是给定图的度数,则可以用d + 1颜色进行着色。

A graph is also known to be planar if and only if it can be drawn in a planar in such a way that no two edges cross each other. A special case is the 4 - colors problem for planar graphs. The problem is to color the region in a map in such a way that no two adjacent regions have the same color. Yet only four colors are needed. This is a problem for which graphs are very useful because a map can be easily transformed into a graph. Each region of the map becomes the node, and if two regions are adjacent, they are joined by an edge.

当并且仅当可以以没有两个边彼此交叉的方式在平面上绘制图形时,该图形也是平面的。 特殊情况是平面图的4色问题。 问题是要以一种没有两个相邻区域具有相同颜色的方式为地图中的区域着色。 但是只需要四种颜色。 对于图而言,这是一个非常有用的问题,因为可以轻松地将图转换为图。 地图的每个区域都将成为节点,如果两个区域相邻,则它们将通过一条边连接。

Graph coloring problem can also be solved using a state space tree, whereby applying a backtracking method required results are obtained.

图形着色问题也可以使用状态空间树来解决,从而应用回溯方法可以获得所需的结果。

For solving the graph coloring problem, we suppose that the graph is represented by its adjacency matrix G[ 1:n, 1:n], where, G[ i, j]= 1 if (i, j) is an edge of G, and G[i, j] = 0 otherwise.

为了解决图形着色问题 ,我们假设图形由其邻接矩阵G [1:n,1:n]表示 ,其中, 如果[i,j]是G的边,则G [i,j] = 1 ,否则G [i,j] = 0 。

The colors are represented by the integers 1, 2, ..., m and the solutions are given by the n-tuple (x1, x2, x3, ..., xn), where x1 is the color of node i.

颜色由整数1、2,...,m表示 ,解决方案由n元组( x1,x2,x3,...,xn )给出,其中x1是节点i的颜色。

查找图的m-色的算法。 (Algorithm for finding the m - colorings of a graph)

1.	Algorithm mcoloring ( k )
2.	// this algorithm is formed using the recursive backtracking 
3.	// schema. The graph is represented by its Boolean adjacency 
4.	// matrix G [1: n, 1: n]. All assignments of 1, 2, …, m to the 
5.	// vertices of the graph such that adjacent vertices are
6.	// assigned distinct are printed. K is the index 
7.	// of the next vertex to color.
8.	{
9.	Repeat
10.	{
11.	// generate all legal assignments for x[k],
12.	Next value (k); // assign to x[k] a legal color.
13.	 If ( x[k] = 0 ) then return; // no new color possible
14.	 If (k = n) then // at most m colors have been used to color the n vertices.
15.	  Write (x[1 : n ]);
16.	 Else mcoloring (k + 1);
17.	}
18.	Until (false);
19.	}

This algorithm uses the recursive backtracking schema. In this algorithm colors to be assigned are to determine from the range (0, m), i.e., m colors are available.

该算法使用递归回溯模式。 在该算法中,要分配的颜色是从范围(0,m)确定的,即m种颜色可用。

The total time required by the above algorithm is O (nm^n).

上述算法所需的总时间为O(nm ^ n)

翻译自: https://www.includehelp.com/algorithms/graph-coloring-problem-solution-using-backtracking-algorithm.aspx

回溯法求解地图着色问题

你可能感兴趣的:(算法,python,java,人工智能,动态规划)