Skip to content

Commit

Permalink
Fix handling of parallel edges
Browse files Browse the repository at this point in the history
This commit fixes an issue where we were overcounting parallel edges in
the graph. There was a bug in the logic that was calculating the
combined weight of parallel edges incorrectly.

Co-authored-by: georgios-ts <[email protected]>
  • Loading branch information
mtreinish and georgios-ts committed Jun 9, 2022
1 parent 97fcc61 commit e03856b
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions retworkx-core/src/centrality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,9 @@ where
let x_last = x.clone();
for node_index in graph.node_identifiers() {
let node = graph.to_index(node_index);
for neighbor in graph.neighbors(node_index) {
let w_vec: Vec<G::EdgeRef> = graph
.edges(node_index)
.filter(|edge| edge.target() == neighbor)
.collect();
let mut w = 0.;
for edge in w_vec {
w += weight_fn(edge)?;
}
for edge in graph.edges(node_index) {
let w = weight_fn(edge)?;
let neighbor = edge.target();
x[graph.to_index(neighbor)] += x_last[node] * w;
}
}
Expand Down

0 comments on commit e03856b

Please sign in to comment.