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
.osm
format. - Use this tool to convert file format from
.osm
to.pbf
. Make sure that you use the tool in the same directory wheremap.osm
is present. - Get a rust distribution with cargo.
- Run
cargo --version
to check if the package has been installed correctly. If not, use google. Runcargo install osm4routing
to installosm4routing
package. The.csv
files have a header row, to know more, refer theosm4routing
code here. - Use command
osm4routing <path_to_your.osm.pbf>
in cmd. This will yield two.csv
files namelynodes.csv
andedges.csv
inC:\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.