当前位置: 首页 > news >正文

C#,图论与图算法,图着色问题(Graph Coloring)的威尔士-鲍威尔(Welch Powell Algorithm)算法与源代码

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》

1 图着色算法概述

1967年,Welsh和Powell算法引入了图色数的上界。它提供了一个在静态图上运行的贪婪算法。

顶点根据其度数排序,得到的贪婪着色最多使用颜色,最多比图的最大度数多一个。这种启发式被称为威尔士-鲍威尔算法。

2 伪代码

威尔士鲍威尔算法:

  1. 求每个顶点的阶数。
  2. 按降价顺序列出顶点,即价度(v(i))>=度(v(i+1))。
  3. 为列表中的第一个顶点上色。
  4. 沿着已排序的列表向下,为每个未连接到相同颜色上方的有色顶点着色,然后划掉列表中的所有有色顶点。
  5. 对未着色的顶点重复此过程,使用新颜色始终按度数降序操作,直到所有顶点都按度数降序操作,直到所有顶点都着色为止。

3 源程序

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++;}}}}}
}
http://www.lryc.cn/news/317973.html

相关文章:

  • 用python写一个脚本,实现加速3X并压缩mp4视频以降低文件大小。
  • Flink广播流 BroadcastStream
  • IP数据报格式
  • GET https://registry.npm.taobao.org/xxxx error (CERT_HAS_EXPIRED)解决
  • SSM Java Web项目由于spring-mvc.xml配置不对带来的一系列问题
  • MySQL事务隔离
  • Java基础知识总结(1)
  • 脚手架原理之webpack处理html文件和模块打包
  • Winform编程详解一:Form窗口
  • Windows Server 2025 Install Preview
  • 四、MySQL
  • C#使用泛型自定义的方法设计队列CQueue<T>类
  • IDEA自定义Maven仓库
  • Codeql复现CVE-2018-11776学习笔记
  • CVE-2024-27199 JetBrains TeamCity 身份验证绕过漏洞2
  • ms office学习记录12:Excel学习记录㈥
  • 基于YOLOv8/YOLOv7/YOLOv6/YOLOv5的条形码二维码检测系统(深度学习+UI界面+训练数据集+Python代码)
  • npm yarn 一起使用报错
  • 基于springboot实现驾校信息管理系统项目【项目源码+论文说明】计算机毕业设计
  • DXP软件界面显示“No Hard Devices”【简单的操作问题】加【软件下载】
  • 通过Spring Boot 实现页面配置生成动态接口?
  • 【数据结构与算法】:插入排序与希尔排序
  • 前端性能优化——javascript
  • Docker容器化技术(使用Docker搭建论坛)
  • C# ListView 控件使用
  • 【string一些函数用法的补充】
  • 【Go】令牌桶限流算法
  • go的slice学习
  • 软件设计师17--磁盘管理
  • 学点Java打小工——Day2Day3一点作业