Description
Hello,
First of all, thank you for GDS, it is an amazing set of tools and I am delighted by the 1.5.0 release, which I am using with the 4.2.3 release of the Neo4j server.
I have an issue where I cannot obtain enough data from the relationships traversed in the path finding algorithms though. There is a community discussion around this as well, and it seems to not have arrived at a solution.
Say that you have a graph similar to the road network examples in the GDS documentation:
CREATE (a:Location {name: 'A'}),
(b:Location {name: 'B'}),
(c:Location {name: 'C'}),
(d:Location {name: 'D'}),
(e:Location {name: 'E'}),
(f:Location {name: 'F'}),
(a)-[:ROAD {cost: 50}]->(b),
(a)-[:ROAD {cost: 50}]->(c),
(a)-[:ROAD {cost: 100}]->(d),
(b)-[:ROAD {cost: 40}]->(d),
(b)-[:RAIL {cost: 20}]->(d),
(c)-[:ROAD {cost: 40}]->(d),
(c)-[:ROAD {cost: 80}]->(e),
(d)-[:ROAD {cost: 30}]->(e),
(d)-[:ROAD {cost: 80}]->(f),
(e)-[:ROAD {cost: 40}]->(f);
I have added a second relationship with a new label between B
and D
compared to your example.
Now, you want to apply e.g. Yen's K Shortest Paths algorithm and find paths between A
and F
:
MATCH (source:Location {name: 'A'}), (target:Location {name: 'F'})
CALL gds.beta.shortestPath.yens.stream({
nodeProjection: 'Location',
relationshipProjection: [
"ROAD",
"RAIL"
],
relationshipProperties: "cost",
sourceNode: id(source),
targetNode: id(target),
k: 3,
relationshipWeightProperty: 'cost',
path: true
})
YIELD index, nodeIds, costs, path
RETURN
index,
[nodeId IN nodeIds | gds.util.asNode(nodeId).name] AS nodeNames,
costs,
path
ORDER BY index
If I look at the path
results of the first record I see
{
"start": {
"identity": 0,
"labels": [
"Location"
],
"properties": {
"name": "A"
}
},
"end": {
"identity": 5,
"labels": [
"Location"
],
"properties": {
"name": "F"
}
},
"segments": [
{
"start": {
"identity": 0,
"labels": [
"Location"
],
"properties": {
"name": "A"
}
},
"relationship": {
"identity": -1,
"start": 0,
"end": 1,
"type": "PATH_0",
"properties": {
"cost": 50.0
}
},
"end": {
"identity": 1,
"labels": [
"Location"
],
"properties": {
"name": "B"
}
}
},
[...]
],
"length": 4.0
}
I can get the nodes, with ids and properties, but I have no identification to match which of the available relationships that was traversed in the segments[i].relationship
specification. It creates a new PATH_0
type and does not relay any properties except the one specified in the relationshipWeightProperty
. All I have to match with is the cost
property (which in most cases in my usecase will be enough, even though I guess that matching needs to be done in the application by repeatedly querying the database for relationships between these nodes with the corresponding cost
).
I have tried with native projections, anonymous projections and cypher projections with the same results.
Questions:
- Is it possible to do right now?
- Is it possible to implement it?
- If so, I might be able to make an attempt to implement it if you would accept that. That is if there isn't a good reason for creating
PATH_X
type relationships and returning those instead that I am unaware of?