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

Remove The Hashmap from Shorted Path for Centrality Computation #1307

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Paulo-21
Copy link
Contributor

@Paulo-21 Paulo-21 commented Nov 3, 2024

Hello,
I removed the hashmap for the shorted path for centrality.

This may improve performance.

Tell me what do u think about :)

@coveralls
Copy link

coveralls commented Nov 3, 2024

Pull Request Test Coverage Report for Build 11846697683

Details

  • 20 of 20 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 95.809%

Totals Coverage Status
Change from base Build 11840985523: 0.0%
Covered Lines: 18013
Relevant Lines: 18801

💛 - Coveralls

Copy link
Collaborator

@IvanIsCoding IvanIsCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think minimizing the number of hashing operations that happen during the shortest path is a good idea in general. But I am not convinced this works, we need to benchmark this more carefully.

I have a feeling this method will be slower for directed graphs, where some nodes are not able to reach all other nodes in the graph. In those cases, having a small hashmap with the nodes that can be reached is much faster than having a large vector with mostly non-visited entries.

let mut verts_sorted_by_distance: Vec<G::NodeId> = Vec::with_capacity(c); // a stack
let mut predecessors: Vec<Vec<usize>> = vec![Vec::new(); max_index];
let mut sigma: Vec<f64> = vec![0.; max_index];
let mut distance: Vec<i64> = vec![-1; max_index];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more appropriate type here is Option<i64> if you want to represent missing paths. I'd even say Option<usize>

let coeff = (1.0 + delta[iw]) / path_calc.sigma[iw];
let p_w = path_calc.predecessors.get(iw).unwrap();
for iv in p_w {
//let iv = graph.to_index(*v);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment

Comment on lines -361 to -366

for node in graph.node_identifiers() {
predecessors.insert(node, Vec::new());
sigma.insert(node, 0.0);
distance.insert(node, -1);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se how the hashmap was full filled with value for all node of the graph, so replacing with a vec of size of node bound will no be a problem for cache efficiency, because hashmap was already full when the algorithm started

@Paulo-21
Copy link
Contributor Author

Paulo-21 commented Nov 8, 2024

I think minimizing the number of hashing operations that happen during the shortest path is a good idea in general. But I am not convinced this works, we need to benchmark this more carefully.

I have a feeling this method will be slower for directed graphs, where some nodes are not able to reach all other nodes in the graph. In those cases, having a small hashmap with the nodes that can be reached is much faster than having a large vector with mostly non-visited entries.

I heard your argument and i agree that we should benchmark to be sure that it will be faster when the hashmap was not full filled
But in this particular case the hashmap was full filled before the algorithm started so i don't think it will cause any different.
I think we can replace every hashmap indexed by NodeId type and that is full filled before algorithm start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants