0

I have a list of machines with longitude and latitude within a city. From a starting point, I need to traverse all the machines with minimum effort.There is no relationship between each machines.

I'm exploring Neo4j to solve this problem. Question:

Option1: I have tried Neo4j spatial, added a SimplePointLayer to it, but couldn't find an algorithm to find the best routing.
Is there any way to achieve this with Neo4j Spatial?

Option2: 1. I've seen many examples of putting road data into Neo4j as relationships to the nodes?
How can I load road data from map to my Neo4j?
2. If road data can be loaded to Neo4j, seems like minimum spanning tree algorithm can solve the problem ?

xuan zou
  • 1
  • 1

1 Answers1

0

I think the best approach would be to create relationships based on the latitude and longitude properties of the node. Neo4j can calculate the distance based on two points, so you can create relationships between cities. You should define an arbitrary threshold below which distance the relationship should be created. This is an example from the docs:

WITH point({ longitude: 12.78, latitude: 56.7}) AS p1, 
     point({ latitude: 56.71, longitude: 12.79}) AS p2
RETURN distance(p1,p2) AS dis

In the next step, you can the minimum spanning tree as you suggested from the GDS library. This is the example algorithm execution from the docs:

MATCH (n:Place {id: 'D'})
CALL gds.alpha.spanningTree.minimum.write({
  nodeProjection: 'Place',
  relationshipProjection: {
    LINK: {
      type: 'LINK',
      properties: 'cost',
      orientation: 'UNDIRECTED'
    },
    startNodeId: id(n),
    relationshipWeightProperty: 'cost',
    writeProperty: 'MINST',
    weightWriteProperty: 'writeCost'
  }
})
YIELD createMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN createMillis, computeMillis, writeMillis, effectiveNodeCount;
Tomaž Bratanič
  • 6,319
  • 2
  • 18
  • 31