This algorithm assigns a unique integer value known as its color to the vertices of a graph such that no neighboring vertices share the same color. The reason why this is called color is that this task is equivalent to assigning a color to each nation on a map so that no neighboring nations share the same color.
Given a set of k vertices, the algorithm first colors all vertices with the same color - the first color. It then starts from all the vertices and has each vertex send its own colors to its neighbors. If there are two neighboring vertices with the same color, the algorithm will reassign colors where there is a conflict. The same process is repeated until all conflicts are resolved.
The algorithm has a worst-case time complexity of O(V^2 + E), where V is the number of vertices and E is the number of edges.
On the social10 graph, say we want to color the Person
vertices in such a way that any two vertices that are either connected by a Friend
edge or a Coworker
edge do not have the same color. By running the greedy_graph_color
algorithm, we get the following result:
Name
Description
v_type
A set of all vertex types to color.
e_type
A set of all edge types to traverse.
max_colors
The Maximum number of colors that can be used. Use a large number like 999999 unless there is a strict limit.
print_color_count
If set to true, the total number of colors used will be displayed
display
If set to true, the output will display all vertices and their associated color
file_path
If a file path is provided, the output will be saved to the file indicated by the file path in CSV format.