Skip to content

Commit

Permalink
Merge branch 'main' into fix-typos
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanIsCoding authored Nov 30, 2024
2 parents f4f4a56 + 5d28053 commit 6aaff46
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
run: pushd rustworkx-core && cargo test && popd
- name: rustworkx-core Docs
run: pushd rustworkx-core && cargo doc && popd
env:
RUSTDOCFLAGS: '-D warnings'
- uses: actions/upload-artifact@v4
with:
name: rustworkx_core_docs
Expand Down
11 changes: 7 additions & 4 deletions rustworkx-core/src/centrality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,18 +1073,21 @@ mod test_katz_centrality {
/// In the case of a graphs with more than one connected component there is
/// an alternative improved formula that calculates the closeness centrality
/// as "a ratio of the fraction of actors in the group who are reachable, to
/// the average distance" [^WF]. You can enable this by setting `wf_improved` to `true`.
/// the average distance".[^WF]
/// You can enable this by setting `wf_improved` to `true`.
///
/// [^WF] Wasserman, S., & Faust, K. (1994). Social Network Analysis:
/// [^WF]: Wasserman, S., & Faust, K. (1994). Social Network Analysis:
/// Methods and Applications (Structural Analysis in the Social Sciences).
/// Cambridge: Cambridge University Press. doi:10.1017/CBO9780511815478
/// Cambridge: Cambridge University Press.
/// <https://doi.org/10.1017/CBO9780511815478>
///
/// Arguments:
/// # Arguments
///
/// * `graph` - The graph object to run the algorithm on
/// * `wf_improved` - If `true`, scale by the fraction of nodes reachable.
///
/// # Example
///
/// ```rust
/// use rustworkx_core::petgraph;
/// use rustworkx_core::centrality::closeness_centrality;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ use super::InvalidInputError;

/// Generate a Dorogovtsev-Goltsev-Mendes graph
///
/// Generate a graph following the recursive procedure in [1].
/// Generate a graph following the recursive procedure by Dorogovtsev, Goltsev,
/// and Mendes[^DGM2002].
/// Starting from the two-node, one-edge graph, iterating `n` times generates
/// a graph with `(3**n + 3) // 2` nodes and `3**n` edges.
/// a graph with `(3^n + 3) // 2` nodes and `3^n` edges.
///
/// # Arguments
///
/// Arguments:
///
/// * `n` - The number of iterations to perform. n=0 returns the two-node, one-edge graph.
/// * `n` - The number of iterations to perform. `n = 0` returns the two-node, one-edge graph.
/// * `default_node_weight` - A callable that will return the weight to use for newly created nodes.
/// * `default_edge_weight` - A callable that will return the weight object to use for newly created edges.
///
/// # Example
///
/// ```rust
/// use rustworkx_core::petgraph;
/// use rustworkx_core::generators::dorogovtsev_goltsev_mendes_graph;
Expand All @@ -43,10 +44,10 @@ use super::InvalidInputError;
/// );
/// ```
///
/// .. [1] S. N. Dorogovtsev, A. V. Goltsev and J. F. F. Mendes
/// [^DGM2002]: S. N. Dorogovtsev, A. V. Goltsev and J. F. F. Mendes
/// “Pseudofractal scale-free web”
/// Physical Review E 65, 066122, 2002
/// https://arxiv.org/abs/cond-mat/0112143
/// Physical Review E 65, 066122 (2002)
/// <https://arxiv.org/abs/cond-mat/0112143>
///
pub fn dorogovtsev_goltsev_mendes_graph<G, T, F, H, M>(
n: usize,
Expand Down
2 changes: 1 addition & 1 deletion rustworkx-core/src/generators/star_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use super::InvalidInputError;
/// * `bidirectional` - Whether edges are added bidirectionally. If set to
/// `true` then for any edge `(u, v)` an edge `(v, u)` will also be added.
/// If the graph is undirected this will result in a parallel edge.
///
/// # Example
/// ```rust
/// use rustworkx_core::petgraph;
Expand Down
44 changes: 26 additions & 18 deletions rustworkx-core/src/steiner_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@ where
Ok(out_edges)
}

/// Solution to a minimum Steiner tree problem.
///
/// This `struct` is created by the [steiner_tree] function.
pub struct SteinerTreeResult {
pub used_node_indices: HashSet<usize>,
pub used_edge_endpoints: HashSet<(usize, usize)>,
Expand All @@ -454,21 +457,25 @@ pub struct SteinerTreeResult {
/// complete graph in which each edge is weighted by the shortest path distance
/// between nodes in ``graph``.
///
/// This algorithm [1]_ produces a tree whose weight is within a
/// :math:`(2 - (2 / t))` factor of the weight of the optimal Steiner tree
/// where :math:`t` is the number of terminal nodes. The algorithm implemented
/// here is due to [2]_ . It avoids computing all pairs shortest paths but rather
/// reduces the problem to a single source shortest path and a minimum spanning tree
/// problem.
/// This algorithm by Kou, Markowsky, and Berman[^KouMarkowskyBerman1981]
/// produces a tree whose weight is within a `(2 - (2 / t))` factor of
/// the weight of the optimal Steiner tree where `t` is the number of
/// terminal nodes.
/// The algorithm implemented here is due to Mehlhorn[^Mehlhorn1987]. It avoids
/// computing all pairs shortest paths but rather reduces the problem to a
/// single source shortest path and a minimum spanning tree problem.
///
/// Arguments:
/// `graph`: The input graph to compute the steiner tree of
/// `terminal_nodes`: The terminal nodes of the steiner tree
/// `weight_fn`: A callable weight function that will be passed an edge reference
/// for each edge in the graph and it is expected to return a `Result<f64>`
/// which if it doesn't error represents the weight of that edge.
/// # Arguments
///
/// - `graph` - The input graph to compute the Steiner tree of
/// - `terminal_nodes` - The terminal nodes of the Steiner tree
/// - `weight_fn` - A callable weight function that will be passed an edge reference
/// for each edge in the graph and it is expected to return a [`Result<f64>`]
/// which if it doesn't error represents the weight of that edge.
///
/// # Returns
///
/// Returns a custom struct that contains a set of nodes and edges and `None`
/// A custom struct that contains a set of nodes and edges and `None`
/// if the graph is disconnected relative to the terminal nodes.
///
/// # Example
Expand Down Expand Up @@ -509,13 +516,14 @@ pub struct SteinerTreeResult {
/// let tree = steiner_tree(&input_graph, &terminal_nodes, weight_fn).unwrap().unwrap();
/// ```
///
/// .. [1] Kou, Markowsky & Berman,
/// [^KouMarkowskyBerman1981]: Kou, Markowsky & Berman,
/// "A fast algorithm for Steiner trees"
/// Acta Informatica 15, 141–145 (1981).
/// https://link.springer.com/article/10.1007/BF00288961
/// .. [2] Kurt Mehlhorn,
/// Acta Informatica 15, 141–145 (1981)
/// <https://link.springer.com/article/10.1007/BF00288961>
/// [^Mehlhorn1987]: Kurt Mehlhorn,
/// "A faster approximation algorithm for the Steiner problem in graphs"
/// https://doi.org/10.1016/0020-0190(88)90066-X
/// Information Processing Letters 27(3), 125-128 (1987)
/// <https://doi.org/10.1016/0020-0190(88)90066-X>
pub fn steiner_tree<G, F, E>(
graph: G,
terminal_nodes: &[G::NodeId],
Expand Down
1 change: 0 additions & 1 deletion rustworkx-core/src/token_swapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ where
/// assert_eq!(3, output.len());
///
/// ```
pub fn token_swapper<G>(
graph: G,
mapping: HashMap<G::NodeId, G::NodeId>,
Expand Down
6 changes: 3 additions & 3 deletions src/dag_algo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ pub fn collect_runs(
// This is where a filter function error will be returned, otherwise Result is stripped away
let py_run: Vec<PyObject> = run_result?
.iter()
.map(|node| return graph.graph.node_weight(*node).into_py(py))
.map(|node| graph.graph.node_weight(*node).into_py(py))
.collect();

result.push(py_run)
Expand Down Expand Up @@ -667,7 +667,7 @@ pub fn transitive_reduction(
);
}
}
return Ok((
Ok((
digraph::PyDiGraph {
graph: tr,
node_removed: false,
Expand All @@ -680,5 +680,5 @@ pub fn transitive_reduction(
.iter()
.map(|(k, v)| (k.index(), v.index()))
.collect::<DictMap<usize, usize>>(),
));
))
}
4 changes: 2 additions & 2 deletions src/digraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl GraphBase for PyDiGraph {
type EdgeId = EdgeIndex;
}

impl<'a> NodesRemoved for &'a PyDiGraph {
impl NodesRemoved for &PyDiGraph {
fn nodes_removed(&self) -> bool {
self.node_removed
}
Expand Down Expand Up @@ -886,7 +886,7 @@ impl PyDiGraph {
///
/// :param int node_a: The index for the first node
/// :param int node_b: The index for the second node
///
/// :returns: A list with all the data objects for the edges between nodes
/// :rtype: list
/// :raises NoEdgeBetweenNodes: When there is no edge between nodes
Expand Down
2 changes: 1 addition & 1 deletion src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl GraphBase for PyGraph {
type EdgeId = EdgeIndex;
}

impl<'a> NodesRemoved for &'a PyGraph {
impl NodesRemoved for &PyGraph {
fn nodes_removed(&self) -> bool {
self.node_removed
}
Expand Down
12 changes: 6 additions & 6 deletions src/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ where
}
}

impl<'py, T> PyEq<Bound<'py, PyAny>> for T
impl<T> PyEq<Bound<'_, PyAny>> for T
where
for<'p> T: PyEq<T> + Clone + FromPyObject<'p>,
{
Expand Down Expand Up @@ -1031,7 +1031,7 @@ impl PyHash for EdgeList {
}
}

impl<'py> PyEq<Bound<'py, PyAny>> for EdgeList {
impl PyEq<Bound<'_, PyAny>> for EdgeList {
#[inline]
fn eq(&self, other: &Bound<PyAny>, py: Python) -> PyResult<bool> {
PyEq::eq(&self.edges, other, py)
Expand Down Expand Up @@ -1119,7 +1119,7 @@ impl PyHash for IndexPartitionBlock {
}
}

impl<'py> PyEq<Bound<'py, PyAny>> for IndexPartitionBlock {
impl PyEq<Bound<'_, PyAny>> for IndexPartitionBlock {
#[inline]
fn eq(&self, other: &Bound<PyAny>, py: Python) -> PyResult<bool> {
PyEq::eq(&self.block, other, py)
Expand Down Expand Up @@ -1522,7 +1522,7 @@ impl PyHash for PathMapping {
}
}

impl<'py> PyEq<Bound<'py, PyAny>> for PathMapping {
impl PyEq<Bound<'_, PyAny>> for PathMapping {
#[inline]
fn eq(&self, other: &Bound<PyAny>, py: Python) -> PyResult<bool> {
PyEq::eq(&self.paths, other, py)
Expand Down Expand Up @@ -1686,7 +1686,7 @@ impl PyHash for MultiplePathMapping {
}
}

impl<'py> PyEq<Bound<'py, PyAny>> for MultiplePathMapping {
impl PyEq<Bound<'_, PyAny>> for MultiplePathMapping {
#[inline]
fn eq(&self, other: &Bound<PyAny>, py: Python) -> PyResult<bool> {
PyEq::eq(&self.paths, other, py)
Expand Down Expand Up @@ -1750,7 +1750,7 @@ impl PyHash for PathLengthMapping {
}
}

impl<'py> PyEq<Bound<'py, PyAny>> for PathLengthMapping {
impl PyEq<Bound<'_, PyAny>> for PathLengthMapping {
#[inline]
fn eq(&self, other: &Bound<PyAny>, py: Python) -> PyResult<bool> {
PyEq::eq(&self.path_lengths, other, py)
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ pub trait NodesRemoved {
fn nodes_removed(&self) -> bool;
}

impl<'a, Ty> NodesRemoved for &'a StablePyGraph<Ty>
impl<Ty> NodesRemoved for &StablePyGraph<Ty>
where
Ty: EdgeType,
{
Expand Down

0 comments on commit 6aaff46

Please sign in to comment.