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

improving shortest path all pairs through BFS computations #11053

Closed
nathanncohen mannequin opened this issue Mar 26, 2011 · 9 comments
Closed

improving shortest path all pairs through BFS computations #11053

nathanncohen mannequin opened this issue Mar 26, 2011 · 9 comments

Comments

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Mar 26, 2011

After taking a look at the SparseGraph backend, it looks like some time is actually spent obtaining the list of neighbors. This patch caches so that the out_neighbors method does not have to be called so often.

Depends on #10905

CC: @sagetrac-ylchapuy

Component: graph theory

Author: Nathann Cohen

Reviewer: Leonardo Sampaio

Merged: sage-4.7.2.alpha2

Issue created by migration from https://trac.sagemath.org/ticket/11053

@nathanncohen nathanncohen mannequin added this to the sage-4.7.1 milestone Mar 26, 2011
@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Mar 26, 2011

comment:1

Before

sage: g = graphs.Grid2dGraph(60,60)
sage: %time d = g.shortest_path_all_pairs()
CPU times: user 14.52 s, sys: 0.51 s, total: 15.03 s
Wall time: 15.03 s
sage: g = graphs.Grid2dGraph(30,30)
sage: %timeit d = g.shortest_path_all_pairs()
5 loops, best of 3: 752 ms per loop
sage: g = graphs.PetersenGraph()
sage: %timeit d = g.shortest_path_all_pairs()
625 loops, best of 3: 73.5 µs per loop

After

sage: g = graphs.Grid2dGraph(60,60)
sage: %time d = g.shortest_path_all_pairs()
CPU times: user 10.70 s, sys: 0.53 s, total: 11.23 s
Wall time: 11.24 s
sage: g = graphs.Grid2dGraph(30,30)
sage: %timeit d = g.shortest_path_all_pairs()
5 loops, best of 3: 549 ms per loop
sage: g = graphs.PetersenGraph()
sage: %timeit d = g.shortest_path_all_pairs()
625 loops, best of 3: 53.4 µs per loop

@nathanncohen

This comment has been minimized.

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Jun 5, 2011

Attachment: trac_11053.patch.gz

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Jun 5, 2011

comment:3

I had set this patch to "needs review", as I was wondering why Cython was apparently slower than a C code I had written independently. Turns out the different lies in how the vertices of the 2d grid (which is the graph on which I was testing the performances) were labelled.

In the C code, they were labelled from left to right, then from top to bottom, why Sage's numbering is much more random, hence different performances in practice.

Hail Cython ;-)

Nathann

@sagetrac-lsampaio
Copy link
Mannequin

sagetrac-lsampaio mannequin commented Aug 4, 2011

comment:4

I reviwed the patch and it seens to be working well!

@sagetrac-lsampaio
Copy link
Mannequin

sagetrac-lsampaio mannequin commented Aug 4, 2011

Reviewer: Leonardo Sampaio

@jdemeyer
Copy link

Dependencies: #10905

@jdemeyer
Copy link

Merged: sage-4.7.2.alpha2

@jdemeyer

This comment has been minimized.

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

No branches or pull requests

2 participants