0

I want to solve nearest neighbors/travelling salesman problem using Neo4j database. I have 200 cities that are connect with one another. I have tried using this code below to solve the problem but it takes forever to calculate.

MATCH (from:Node {name: "Source node" })
MATCH path = (from)-[:CONNECTED_TO*6]->()
WHERE ALL(n in nodes(path) WHERE 1 = length(filter(m in nodes(path) WHERE m = n)))
AND length(nodes(path)) = 7
RETURN path,
    reduce(distance = 0, edge in relationships(path) | distance + edge.distance)
    AS totalDistance
ORDER BY totalDistance ASC
LIMIT 1

Any help appreciated. Thanks!

0 Answers0