Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Color the vertices in a graph with no adjacent vertices sharing a color
| ResourceFunction["ColorGraphVertices"][graph] colors the vertices of graph with no adjacent vertices having the same color. | |
| ResourceFunction["ColorGraphVertices"][graph, colors] uses colors from the color list colors. | 
Color the vertices of the Petersen graph:
| In[1]:= | ![ResourceFunction["ColorGraphVertices"][PetersenGraph[]]](https://www.wolframcloud.com/obj/resourcesystem/images/d31/d3137161-1d52-44a8-a00d-801ae32c4e37/19044959317f8ef0.png) | 
| Out[1]= |  | 
Color the vertices of the Petersen graph with color list 105:
| In[2]:= | ![ResourceFunction["ColorGraphVertices"][PetersenGraph[], ColorData[105, "ColorList"]]](https://www.wolframcloud.com/obj/resourcesystem/images/d31/d3137161-1d52-44a8-a00d-801ae32c4e37/5e086268fcbfafb1.png) | 
| Out[2]= |  | 
Color the vertices of the Petersen graph with a random sample of crayola colors:
| In[3]:= | ![ResourceFunction["ColorGraphVertices"][PetersenGraph[], RandomSample[ColorData["Crayola", "ColorList"]]]](https://www.wolframcloud.com/obj/resourcesystem/images/d31/d3137161-1d52-44a8-a00d-801ae32c4e37/66b9c53e1407fd5e.png) | 
| Out[3]= |  | 
Color the vertices of the Pappus graph:
| In[4]:= | ![ResourceFunction["ColorGraphVertices"][GraphData["PappusGraph"]]](https://www.wolframcloud.com/obj/resourcesystem/images/d31/d3137161-1d52-44a8-a00d-801ae32c4e37/3f680f8aad098a95.png) | 
| Out[4]= |  | 
Use ColorGraphVertices to color the vertices, or nodes of a graph or network, respectively:
| In[6]:= | ![ResourceFunction["ColorGraphVertices"][CompleteGraph[7]]](https://www.wolframcloud.com/obj/resourcesystem/images/d31/d3137161-1d52-44a8-a00d-801ae32c4e37/14cf7bf10b1e6c5d.png) | 
| Out[6]= |  | 
One can also color the edges:
| In[7]:= | ![ResourceFunction["ColorGraphEdges"][CompleteGraph[7]]](https://www.wolframcloud.com/obj/resourcesystem/images/d31/d3137161-1d52-44a8-a00d-801ae32c4e37/1d300e8f1687b927.png) | 
| Out[7]= |  | 
The number of colors needed for the vertices is given by VertexChromaticNumber:
| In[8]:= | ![VertexChromaticNumber[PetersenGraph[]]](https://www.wolframcloud.com/obj/resourcesystem/images/d31/d3137161-1d52-44a8-a00d-801ae32c4e37/4acb6307d79200b5.png) | 
| Out[8]= |  | 
Verify the cases with FindVertexColoring:
| In[9]:= | ![Length[DeleteDuplicates[FindVertexColoring[PetersenGraph[]]]]](https://www.wolframcloud.com/obj/resourcesystem/images/d31/d3137161-1d52-44a8-a00d-801ae32c4e37/2fd548c6ee1fcb5a.png) | 
| Out[9]= |  | 
Color the vertices of the skeleton of the Császár polyhedron:
| In[10]:= | ![ResourceFunction["ColorGraphVertices"][
 MeshConnectivityGraph[
  PolyhedronData["CsaszarPolyhedron", "Polyhedron"], 0]]](https://www.wolframcloud.com/obj/resourcesystem/images/d31/d3137161-1d52-44a8-a00d-801ae32c4e37/4138aabfee6e2e94.png) | 
| Out[10]= |  | 
Make a large random graph and color the vertices:
| In[11]:= | ![ResourceFunction["ColorGraphVertices"][
 RandomGraph[BarabasiAlbertGraphDistribution[192, 3]], ImageSize -> Full]](https://www.wolframcloud.com/obj/resourcesystem/images/d31/d3137161-1d52-44a8-a00d-801ae32c4e37/7e6cc44ac7ab607b.png) | 
| Out[11]= |  | 
Make a 3D buckyball graph with colors:
| In[12]:= | ![Graph3D[ResourceFunction["ColorGraphVertices"][BuckyballGraph[]]]](https://www.wolframcloud.com/obj/resourcesystem/images/d31/d3137161-1d52-44a8-a00d-801ae32c4e37/4374472ff4a7daf1.png) | 
| Out[12]= |  | 
Wolfram Language 12.3 (May 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License