cypher - neo4j shortest with connector node and multiple options -
i have cities, roads , transporters in database. road connected , relationship 2 (different) cities. each road has property distance (in kilometers). multiple transporters have relationship roads. every transporter has price (per kilometer).
now question. want cheapest option packet city b. there direct road or else have go via other cities , transporters. , want explicitly use dijkstra algorithm this.
can query done in cypher? , if not, how can done using neo4j java api?
based on sample dataset, think there modelisation problem makes maybe things difficult, matching on directed relationships.
however how can find lowest cost path :
match (a:city { name:'citya' }),(d:city { name:'cityd' }) match p=(a)-[*]-(d) p, filter(x in nodes(p) 'road' in labels(x)) roads p, reduce(dist = 0, x in roads | dist + x.distance) totaldistance return p, totaldistance order totaldistance limit 5
Comments
Post a Comment