Note
This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.
rustworkx.hyperbolic_greedy_routing#
- hyperbolic_greedy_routing(graph, pos, source, destination)#
Performs the greedy routing algorithm from
sourcetodestinationusing the hyperbolic distance.The greedy routing algorithm attempts to find the shortest path between
sourceanddestinationby starting fromsourceand continuously going to the neighbor closest todestination. The closest neighbor of \(u\) is the node \(v\) that minimizes the hyperbolic distance\[d(u,v) = \text{arccosh}\left[x_0(u) x_0(v) - \sum_{j=1}^D x_j(u) x_j(v) \right],\]where \(D\) is the dimension of the hyperbolic space and \(x_d(u)\) is the \(d\) th-dimension coordinate of node \(u\) in the hyperboloid model. The distance is computed using
pos, an array of shape (n, D) in which the \(i\)-th row is the position of the \(i\) -th indexed vertex in the graph. The dimension is inferred from the coordinatesposand the 0-dimension “time” coordinate is inferred from the other coordinates. Note that the hyperbolic space is at least 2 dimensional.Note
Node indices are constant across removal of nodes. Since
posmaps rows to node indices, the unused rows should not be deleted.This algorithm has a time complexity of \(O(m)\) for \(m\) edges.
- Parameters:
graph (PyGraph) – The input graph.
pos (list[list[float]]) – Hyperboloid coordinates of the nodes [[\(x_1(1)\), …, \(x_D(1)\)], [\(x_1(2)\), …, \(x_D(2)\)], …]. The “time” coordinate \(x_0\) is inferred from the other coordinates.
source (int) – source of the greedy routing path.
destination (int) – destination of the greedy routing path.
- Returns:
A tuple
(path, length)wherepathis the path followed andlengthis the sum of the distance between nodes on the path. ReturnsNoneif the greedy algorithm fails. to reachdestination.- Return type:
Optional[tuple[list[int], float]]