Please see:

http://neo4j.com/docs/stable/query-match.html#_shortest_path 
<http://neo4j.com/docs/stable/query-match.html#_shortest_path>

match path1 = allShortestPaths((start:Port {name:"Buenos 
Aires"})-[:TRIP_TO*]-(end:Port {"New York"})),
path1 = allShortestPaths((start:Port {name:"New York"})-[:TRIP_TO*]-(end:Port 
{"Liverpool"})),
return path1, path2
reduce(days = 0, trip in rels(path) | days + trip.days) + reduce(days = 0, trip 
in rels(path2) | days + trip.days) as days
order by days asc



> Am 10.10.2015 um 16:28 schrieb Sebastian M Cheung <[email protected]>:
> 
> How to get say
> 
> Buenos Aires - New York - Liverpool in terms of number of days?
> and shortest path, say between Buenos Aires - Liverpool?
> 
> 
> 
> 
> 
> 
> from py2neo import Graph, Node, Relationship, authenticate
> import os
> 
> url = os.environ.get('GRAPHENEDB_URL', 'http://localhost:7474')
> username = os.environ.get('NEO4J_USERNAME')
> password = os.environ.get('NEO4J_PASSWORD')
> 
> if username and password:
>     authenticate(url.strip('http://'), username, password)
> 
> graph = Graph(url + '/db/data/')
> 
> buenos_aires = Node("Port", name="Buenos Aires")
> new_york = Node("Port", name="New York")
> liverpool = Node("Port", name="Liverpool")
> casablanca = Node("Port", name="Casablanca")
> cape_town = Node("Port", name="Cape Town")
> 
> graph.create(buenos_aires, new_york, liverpool, casablanca, cape_town)
> 
> rel1 = Relationship(buenos_aires, "TRIP_TO", new_york, days=6)
> rel2 = Relationship(buenos_aires, "TRIP_TO", casablanca, days=5)
> rel3 = Relationship(buenos_aires, "TRIP_TO", cape_town, days=4)
> rel4 = Relationship(new_york, "TRIP_TO", liverpool, days=4)
> rel5 = Relationship(liverpool, "TRIP_TO", casablanca, days=3)
> rel6 = Relationship(liverpool, "TRIP_TO", cape_town, days=6)
> rel7 = Relationship(casablanca, "TRIP_TO", liverpool, days=3)
> rel8 = Relationship(casablanca, "TRIP_TO", cape_town, days=6)
> rel9 = Relationship(cape_town, "TRIP_TO", new_york, days=8)
> 
> watch1_rels = graph.create(rel1, rel2, rel3, rel4, rel5, rel6, rel7, rel8, 
> rel9)
> 
> watch2_mygraphs = graph.cypher.execute("MATCH (n:Port) RETURN n LIMIT 5")
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Neo4j" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.
> <Screen Shot 2015-10-10 at 12.14.01.png>

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to