Find the shortest path between two nodes using Breadth-First Search.
::ShortestPath
::ShortestPath<EdgeType>::To(to_id: ID) ::ShortestPath<EdgeType>::From(from_id: ID)
QUERY GetShortestPath (from_id: ID, to_id: ID) => path <- N<Location>(from_id)::ShortestPath<Road>::To(to_id) RETURN path QUERY CreateLocation (name: String) => location <- AddN<Location>({ name: name, }) RETURN location QUERY ConnectLocations (from_id: ID, to_id: ID, distance_km: U32) => road <- AddE<Road>({ distance_km: distance_km, })::From(from_id)::To(to_id) RETURN road
from helix.client import Client client = Client(local=True, port=6969) central = client.query("CreateLocation", {"name": "Central Station"}) market = client.query("CreateLocation", {"name": "Market Square"}) harbor = client.query("CreateLocation", {"name": "Harbor"}) central_id = central[0]["location"]["id"] market_id = market[0]["location"]["id"] harbor_id = harbor[0]["location"]["id"] client.query("ConnectLocations", { "from_id": central_id, "to_id": market_id, "distance_km": 2, }) client.query("ConnectLocations", { "from_id": market_id, "to_id": harbor_id, "distance_km": 3, }) result = client.query("GetShortestPath", { "from_id": central_id, "to_id": harbor_id, }) print(result)
[([Nodes], [Edges])]
Was this page helpful?