Skip to content

This program provides location information using graphs and Dijkstra's algorithm.

Notifications You must be signed in to change notification settings

Giorgos-Arg/location-graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

location-graph

This java program uses a graph to calculate the shortest distance between locations and to find the closest locations from any location.

Description

By reading the the latitude, longitude and name of each location it builds a weighted graph where the weight is the distance between two locations. The distance is calculated using the Haversine formula. Each location is directly connected with a maximum of ten locations (this can be changed by changing the MAX_LIST_SIZE constant in the Graph class). The shortest distance and the closest locations are calculated using Dijkstra's algorithm.

Usage

Compilation:

javac *.java

Run:

java LocationGraph <functionality> <input_file>:

Where:

<functionality> Description
-shortdist print the shortest distance between two locations
-nclosest print the n closest locations from a given location

<input_file> is a CSV (Comma-Separated Values) file with three columns: Latitude, Longitude and Location Name

Examples

java LocationGraph -shortdist ../data/cy-locations.csv

Creating graph...

Graph is ready! You can view the graph in the file /data/graph.csv.

Give the first location:
esso galata

Give the second location:
kalyana

The shortest between esso galata and kalyana distance is : 2.12 km
java LocationGraph -nclosest ../data/cy-locations.csv

Creating graph...

Graph is ready! You can view the graph in the file /data/graph.csv.

Give a location:
sina oros

Give n:
10

The 10 closest locations from sina oros are:
1: panagia theotokos
2: esso galata
3: ayia anna
4: kalyana
5: argaki tou karvouna
6: vounaras
7: staoudies
8: virviros
9: argaki tou petkou
10: moutti tou zoumi

Author

Giorgos Argyrides (g.aryrides@outlook.com)

About

This program provides location information using graphs and Dijkstra's algorithm.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages