Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-13-2021 12:19 AM
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
Solved! Go to Solution.
04-13-2021 01:59 AM
The Neo4j Graph Algorithms plugin has been replace by the Neo4j Graph Data Science GDS plugin.
*
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
04-13-2021 01:04 AM
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
04-13-2021 01:45 AM
Hi Cobra-san,
Thank you for your reply.
Here is version of DBMS.
Version 4.2.4
And here is error message.
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.
04-13-2021 01:59 AM
The Neo4j Graph Algorithms plugin has been replace by the Neo4j Graph Data Science GDS plugin.
*
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
04-13-2021 03:31 AM
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
04-13-2021 03:59 AM
No problem, don't hesitate to ask if you can't find
04-15-2021 11:22 PM
04-15-2021 11:32 PM
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?
04-16-2021 12:01 AM
Can you give me the Cypher requests to create the graph please?
04-16-2021 02:56 AM
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)
04-16-2021 02:58 AM
04-16-2021 03:18 AM
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
04-19-2021 03:16 AM
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
05-27-2021 10:03 PM
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.
05-28-2021 01:03 AM
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
All the sessions of the conference are now available online