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

Graph::InDegree and IncidentsTo are slower than OutDegree and IncidentsFrom #79

Closed
osrf-migration opened this issue Sep 6, 2017 · 2 comments
Labels
bug Something isn't working

Comments

@osrf-migration
Copy link

Original report (archived issue) by Steve Peters (Bitbucket: Steven Peters, GitHub: scpeters).


The Graph class uses an adjacency list internally to assist with computations. This is stored internally as a map of Edges departing from each Vertex. This allows the IncidentsFrom and OutDegree functions to look up a list of edges directly given a vertex id.

There is no equivalent data structure for storing a list of edges arriving at a given vertex, however. This means that IncidentsTo and InDegree need to iterate over all vertices and then all edges to see if any of those edges arrive at the specified vertex.

I've added a test that illustrates this performance difference for graphs with large numbers of nodes in branch edgeless_performance_test (a4edbb1). These test cases instantiates a graph with many vertices and no edges, then call InDegree and OutDegree for each vertex, expecting 0, since there are no edges. The test case that calls InDegree is much slower than OutDegree:

# DirectedEdge
[ RUN      ] GraphTestFixture/0.EdgelessInDegree
[       OK ] GraphTestFixture/0.EdgelessInDegree (936 ms)
[ RUN      ] GraphTestFixture/0.EdgelessOutDegree
[       OK ] GraphTestFixture/0.EdgelessOutDegree (8 ms)
# UndirectedEdge
[ RUN      ] GraphTestFixture/1.EdgelessInDegree
[       OK ] GraphTestFixture/1.EdgelessInDegree (1270 ms)
[ RUN      ] GraphTestFixture/1.EdgelessOutDegree
[       OK ] GraphTestFixture/1.EdgelessOutDegree (8 ms)

For cases when a graph with directed edges represents the kinematics of a multibody system with vertices as Links and edges as Joints, the IncidentsTo function is equivalent to GetParentJoints, which is used in many places in gazebo physics.

This is an issue of performance not correctness, so it may not be a priority, but I wanted to mention it.

@osrf-migration
Copy link
Author

Original comment by Carlos Agüero (Bitbucket: caguero, GitHub: caguero).


Thanks for bringing this up and the detail description. See pull request #188.

@osrf-migration
Copy link
Author

Original comment by Steve Peters (Bitbucket: Steven Peters, GitHub: scpeters).


  • changed state from "new" to "resolved"

pull request #188

@osrf-migration osrf-migration added major bug Something isn't working labels Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant