Skip to content

This is real time implementation for applying a star algorithm in graph database [Neo4j].

Notifications You must be signed in to change notification settings

sangamkotalwar/A-star-in-graph-database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

A-star-in-graph-database

This is real time implementation for applying a star algorithm in graph database [Neo4j].

For visualisation we have used Neovis.js

Getting Started

Installation

Detailed installation guide for latest Neo4j can be found here.

Check

Check if the Neo4j is working by opening http://localhost:7474/browser

Enter your Username and password and you're good to go.

Pre-requisites

Important Jar Files

Download the Jar Files of APOC which already have a-star algorithm implemented, which are given in this repository.
Copy these JAR files to <neo4j-home>/plugins.

Importing Dataset

Dataset can be found here.

Dataset can be imported using this command in your Neo4j browser :

LOAD CSV WITH HEADERS FROM 
"https://raw.githubusercontent.com/geoiq/acetate/master/places/Europe-z4-z6.txt"
as row FIELDTERMINATOR "\t"
MERGE (city:City{name: row.name})
ON CREATE SET city.population = toINT(row.population), city.longitude = toFLOAT(row.longitude), city.latitude = toFLOAT(row.latitude) 
MERGE (country:Country{code: row.`country code`})
MERGE (city)-[:IS_IN]->(country)

You can change the continents using the places dataset. I've used Asia, Europe and Africa.

Distance Calculation

We calculated distance between cities and save it as a relationship property between them where the distance is less than 250km. This way we set a threshold to travel less than 250km per day on our trip and still wind up in one of the cities on the list every day.

WITH 250 as distanceInKm
MATCH (c1:City),(c2:City)
WHERE id(c1) < id(c2)
WITH c1,c2,
distance(point({longitude:c1.longitude,latitude:c1.latitude}), 
         point({longitude:c2.longitude,latitude:c2.latitude})) as distance
WHERE distance < (distanceInKm * 1000) 
MERGE (c1)-[l:LINK]->(c2)
ON CREATE SET l.distance = distance

Running the Project

Open the html file provided in the repository. Give the places => "from" and "to"
You'll get the shortest path between two cities with max. 250 km distance constraint.
The Nodes diameter increases with the increase in population of thge city and the edge's width increases with the increase in distance between the two cities, considering maximum distance to be 250 kms.

About

This is real time implementation for applying a star algorithm in graph database [Neo4j].

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages