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

Improve documentation for graph_greedy_color #857

Merged
merged 6 commits into from
May 17, 2023
Merged
Changes from all commits
Commits
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
27 changes: 26 additions & 1 deletion src/coloring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,38 @@ use petgraph::visit::NodeCount;

use rayon::prelude::*;

/// Color a PyGraph using a largest_first strategy greedy graph coloring.
/// Color a :class:`~.PyGraph` object using a greedy graph coloring algorithm.
///
/// This function uses a `largest-first` strategy as described in [1]_ and colors
/// the nodes with higher degree first.
///
/// .. note::
///
/// The coloring problem is NP-hard and this is a heuristic algorithm which
/// may not return an optimal solution.
///
/// :param PyGraph: The input PyGraph object to color
///
/// :returns: A dictionary where keys are node indices and the value is
/// the color
/// :rtype: dict
///
/// .. 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)
/// colors = [coloring[node] for node in graph.node_indices()]
///
/// # Draw colored graph
/// layout = rx.shell_layout(graph, nlist=[[0, 1, 2, 3, 4],[6, 7, 8, 9, 5]])
/// mpl_draw(graph, node_color=colors, pos=layout)
///
///
/// .. [1] Adrian Kosowski, and Krzysztof Manuszewski, Classical Coloring of Graphs,
/// Graph Colorings, 2-19, 2004. ISBN 0-8218-3458-4.
#[pyfunction]
#[pyo3(text_signature = "(graph, /)")]
pub fn graph_greedy_color(py: Python, graph: &graph::PyGraph) -> PyResult<PyObject> {
Expand Down