summaryrefslogtreecommitdiffstats
path: root/_archive/neo4j-a-star-search.md
diff options
context:
space:
mode:
Diffstat (limited to '_archive/neo4j-a-star-search.md')
-rw-r--r--_archive/neo4j-a-star-search.md48
1 files changed, 26 insertions, 22 deletions
diff --git a/_archive/neo4j-a-star-search.md b/_archive/neo4j-a-star-search.md
index 4db68d6..bbe80a6 100644
--- a/_archive/neo4j-a-star-search.md
+++ b/_archive/neo4j-a-star-search.md
@@ -5,28 +5,31 @@ author: Wickramage Don Sadeep Madurange
layout: post
---
-Back in 2018, we used the <a href="https://neo4j.com/" class="external"
-target="_blank" rel="noopener noreferrer">Neo4J</a> graph database
-to track the movement of marine vessels. We were interested in the shortest
-path a ship could take through a network of about 13,000 route points.
-Performance issues with Neo4J’s shortest-path algorithms limited our search to
-about 4,000 route points.
-
-A graph is a finite set of vertices, and a subset of vertex pairs known as
-edges. Edges can have weights. In the case of vessel tracking, the route points
-can be modeled as a graph with the distances between them as weights. For
-different reasons, people are interested in minimizing (or maximizing) the
-weight of a path through a set of vertices. For instance, we may want to find
-the shortest path between two ports.
-
-Dijkstra's algorithm is one such algorithm that finds the shortest path between
-two vertices. The one drawback of this algorithm is that it computes all the
-shortest paths from the source to all other vertices before terminating at the
-destination vertex.
-
-The following enhancement, also known as the A* search, employs spherical
-distance between route points (which are on the earth's surface) as a heuristic
-to steer the search in the direction of the destination far more quickly:
+Back in 2018, we used <a href="https://neo4j.com/" class="external"
+target="_blank" rel="noopener noreferrer">Neo4J</a> graph database to track the
+movement of marine vessels. We were interested in the shortest path a ship
+could take through a network of about 13,000 route points. Algorithms based on
+graph theory, such as A* search, provide an optimal solution to this
+problem. Therefore, it was useful to model the set of route points as a graph.
+
+A graph is a finite set of vertices, and a subset of vertex pairs (edges).
+Edges can have weights. In the case of vessel tracking, the route points form
+the vertices of a graph; the routes between them, the edges; and the distances
+between them are the weights. For different reasons, people are interested in
+minimizing (or maximizing) the weight of a path through a set of vertices. For
+instance, we may want to find the shortest path between two ports.
+
+Given such a graph, an algorithm like Dijkstra's search could compute the
+shortest path between two vertices. In fact, this was the algorithm the Neo4J
+project shipped with at the time. One drawback of Dijkstra's algorithm is that
+it computes all the shortest paths from the source to all other vertices before
+terminating at the destination vertex. The exhaustive nature of this search
+limited our search to about 4,000 route points.
+
+The following enhancement to Dijkstra's search, also known as the A* search,
+employs a heuristic to steer the search in the direction of the destination
+more quickly. In the case of our network of vessels, which are on the earth's
+surface, spherical distance is a good candidate for a heuristic:
```
package org.neo4j.graphalgo.impl;
@@ -305,6 +308,7 @@ public class ShortestPathAStar extends Algorithm<ShortestPathAStar> {
}
}
```
+
The heuristic function is domain-specific. If chosen wisely, it can
significantly speed up the search. In our case, we achieved a 300x speedup,
enabling us to expand our search from 4,000 to 13,000 route points. The <a