0

In neo4j i'm using GDS' Yen's k-algo to get top 3 shortest path between two nodes.

but im having hard time projecting my graph into memory thus Yen's k alog not giving me my desired output.

CALL gds.graph.project(
  'test1',
  ['A', 'B', 'C', 'D'],
  {Director_In: {orientation: 'UNDIRECTED'}, Shareholder_In: {orientation: 'UNDIRECTED'}}
  )
YIELD
  graphName AS graph, nodeCount AS nodes, relationshipCount AS rels

this gives me result but with virtual relationship having nagative cost like PATH_0, PATH_1 PATH_2... (some guy on discord suggested me to use Undirected orientation) virtual relationships

but when i'm using cupher projection im getting no result..

CALL gds.graph.project.cypher(
  'persons',
  'MATCH (n) RETURN id(n) AS id',
  'MATCH (n)-[r]->(m) RETURN id(n) AS source, id(m) AS target, type(r) AS type')
YIELD
  graphName AS graph, nodeQuery, nodeCount AS nodes, relationshipQuery, relationshipCount AS rels

and below is my cypher query

MATCH (source:A {prop: 1}), (target:B {prop: 3})
CALL gds.shortestPath.yens.stream('persons', {
sourceNode: source,
targetNode: target, 
k:4
})
YIELD index, sourceNode, targetNode, totalCost, nodeIds, costs, path
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,
nodes(path) as path

PS:- when im using normal shortestPath i get the desired result.

MATCH path = shortestPath((start:A)-[*]-(end:B))
where elementId(start) = "1:x:4" and elementId(end) = "124:x:123"   

i get my desired output from the above query.this is the shortest path

How should i project my graph so that i can get the desired result?

(also my graph is not weighted)

RTK
  • 17
  • 7
  • The simplest reason why your query doesn't return anything is that your `MATCH` statement isn't returning two nodes. Did you check that your graph contains `prop:1` and `prop:3`? They could, for example, be in the graph as `"1"` and `"3"`. – Vincent Rupp Apr 27 '23 at 20:16

0 Answers0