Welsh, D.J.A. and Powell, M.B. (1967) An Upper Bound for the Chromatic Number of a Graph and Its Application to Timetabling Problems. 《The Computer Journal》, 10, 85-86.
《The Computer Journal》
1967年,Welsh和Powell算法引入了图色数的上界。它提供了一个在静态图上运行的贪婪算法。
顶点根据其度数排序,得到的贪婪着色最多使用颜色,最多比图的最大度数多一个。这种启发式被称为威尔士-鲍威尔算法。
威尔士鲍威尔算法:
- using System;
- using System.Collections;
- using System.Collections.Generic;
-
- namespace Legalsoft.Truffer.Algorithm
- {
- public class Vertex : IComparable<Vertex>
- {
- public int color { get; set; } = 0;
- public int degree { get; set; } = 0;
-
- public int CompareTo(Vertex o)
- {
- return o.degree - this.degree;
- }
- }
-
- public class Welch_Powell_Color
- {
- public void Welsh_Powell(int n, Vertex[] vertex, int[,] edges)
- {
- Array.Sort(vertex);
-
- int ncolor = 0;
- int colored_cnt = 0;
- while (colored_cnt < n)
- {
- ncolor++;
- for (int i = 1; i <= n; i++)
- {
- if (vertex[i].color == 0)
- {
- bool ok = true;
- for (int j = 1; j <= n; j++)
- {
- if (edges[i, j] == 1 && vertex[j].color == ncolor)
- {
- ok = false;
- break;
- }
- }
- if (!ok)
- {
- continue;
- }
-
- vertex[i].color = ncolor;
- colored_cnt++;
- }
- }
- }
- }
- }
- }