Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "saturation first" and "independent set" greedy node coloring strategies #1138

Merged
merged 43 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d286722
initial commit
alexanderivrii Mar 10, 2024
3b837da
fix and test
alexanderivrii Mar 10, 2024
5994216
python formatting
alexanderivrii Mar 10, 2024
9f947e9
creating enums
alexanderivrii Mar 10, 2024
2191398
also passing greedy strategy to edge coloring functions; improving do…
alexanderivrii Mar 11, 2024
ca55aea
release notes'
alexanderivrii Mar 11, 2024
6a34c51
python test
alexanderivrii Mar 11, 2024
525755a
reno fix
alexanderivrii Mar 11, 2024
78316d4
reno fix
alexanderivrii Mar 11, 2024
6a815a4
minor cleanup
alexanderivrii Mar 11, 2024
0ad270e
small rust cleanup
alexanderivrii Mar 11, 2024
e9b763b
adding greedy node coloring using maximal independent set + reworked…
alexanderivrii Mar 12, 2024
9bd2a47
updating top-level source, tests and docs
alexanderivrii Mar 12, 2024
68a74e3
docs
alexanderivrii Mar 12, 2024
2ea2820
Merge branch 'main' into more-greedy-color
alexanderivrii Apr 30, 2024
5dd96d2
applying fix from code review
alexanderivrii Apr 30, 2024
0874242
adding IndependentSet to pyi as well
alexanderivrii Apr 30, 2024
d227ad9
Adding a table that describes greedy strategies available
alexanderivrii Apr 30, 2024
b6eb143
converting table to sphinx-style
alexanderivrii May 5, 2024
7f733f5
fix reference to footnotes
alexanderivrii May 5, 2024
8a54755
docs improvements
alexanderivrii May 6, 2024
7322ead
another attempt
alexanderivrii May 6, 2024
787193d
attempt to extend API with preset_color_fn for edges
alexanderivrii May 7, 2024
4ed0704
minor
alexanderivrii May 7, 2024
8c8238d
finally compiling
alexanderivrii May 7, 2024
7ec8200
fixing pyi API and edding python tests
alexanderivrii May 7, 2024
c65ddf7
adding rustworkx-core tests
alexanderivrii May 7, 2024
da1f90f
adding arguments to docstrings
alexanderivrii May 7, 2024
4b61264
expanding release note
alexanderivrii May 7, 2024
f2fd4e5
another docs fix
alexanderivrii May 7, 2024
294f1d9
Update releasenotes/notes/saturation-greedy-color-109d40f189590d3a.yaml
alexanderivrii May 15, 2024
298e0d8
a round of renaming
alexanderivrii May 22, 2024
e040aad
restoring greedy_node_coloring API for backwards compatibility
alexanderivrii May 22, 2024
c107433
restoring greedy_edge_coloring API for backwards compatibility
alexanderivrii May 22, 2024
d7b0ab5
fix to rustworkx coloring
alexanderivrii May 22, 2024
2f698ab
changing return type of new rustworkx-core functions to be Result
alexanderivrii May 22, 2024
ba52a73
black
alexanderivrii May 22, 2024
b1ec8c9
removing NodeIndexable in node coloring functions
alexanderivrii May 22, 2024
9295808
and from edge coloring functions
alexanderivrii May 22, 2024
b480be6
suggestions from code review
alexanderivrii May 22, 2024
a999b83
suggestions from code review
alexanderivrii May 22, 2024
3e84085
release note update
alexanderivrii May 22, 2024
7101d83
Merge branch 'main' into more-greedy-color
mtreinish May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/api/algorithm_functions/coloring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Coloring
.. autosummary::
:toctree: ../../apiref

rustworkx.ColoringStrategy
rustworkx.graph_greedy_color
rustworkx.graph_bipartite_edge_color
rustworkx.graph_greedy_edge_color
Expand Down
59 changes: 59 additions & 0 deletions releasenotes/notes/saturation-greedy-color-109d40f189590d3a.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
features:
- Added a new class :class:`~.ColoringStrategy` used to specify the strategy used by
the greedy node and edge coloring algorithms.
The ``Degree`` strategy colors the nodes with higher degree first.
The ``Saturation`` strategy dynamically chooses the vertex that has the largest
number of different colors already assigned to its neighbors, and, in case of a tie,
the vertex that has the largest number of uncolored neighbors.
The ``IndependentSet`` strategy finds independent subsets of the graph, and assigns
a different color to each of these subsets.
- |
The rustworkx-core ``coloring`` module has 2 new functions,
``greedy_node_color_with_coloring_strategy`` and
``greedy_edge_color_with_coloring_strategy``.
These functions color respectively the nodes or the edges of the graph
using the specified coloring strategy and handling the preset colors
when provided.
- |
Added a new keyword argument, ``strategy``, to :func:`.graph_greedy_color`
and to :func:`.graph_greedy_edge_color` to specify the greedy coloring strategy.

For example:

.. jupyter-execute::

import rustworkx as rx
from rustworkx.visualization import mpl_draw

graph = rx.generators.generalized_petersen_graph(5, 2)

coloring = rx.graph_greedy_color(graph, strategy=rx.ColoringStrategy.Saturation)
colors = [coloring[node] for node in graph.node_indices()]

layout = rx.shell_layout(graph, nlist=[[0, 1, 2, 3, 4],[6, 7, 8, 9, 5]])
mpl_draw(graph, node_color=colors, pos=layout)
- |
Added a new keyword argument, ``preset_color_fn``, to :func:`.graph_greedy_edge_color`
which is used to provide preset colors for specific edges when computing the graph
coloring. You can optionally pass a callable to that argument which will
be passed edge index from the graph and is either expected to return an
integer color to use for that edge, or `None` to indicate there is no
preset color for that edge. For example:

.. jupyter-execute::

import rustworkx as rx
from rustworkx.visualization import mpl_draw

graph = rx.generators.generalized_petersen_graph(5, 2)

def preset_colors(edge_index):
if edge_index == 0:
return 3

coloring = rx.graph_greedy_edge_color(graph, preset_color_fn=preset_colors)
colors = [coloring[edge] for edge in graph.edge_indices()]

layout = rx.shell_layout(graph, nlist=[[0, 1, 2, 3, 4], [6, 7, 8, 9, 5]])
mpl_draw(graph, edge_color=colors, pos=layout)
Loading