cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Restricted shortest path: include nodes with certain properties in the shortest found path

techfox
Node

I have the following problem which i can't solve since a couple of days:

Due to the existing data model i have a graph containing nodes which all have the same label (:signal).
However the nodes have different "name" properties: (such as A,B,C,D,E,F,G in my example)
I want to restrict the found shortest path such that it will have the constraint to go through at least one node with the properties name  "E" and "F".
(All relationships shown here are directed ->)

     B- E- G
   /       \  /     \
 /          F        \
A                    H
  \                   /
    C     -   D

Therefore, i would expect the found restricted shortest path to be: A,B,E,G,H.

I have expiremented with the following query.

 

 

MATCH (start:signal{name:"A"})
MATCH (target:signal{name:"G"})
MATCH path = shortestPath((start)-[*]->(target))
WHERE ANY(s IN NODES(path) WHERE s:signal AND s.name in ["E", "F"])
RETURN s as signal, nodes(path) as signalPath

 

 

It works, however in a larger example with slightly longer paths and more intersections this query blows up computationally and is really slow.

I cannot constraint the amount of hops since i don't know the data beforehand and don't know how many hops the shortest path will approximately be.

I have also experimented with apoc.expand.path() but the the filtering options only allow me to filter by label and not by property.

Do you guys have any suggestions for me to try?
Thank you very much for your help!

0 REPLIES 0