I have created a few nodes called routes and have given several relationships that are travel times as shown below.
SELECT *
FROM cypher('Map', $$
CREATE (a:Route {name: 'A'}),
(b:Route {name: 'B'}),
(c:Route {name: 'C'}),
(d:Route {name: 'D'}),
(e:Route {name: 'E'}),
(f:Route {name: 'F'}),
(a)-[:Connects {time: 4}]->(b),
(a)-[:Connects {time: 2}]->(c),
(b)-[:Connects {time: 6}]->(c),
(b)-[:Connects {time: 9}]->(d),
(c)-[:Connects {time: 1}]->(d),
(c)-[:Connects {time: 8}]->(e),
(c)-[:Connects {time: 3}]->(f),
(d)-[:Connects {time: 3}]->(a),
(e)-[:Connects {time: 10}]->(b),
(f)-[:Connects {time: 2}]->(e)
$$) AS (x agtype);
I am trying to find all possible connections for specified routes along with the total time travelled. For example, if I want the information from Route ‘A’ to Route ‘F’, how would I do so? I am not concerned about the shortest path but just want all the possible routes.
2
Answers
The way I think that you can solve it, is coding a DFS (Depth First Search). Marking all the visited nodes, and doing an
if
if the destination node has not been visited, and calling the dfs function recursively with this node as the new node parameter.You can write your own codes to run on Apache AGE, you just have to save it at:
I found this code in C language, maybe it can help you!
Depth First Search(DFS)
You can use the following query
Result: