ta-oka
(Ta Okano)
April 13, 2021, 7:19am
1
Hi,
I'm trying to get shotest path according to relationships property "Length" that have length of able.
I tried to use "algo.shortestPath.stream" but it does not work.
I think it instead of other algorism.
does anyone know what algorism should i use?
-neo4j version, desktop 1.4.3,
-query
MATCH (start:Point{name:"90000000049676"}), (finish:Point{name:"390000000040694"})
CALL algo.shortestPath.stream(start, finish, "Length")
YIELD nodeId, cost
MATCH (n) WHERE id(n)=nodeId
return n.name, cost
cobra
(Cobra)
April 13, 2021, 8:04am
2
Hello @ta-oka
Can you give us the version of your Neo4j database?
It doesn't work because there is an error or the results are not correct?
Regards,
Cobra
ta-oka
(Ta Okano)
April 13, 2021, 8:45am
3
Hi Cobra-san,
Thank you for your reply.
Here is version of DBMS.
Version 4.2.4
And here is error message.
Neo.ClientError.Procedure.ProcedureNotFound
There is no procedure with the name algo.shortestPath.stream
registered for this database instance. Please ensure you've spelled the procedure name correctly and that the procedure is properly deployed.
cobra
(Cobra)
April 13, 2021, 8:59am
4
The Neo4j Graph Algorithms plugin has been replace by the Neo4j Graph Data Science GDS plugin.
So you must install GDS on your database.
Then create an in-memory graph to execute the algorithm on it (you can replace the *
by the relationship type or the list of relationship types):
CALL gds.graph.create(
'myGraph',
'Point',
'*',
{
relationshipProperties: 'Length'
}
)
MATCH (start:Point {name:"90000000049676"}), (finish:Point {name:"390000000040694"})
CALL gds.beta.shortestPath.dijkstra.stream('myGraph', {
sourceNode: id(start),
targetNode: id(finish),
relationshipWeightProperty: 'Length'
})
YIELD index, sourceNode, targetNode, totalCost, nodeIds, costs
RETURN
index,
gds.util.asNode(sourceNode).name AS sourceNodeName,
gds.util.asNode(targetNode).name AS targetNodeName,
totalCost,
[nodeId IN nodeIds | gds.util.asNode(nodeId).name] AS nodeNames,
costs
ORDER BY index
Regards,
Cobra
1 Like
ta-oka
(Ta Okano)
April 13, 2021, 10:31am
5
Hello Cobra-san,
Thank you for your response.
Syntax is OK, but result is "(no changes, no records)".
I think I mistake something due to I am newer about neo4j.
I will try to take look and resolve.
anyway thanks for your useful response
BR oka
cobra
(Cobra)
April 13, 2021, 10:59am
6
No problem, don't hesitate to ask if you can't find
ta-oka
(Ta Okano)
April 16, 2021, 6:32am
9
Hi,
problem is "no change ,no record" on my neo4j.
I doubt name type and change to string to integer but does not work.
I attached some node and relation info, do you have any idea what should i check any point?
cobra
(Cobra)
April 16, 2021, 7:01am
10
Can you give me the Cypher requests to create the graph please?
ta-oka
(Ta Okano)
April 16, 2021, 9:56am
11
Hi Cobra-san,
Sorry for bothering you.
I attached sample csv files for test.
Could you import below files.
Thank you for your support
BR//Oka
・Node_0416.csv (need to change file name txt to csv due to upload issue)
LOAD CSV WITH HEADERS FROM 'file:///Node_0416.csv' AS line
CREATE (:Point { name:line.FromID})
・Relation(need to change file name txt to csv due to upload issue)
LOAD CSV WITH HEADERS FROM "file:///Rel_0416.csv" AS csvLine
MATCH (a:Point {name:csvLine.FromID}), (b:Point {name:csvLine.ToID})
CREATE (a)-[:Cable {Length: csvLine.Length,Structure: csvLine.Structure,Capa: csvLine.Capa,Used: csvLine.Used,Rate: csvLine.Rate}]->(b)
ta-oka
(Ta Okano)
April 16, 2021, 9:58am
12
sorry attached file are here.Node_0416.txt (65 Bytes) Rel_0416.txt (247 Bytes)
cobra
(Cobra)
April 16, 2021, 10:18am
13
Convert Length
property to floats:
MATCH p=()-[r:Cable]->() SET r.Length = toFloat(r.Length)
Create the in-memory graph:
CALL gds.graph.create(
'myGraph',
'Point',
'Cable',
{
relationshipProperties: 'Length'
}
)
Get the shortest path:
MATCH (start:Point {name:"1001"}), (finish:Point {name:"1007"})
CALL gds.beta.shortestPath.dijkstra.stream('myGraph', {
sourceNode: id(start),
targetNode: id(finish),
relationshipWeightProperty: 'Length'
})
YIELD index, sourceNode, targetNode, totalCost, nodeIds, costs
RETURN
index,
gds.util.asNode(sourceNode).name AS sourceNodeName,
gds.util.asNode(targetNode).name AS targetNodeName,
totalCost,
[nodeId IN nodeIds | gds.util.asNode(nodeId).name] AS nodeNames,
costs
ORDER BY index
It returns:
Regards,
Cobra
ta-oka
(Ta Okano)
April 19, 2021, 10:16am
14
Hi Cobra-san,
Thank you so much for your support!
Your cypher is working and that result is I want.
I really appreciate for your support.
BR//Okano
1 Like
ta-oka
(Ta Okano)
May 28, 2021, 5:03am
15
Hi,
I have additional question.
Can I get multiple path according to in the order of relation property that is length.
Sometimes cannot use shortest path.so i would like to know top5 path.
cobra
(Cobra)
May 28, 2021, 8:03am
16
Hello @ta-oka
You should always open a new topic since it's a different problem.
You should have a look at the allShortestPaths() function.
Regards,
Cobra