partition_graph_color#
- m4opt.utils.optimization.partition_graph_color(graph, partition, **kwargs)[source] [edit on github]#
Find a coloring for a partition of a graph.
- Parameters:
graph (Graph) – A graph in the form of a
networkx.Graphobject.partition (ndarray) – Partition assignments of the nodes in the graphs as returned by
partition_graph().**kwargs – Any additional arguments to pass to
networkx.algorithms.coloring.greedy_color.
- Returns:
An integer-valued array of color assignments for each partition. The color for node
iin the original graph iscolor[partition[i]].- Return type:
Example
from matplotlib import pyplot as plt from m4opt.utils.optimization import partition_graph, partition_graph_color import networkx as nx graph = nx.triangular_lattice_graph(20, 40) part = partition_graph(graph, 20, seed=42) color = partition_graph_color( graph, part, strategy="connected_sequential", interchange=True) ax = plt.axes(aspect=1) nx.draw( graph, ax=ax, pos=nx.get_node_attributes(graph, "pos"), node_size=50, node_color=color[part], cmap="cool", )