An implementation of a star algorithm in python3 to find the shortest path between two given locations.
- First download the map data from openstreetmap. After exporting, if the file doesn't have any filename extension then change it to a
.osmformat. - Use this tool to convert file format from
.osmto.pbf. Make sure that you use the tool in the same directory wheremap.osmis present. - Get a rust distribution with cargo.
- Run
cargo --versionto check if the package has been installed correctly. If not, use google. Runcargo install osm4routingto installosm4routingpackage. The.csvfiles have a header row, to know more, refer theosm4routingcode here. - Use command
osm4routing <path_to_your.osm.pbf>in cmd. This will yield two.csvfiles namelynodes.csvandedges.csvinC:\Users\<Username>
To run the code on this repo, the nodes.csv and edges.csv files can be downloaded. Pseudocode for A* star algorithm is given on wikipedia.
This implementation of A* is not very efficient for reasons:
- The use of pandas dataframe for graph construction. The graph can be constructed directly by parsing the edges.csv file.
- The heuristic function can make sql queries instead of searching lat lons in pandas dataFrame.
There are various such other possibilities that can help make this code run more efficiently. To contribute, please create a pull request.
