-
Notifications
You must be signed in to change notification settings - Fork 808
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
get_nearest_node and shortest_path performance issue #30
Comments
Using an LRU cache is an interesting idea. It that preferable to using an LFU cache in your use case? Yes I think using |
|
Hi origin_node = get_nearst_node_(graph, origin) takes between 3-30 seconds per point Trying to run the function on the entire dataset did not increase the performance (Here i'm running on a subset of the dataset). dfgp.loc[dfgp['group_id'] == id, 'origin_node'] = dfgp.loc[dfgp['group_id'] == id].apply(lambda x: ox.get_nearest_node(graph, point=(x['lat'], x['long'])), axis=1) not sure if the Any ideas? |
It could be modified to, say, take a point and a radius, then create a circle around the point, then do a spatial intersection with geopandas to retain only those nodes that lie within the circle, and then create a subgraph of only those nodes and their incident edges. But, you also said:
You can get the node nearest an arbitrary point with the get_nearest_node function. Then you can use |
I've had some time to look further into this. In your example, I see you have 70245 nodes in your graph. I created a similarly sized graph for the city of Los Angeles (n=63922) but I am not seeing the performance issues you described. However, I did find a way to improve the performance time of Testing the performanceimport osmnx as ox, networkx as nx
ox.config(log_console=True, use_cache=True)
G = ox.graph_from_place('Los Angeles, California, USA', network_type='drive_service')
print(len(G)) Next I define origin and destination lat-long points on opposite sides of LA: orig_point = (34.234, -118.535)
dest_point = (33.939, -118.242) And then get the nearest node to each: %%time
orig_node = ox.get_nearest_node(G, orig_point)
%%time
dest_node = ox.get_nearest_node(G, dest_point)
So, %%time
eg = nx.ego_graph(G, orig_node, radius=2000, distance='length')
This produces a subgraph with the 383 nodes within 2 km of But I'm more interested in the performance of the full graph. So, next I calculate the shortest path between these two nodes using the full graph: %%time
route = nx.shortest_path(G, source=orig_node, target=dest_node, weight='length')
So, it was able to calculate the path in less than a second. route_length_km = sum([G.edge[u][v][0]['length'] for u, v in zip(route, route[1:])]) / 1000. There are 341 nodes in the path and it has a total length of 51.54 km. Lastly, we can plot it to get a sense of the scale: fig, ax = ox.plot_graph_route(G, route, fig_height=20, edge_linewidth=0.3, node_size=0) Can we make this faster with vectorization?In these tests, I will test and commit these updates shortly. |
Fast vectorized great circle calculations are added in 75a7dc3 |
Thank you for the review and the great work ! |
Hi, when I use The version of osmnx is 0.8, networkx is 2.0 |
@SqySimmon please provide a complete working example of code to reproduce this issue and we'll take a look. If this is a new issue, please open a new issue. |
Sorry, I made a mistake in using: |
Is there any error in this code: route_length_km = sum([G.edge[u][v][0]['length'] for u, v in zip(route, route[1:])]) / 1000. Not working for me |
@ovdavid28 if you have general usage questions, please ask on StackOverflow per the contributing guidelines. |
I'm trying to calculate routes from thousands of points.
Running the
get_nearest_node
andshortest_path
on the following network takes a long time.In order to increase the performance of the function I think the function should select a subset of nodes (based on some parameter), there after run the great_circle() method.
I'm thinking of using
nx.ego_graph
- do you think this is a good direction?In the meantime since I have some points that repeat themselves I've used some caching techniques. Do you think it is relevant to add to the core.py?
The text was updated successfully, but these errors were encountered: