Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Assign colors to edges of a graph so that no two adjacent edges have the same color
ResourceFunction["EdgeColoring"][g] gives an edge coloring of graph g. |
Get a sample graph:
In[1]:= |
Out[1]= |
Group edges of a graph so that no group contains adjacent edges:
In[2]:= |
Out[2]= |
Highlight edges in the groups:
In[3]:= |
Out[3]= |
Use the specified set of colors:
In[4]:= |
Out[4]= |
In[5]:= |
Out[5]= |
EdgeColoring works with undirected graphs:
In[6]:= |
Out[6]= |
Directed graphs:
In[7]:= |
Out[7]= |
Multigraphs:
In[8]:= |
Out[8]= |
Mixed graphs:
In[9]:= |
Out[9]= |
By default, EdgeColoring uses Brelaz's heuristic, which does not necessarily give the minimum coloring:
In[10]:= |
Out[10]= |
In[11]:= |
Out[11]= |
In this case, a 6-coloring is produced:
In[12]:= |
Out[12]= |
The minimum coloring should use only five colors, as given by the chromatic number of the graph:
In[13]:= |
Out[13]= |
Obtain a minimum coloring using Method→"Optimum":
In[14]:= |
Out[14]= |
In[15]:= |
Out[15]= |
In[16]:= |
Out[16]= |
EdgeColoring returns a proper edge coloring–that is, a coloring in which no two adjacent edges share the same color:
In[17]:= |
In[18]:= |
Out[18]= |
In[19]:= |
Out[19]= |
In[20]:= |
Out[20]= |
Verify by inspection:
In[21]:= |
Out[21]= |
Use EdgeTaggedGraph to verify an edge coloring of a multigraph by inspection:
In[22]:= |
Out[22]= |
In[23]:= |
Out[23]= |
In[24]:= |
Out[24]= |
This work is licensed under a Creative Commons Attribution 4.0 International License