|
| 1 | +--- |
| 2 | +features: |
| 3 | + - Added a new class :class:`~.ColoringStrategy` used to specify the strategy used by |
| 4 | + the greedy node and edge coloring algorithms. |
| 5 | + The ``Degree`` strategy colors the nodes with higher degree first. |
| 6 | + The ``Saturation`` strategy dynamically chooses the vertex that has the largest |
| 7 | + number of different colors already assigned to its neighbors, and, in case of a tie, |
| 8 | + the vertex that has the largest number of uncolored neighbors. |
| 9 | + The ``IndependentSet`` strategy finds independent subsets of the graph, and assigns |
| 10 | + a different color to each of these subsets. |
| 11 | + - | |
| 12 | + The rustworkx-core ``coloring`` module has 2 new functions, |
| 13 | + ``greedy_node_color_with_coloring_strategy`` and |
| 14 | + ``greedy_edge_color_with_coloring_strategy``. |
| 15 | + These functions color respectively the nodes or the edges of the graph |
| 16 | + using the specified coloring strategy and handling the preset colors |
| 17 | + when provided. |
| 18 | + - | |
| 19 | + Added a new keyword argument, ``strategy``, to :func:`.graph_greedy_color` |
| 20 | + and to :func:`.graph_greedy_edge_color` to specify the greedy coloring strategy. |
| 21 | + |
| 22 | + For example: |
| 23 | +
|
| 24 | + .. jupyter-execute:: |
| 25 | +
|
| 26 | + import rustworkx as rx |
| 27 | + from rustworkx.visualization import mpl_draw |
| 28 | +
|
| 29 | + graph = rx.generators.generalized_petersen_graph(5, 2) |
| 30 | +
|
| 31 | + coloring = rx.graph_greedy_color(graph, strategy=rx.ColoringStrategy.Saturation) |
| 32 | + colors = [coloring[node] for node in graph.node_indices()] |
| 33 | +
|
| 34 | + layout = rx.shell_layout(graph, nlist=[[0, 1, 2, 3, 4],[6, 7, 8, 9, 5]]) |
| 35 | + mpl_draw(graph, node_color=colors, pos=layout) |
| 36 | + - | |
| 37 | + Added a new keyword argument, ``preset_color_fn``, to :func:`.graph_greedy_edge_color` |
| 38 | + which is used to provide preset colors for specific edges when computing the graph |
| 39 | + coloring. You can optionally pass a callable to that argument which will |
| 40 | + be passed edge index from the graph and is either expected to return an |
| 41 | + integer color to use for that edge, or `None` to indicate there is no |
| 42 | + preset color for that edge. For example: |
| 43 | + |
| 44 | + .. jupyter-execute:: |
| 45 | + |
| 46 | + import rustworkx as rx |
| 47 | + from rustworkx.visualization import mpl_draw |
| 48 | + |
| 49 | + graph = rx.generators.generalized_petersen_graph(5, 2) |
| 50 | + |
| 51 | + def preset_colors(edge_index): |
| 52 | + if edge_index == 0: |
| 53 | + return 3 |
| 54 | + |
| 55 | + coloring = rx.graph_greedy_edge_color(graph, preset_color_fn=preset_colors) |
| 56 | + colors = [coloring[edge] for edge in graph.edge_indices()] |
| 57 | + |
| 58 | + layout = rx.shell_layout(graph, nlist=[[0, 1, 2, 3, 4], [6, 7, 8, 9, 5]]) |
| 59 | + mpl_draw(graph, edge_color=colors, pos=layout) |
0 commit comments