Skip to content

Render map from data file and find the shortest path between any two points using graph and djikstra's algorithm

Notifications You must be signed in to change notification settings

codicate/map-renderer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

map-renderer

This project uses graph and djikstra's algorithm to render map from data file and find the shortest path between any two points.

Usage

java StreetMap input/[map].txt --show --directions [start] [end]

java StreetMap input/monroe.txt --show --directions i3232 i5942

Explaination

The program first reads through the map data file, and put all intersections into a hash table of nodes, and all street segments into a hash set of edges. Min/max latitude/longitude are recorded to make sure the map fit inside the display windows. We then simply need to loop through the edge, get the longitude and latitude of the start and end, and draw a line between them using Java graphics.

Before I draw the street segments, I first store the segments that makes up the shortest pathinto a hash set. This way, when looping through the edges, I can simply check if the current edge is in the hash set, and if it is, I draw it in red. I used djikstra's algorithm to calculate the shortest path, which will corrects updates the prev variables for each nodes up to the end node. Then we work our ways backward from end to start to store the shortest path into the hash set.

Images

Screenshot_20221215_010335 Screenshot_20221215_010545

About

Render map from data file and find the shortest path between any two points using graph and djikstra's algorithm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages