-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
揭开图着色算法的神秘面纱 #7946
揭开图着色算法的神秘面纱 #7946
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有一些翻译有小小问题,如边着色翻译为边缘着色,总感觉很奇怪,不过总体还是不错哒~!🍻
|
||
![Photo by [salvatore ventura](https://unsplash.com/@salvoventura?utm_source=medium&utm_medium=referral) on [Unsplash](https://unsplash.com?utm_source=medium&utm_medium=referral)](https://cdn-images-1.medium.com/max/12032/0*nMi_GsBxeMO5LlkM) | ||
|
||
Graph coloring is a problem where certain colors are assigned to a particular constraint in a graph. For instance, it could be that you must color a graph, either vertices or edges, so that no two identical colors are adjacent to each other — no two adjacent vertices or edges will have the same color. | ||
图着色是指将特定的颜色按照特定约束条件在图中分配的问题。例如,你必须为一个图形着色,无论是顶点还是边,而且不会有两个相同的颜色相邻——没有两个相邻的顶点或边会有相同的颜色。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
图着色是指将特定的颜色按照特定约束条件在图中分配的问题。例如,你必须为一个图形着色,无论是顶点还是边,而且不会有两个相同的颜色相邻——没有两个相邻的顶点或边会有相同的颜色。 | |
图着色是指将特定的颜色按照约束条件(相邻任意两个部分的颜色不能相同)在图中分配的问题。要进行图着色算法,你必须先为一个图形着色,要么是上色顶点或是上色图的边,并且需要保证不存在两个相邻的部分有相同的颜色 —— 没有两个相邻的顶点或边会有相同的颜色。 |
|
||
I stumbled upon this algorithm and I was thinking about what its purpose was. As I look more deeply into graph coloring problems and their use cases, I realized that they’re widely used in the applications we use. This article will briefly talk about this algorithm and use cases of graph coloring. | ||
我偶然发现了这个算法,我在想它的目的是什么。当我更深入地研究图着色问题以及实际使用时,我意识到它在我们使用的应用程序中有着广泛的应用。本文将简要介绍这种算法和图着色实例。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我偶然发现了这个算法,我在想它的目的是什么。当我更深入地研究图着色问题以及实际使用时,我意识到它在我们使用的应用程序中有着广泛的应用。本文将简要介绍这种算法和图着色实例。 | |
我是在偶然间发现了这个算法,我在想它的应用上的作用是什么。当我更深入地研究图着色问题以及实际使用时,我意识到它在我们使用的应用程序中有着广泛的应用。本文将简要介绍这种算法和图着色实例。 |
|
||
There are many ways of graph coloring problems. You can do [vertex coloring](https://mathworld.wolfram.com/VertexColoring.html#:~:text=A%20vertex%20coloring%20is%20an,colors%20for%20a%20given%20graph.), edge coloring, and geographic [map coloring](https://en.wikipedia.org/wiki/Map_coloring#:~:text=Map%20coloring%20is%20the%20act,different%20features%20on%20a%20map.&text=The%20second%20is%20in%20mathematics,features%20have%20the%20same%20color.). There are different questions you can ask in this algorithm. For instance, we can answer the questions of not assigning the same resources dependent on each other at the same time. We can also answer the questions of what is the minimum number of colors needed to color this graph. Moreover, we can make this into a backtracking question, where we want to find all possible coloring methods that can color this graph. | ||
解决图着色问题的方法有很多。你可以做[顶点着色](https://mathworld.wolfram.com/VertexColoring.html#:~:text=A%20vertex%20coloring%20is%20an,colors%20for%20a%20given%20graph.)、边缘着色和[地图着色](https://en.wikipedia.org/wiki/Map_coloring#:~:text=Map%20coloring%20is%20the%20act,different%20features%20on%20a%20map.&text=The%20second%20is%20in%20mathematics,features%20have%20the%20same%20color.)。在这个算法中,你可以思考不同的问题。例如,我们可以解决不同时分配彼此依赖的相同资源的问题。我们也可以解决这样的问题:为这个图上色所需的最小颜色数是多少。此外,我们可以把它变成一个回溯问题,我们想找到所有可能的着色方法,可以着色这个图。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
解决图着色问题的方法有很多。你可以做[顶点着色](https://mathworld.wolfram.com/VertexColoring.html#:~:text=A%20vertex%20coloring%20is%20an,colors%20for%20a%20given%20graph.)、边缘着色和[地图着色](https://en.wikipedia.org/wiki/Map_coloring#:~:text=Map%20coloring%20is%20the%20act,different%20features%20on%20a%20map.&text=The%20second%20is%20in%20mathematics,features%20have%20the%20same%20color.)。在这个算法中,你可以思考不同的问题。例如,我们可以解决不同时分配彼此依赖的相同资源的问题。我们也可以解决这样的问题:为这个图上色所需的最小颜色数是多少。此外,我们可以把它变成一个回溯问题,我们想找到所有可能的着色方法,可以着色这个图。 | |
现实中存在许多与图着色问题相关的问题,你可以使用[顶点着色](https://mathworld.wolfram.com/VertexColoring.html#:~:text=A%20vertex%20coloring%20is%20an,colors%20for%20a%20given%20graph.)、边着色或[地图着色](https://en.wikipedia.org/wiki/Map_coloring#:~:text=Map%20coloring%20is%20the%20act,different%20features%20on%20a%20map.&text=The%20second%20is%20in%20mathematics,features%20have%20the%20same%20color.)解图着色问题。在这个算法中,你可以思考各种不同类型的问题。例如,我们可以解决不同时分配彼此依赖的相同资源的问题。我们也可以解决这样的问题:为这个图上色所需的最小颜色数是多少。此外,我们可以把它变成一个回溯问题,在这个问题中我们希望找到所有可能的着色方法可以着色这个图。 |
|
||
Let’s assume it’s vertex coloring, where I want to color the graph so that no two adjacent vertices have the same color. | ||
我们假设这是顶点着色,我想给图形着色,这样相邻的两个顶点就不会有相同的颜色。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们假设这是顶点着色,我想给图形着色,这样相邻的两个顶点就不会有相同的颜色。 | |
我们假设这是顶点着色问题,那么如果我想给图形着色,相邻的两个顶点将不会有相同的颜色。 |
|
||
![](https://cdn-images-1.medium.com/max/2000/0*dX9rqaI1V_1bvgv2.png) | ||
|
||
Next, we can start coloring the first vertex on a blank graph. You can choose any random one — it doesn’t matter. | ||
接下来,开始在一个空白图的第一个顶点上色。你可以随便选一个。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
接下来,开始在一个空白图的第一个顶点上色。你可以随便选一个。 | |
接下来,开始在一个空白图的任意一个顶点作为第一个顶点进行上色操作。 |
|
||
A compiler is a program that transforms source code from high-level (Java, Scala) to machine level code. This is usually done in separate steps. One of the very last steps is to allocate registers to the most frequent values of the programs while putting other ones in memory. We can model the symbolic registers (variables) as vertices, and an edge is formed if two variables are needed simultaneously. If the graph can be colored in K color, then the variables can be stored in k registered. | ||
编译器是将源代码从高级(Java、Scala)转换成机器代码的程序。这通常是分步骤进行的,最后一步是将寄存器分配给程序中最常用的值,同时将其它值放入内存。我们可以将符号寄存器(变量)建模为顶点,如果同时需要两个变量,则形成一条边。如果该图可以用 K 色进行着色,那么变量可以存储在 k 寄存器中。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
编译器是将源代码从高级(Java、Scala)转换成机器代码的程序。这通常是分步骤进行的,最后一步是将寄存器分配给程序中最常用的值,同时将其它值放入内存。我们可以将符号寄存器(变量)建模为顶点,如果同时需要两个变量,则形成一条边。如果该图可以用 K 色进行着色,那么变量可以存储在 k 寄存器中。 | |
编译器是将源代码从高级语言(Java、Scala)转换成机器代码的程序。这通常是分步骤进行的,最后一步是将寄存器分配给程序中最常用的值,同时将其它值放入内存。我们可以将符号寄存器(变量)建模为顶点,如果同时需要两个变量,则形成一条边。如果该图可以用 K 色进行着色,那么变量可以存储在 k 寄存器中。 |
@PassionPenguin @lsvih 感谢校对,已完成修改! |
@lsvih label给错了吧( $ lint-md --config ../lint-md/config.json /Users/penguin/Downloads/demystify-graph-coloring-algorithms.md
Lint total 1 files, 0 warnings 0 errors |
@lsvih 校对认领 |
@flashhu 好的 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
I stumbled upon this algorithm and I was thinking about what its purpose was. As I look more deeply into graph coloring problems and their use cases, I realized that they’re widely used in the applications we use. This article will briefly talk about this algorithm and use cases of graph coloring. | ||
我是在偶然间发现了这个算法,我在想它的应用上的作用是什么。当我更深入地研究图着色问题以及实际使用时,我意识到它在我们使用的应用程序中有着广泛的应用。本文将简要介绍这种算法和图着色实例。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我在想它的应用上的作用是什么 => 并思考如何应用它
|
||
![](https://cdn-images-1.medium.com/max/2000/0*dX9rqaI1V_1bvgv2.png) | ||
|
||
Next, we can start coloring the first vertex on a blank graph. You can choose any random one — it doesn’t matter. | ||
接下来,开始在一个空白图的任意一个顶点作为第一个顶点进行上色操作。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
开始在一个空白图的任意一个顶点作为第一个顶点进行上色操作 => 在一个空白图中将任意一个顶点作为第一个顶点进行上色操作
3. Loop through the other vertices, assign the vertices a color if only if 1. It is **not** the adjacent of the vertex A. 2. The vertices have not yet been colored. 3. That vertex’s neighbor doesn’t have the same color as vertex A. | ||
4. Keep doing step 3 until all the vertices are colored. | ||
1. 计算每个顶点的入边,并按降序排列它们。 | ||
2. 选择顺序最接近的第一个顶点,然后分配一种颜色给顶点——我们称其为顶点 A。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
选择顺序最接近的第一个顶点,然后分配一种颜色给顶点 => 选择最多入边的顶点作为第一个顶点,并为其分配颜色
|
||
Another example is making a schedule or time table. You want to make an exam scheduler. Each subject will have a list of students and each student will take multiple classes. You want to make sure that the exams that you schedule don’t conflict with each other. In this case, the vertices can be classes, and there are edges between two classes if the same student is in both classes. The color in the graph, in this case, will be the number of time slots needed to schedule the exams. So, the same color on vertex A and vertex B means that A and B will be conducted in the same time slot. | ||
另一个例子是制定日程表或时间表。你想做一个考试日程安排,每个科目都有一份学生名单,每个学生都要上多节课。你要确保安排的考试不会相互冲突。在这种情况下,顶点可以是课程,如果两个课程中都有相同的学生,则两个课程之间会有边。在这种情况下,图的颜色将是安排考试所需的时隙数。因此,顶点 A 和顶点 B 上的相同颜色意味着 A 和 B 将在同一时隙中进行。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在这种情况下,图的颜色将是安排考试所需的时隙数。因此,顶点 A 和顶点 B 上的相同颜色意味着 A 和 B 将在同一时隙中进行。 => 在这种情况下,图的颜色将是安排考试所需的时间段总数。因此,顶点 A 和顶点 B 上的相同颜色意味着 A 和 B 将在同一时间段中进行。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此行将 time slot 翻为时隙,后一行将 time slot 翻为时间段,可能需要统一一下
@zenblo 已经 merge 啦~ 快快麻溜发布到掘金然后给我发下链接,方便及时添加积分哟。 掘金翻译计划有自己的知乎专栏,你也可以投稿哈,推荐使用一个好用的插件。 |
收到 |
@lsvih 译文翻译完成,resolve #7915