Graph coloring with the eigen values of Hermitian matrix and K-means Clustering with multiprocessing using Ray in Python Generating colored graph using matplotlib Here's a step-by-step explanation of the code:
-
Ray Initialization:
- Initialize the Ray framework with 2 CPUs.
-
Generate Sample Graph:
- Create a sample graph using the Erdos-Renyi model with 7 nodes and a probability of 0.5 for edge creation.
-
Sequential Spectral Graph Coloring:
- Calculate the Laplacian matrix of the graph.
- Compute the second smallest eigenvalue and its corresponding eigenvector.
- Assign colors to vertices based on the sign of the eigenvector.
- Convert the colors to integers.
- Print the colored vertices and the time taken for sequential spectral graph coloring.
-
Parallel Spectral Graph Coloring using Ray:
- Create a remote actor (SpectralGraphColoringActor) to parallelize the spectral graph coloring.
- Measure the time taken for parallel spectral graph coloring.
- Print the colored vertices and the time taken for parallel spectral graph coloring.
-
Convert Colored Vertices to Array for K-Means Clustering:
- Prepare data for K-Means clustering from both sequential and parallel processes.
-
Sequential K-Means Clustering:
- Apply K-Means clustering sequentially to the data obtained from sequential spectral graph coloring.
- Print the K-Means clustering result and the time taken for sequential K-Means clustering.
-
Parallel K-Means Clustering using Ray:
- Create a remote actor (KMeansActor) to parallelize K-Means clustering.
- Measure the time taken for parallel K-Means clustering.
- Print the K-Means clustering result and the time taken for parallel K-Means clustering.
-
Shutdown Ray:
- Terminate the Ray framework.
-
Combine Colored Vertices from Sequential and Parallel Processes:
- Concatenate the colored vertices obtained from sequential spectral graph coloring and both processes of K-Means clustering.
-
Create a Colored Graph:
- Copy the original graph and assign colors to nodes based on the combined colored vertices.
-
Adjust Colors to Avoid Conflicts:
- Check for adjacent nodes with the same color and assign a new color to avoid conflicts.
-
Draw the Colored Graph:
- Layout the graph using the spring layout algorithm.
- Assign colors to nodes and draw the final colored graph.
-
End of Code Execution.