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

Giving some punch to distance computations #7966

Closed
nathanncohen mannequin opened this issue Jan 17, 2010 · 7 comments
Closed

Giving some punch to distance computations #7966

nathanncohen mannequin opened this issue Jan 17, 2010 · 7 comments

Comments

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Jan 17, 2010

This patch creates a function shortest_path_all_vertices in c_graphs which, given a vertex v, computes a shortest path for each other vertex.

With small other modifications, it improves the speed of many functions ( which were all calling each other )

Before :

sage: g = graphs.RandomGNP(50,.3)
sage: %timeit g.shortest_path_lengths(0)
100 loops, best of 3: 3.72 ms per loop
sage: %timeit g.average_distance()
10 loops, best of 3: 383 ms per loop
sage: %timeit g.wiener_index()
10 loops, best of 3: 384 ms per loop
sage: %timeit g.szeged_index()
10 loops, best of 3: 325 ms per loop
sage: %timeit g.eccentricity()
10 loops, best of 3: 189 ms per loop
sage: g.sparse6_string()
':q_OW_CCBb?WcOL@@`_{CGDB@pCGIF``@[WQK_`?w_QIDoo_WSJEBWGOKIDbG?CZ?@@Owwb?@?o_SOMba@X?bA@`OpKhBB@p?kX@Caq@YAACAphWn@B@po{j?@`?o_]QIeGOWMGDCqheEDB@pXMAEBa@GscYLoo__QJEBaxcvBECAPWqYNQ`gwgTKERX}?@@@@Gg[QHdBXt@?BAa@WmYNGWo[OLFCQhqCLFCRPky]POow_SLGCRHw}ca@_w_SLHCq`_u[OGg?GEDBAP_{iUJeBiYKGCbPp_qYMFbyLIea``WoYMFcA`SkXMGS[?MIFCahgw\\NP`Ww]VLfSskYMHDApcs[NHSy`R?A@pOkWMGcb@oy]TjGGKOJIEBh|QjUOox?mWLEryHIh___WOaRIDr@cu[MhTauCCBa@Gk]PHdax_w]NhCq\\Sm'

After

sage: %timeit g.shortest_path_lengths(0)
10 loops, best of 3: 430 µs per loop
sage: %timeit g.average_distance()
10 loops, best of 3: 22 ms per loop
sage: %timeit g.wiener_index()
10 loops, best of 3: 22.1 ms per loop
sage: %timeit g.szeged_index()
10 loops, best of 3: 41.5 ms per loop
sage: %timeit g.eccentricity()
10 loops, best of 3: 22 ms per loop

Nathann

Component: graph theory

Author: Nathann Cohen

Reviewer: Paul Zimmermann

Merged: sage-4.3.4.alpha0

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

@nathanncohen nathanncohen mannequin added this to the sage-4.3.4 milestone Jan 17, 2010
@nathanncohen nathanncohen mannequin assigned rlmill Jan 17, 2010
@nathanncohen nathanncohen mannequin added the s: needs review label Jan 17, 2010
@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Jan 17, 2010

comment:2

Small modification to distance_graph too:

Before :

sage: %timeit g.distance_graph([2,8,9])
10 loops, best of 3: 127 ms per loop

After

sage: %timeit g.distance_graph([2,8,9])
10 loops, best of 3: 49 ms per loop

Nathann

@zimmermann6
Copy link

comment:3

The speedups are great, but I got one extra failure (against 4.3.3 on Fedora 12):

sage -t  graphs/base/c_graph.pyx
File "/usr/local/sage-4.3.3/sage/devel/sage-trac/sage/graphs/base/c_graph.pyx",\
 line 1427:
    sage: all([ len(paths[v]) == 0 or len(paths[v])-1 == g.distance(0,v) for v \
in g])
Exception raised:
    Traceback (most recent call last):
      File "/usr/local/sage-4.3.3/sage/local/bin/ncadoctest.py", line 1231, in \
run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/usr/local/sage-4.3.3/sage/local/bin/sagedoctest.py", line 38, in r\
un_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compil\
eflags)
      File "/usr/local/sage-4.3.3/sage/local/bin/ncadoctest.py", line 1172, in \
run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_43[7]>", line 1, in <module>
        all([ len(paths[v]) == Integer(0) or len(paths[v])-Integer(1) == g.dist\
ance(Integer(0),v) for v in g])###line 1427:
    sage: all([ len(paths[v]) == 0 or len(paths[v])-1 == g.distance(0,v) for v \
in g])
    KeyError: 20

Please could you look at this?

@zimmermann6
Copy link

Reviewer: Paul Zimmermann

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Feb 26, 2010

comment:4

At first, the function associated a path from v to each other vertex, possibly empty if there was none. Then I noticed the other functions in Sage expected the dictionary to only contain keys corresponding to the vertices reachable from v (which was sound, too), and changed the original function, forgetting the docstrings... Fixed now !

And I also removed the (commented) loop which was associating empty paths when needed...

Thank you again ! :-)

Nathann

@zimmermann6
Copy link

comment:5

Attachment: trac_7966.patch.gz

with the new patch c_graph.pyx works again:

[zimmerma@coing sage]$ sage -t  graphs/base/c_graph.pyx
sage -t  "devel/sage-7966/sage/graphs/base/c_graph.pyx"     
         [2.5 s]
 
----------------------------------------------------------------------
All tests passed!
Total time for all tests: 2.5 seconds

Thus a positive review.

Paul

@zimmermann6
Copy link

Author: Nathann Cohen

@sagetrac-mvngu
Copy link
Mannequin

sagetrac-mvngu mannequin commented Mar 3, 2010

Merged: sage-4.3.4.alpha0

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

1 participant