Landmark.incidences#
- Landmark.incidences() list[tuple[Vertex, Edge]]#
Adjacent vertices paired with the edges that lead to them
- Returns:
a
(vertex, edge)pair for each edge leaving this vertex, in the order the edges were connected- Return type:
list of (Vertex subclass, Edge)
v.incidences()isadjacentandout_edgestaken together: the first element of each pair is the vertex at the far end of the edge, the second is the edge itself, so itsEdge.costandEdge.dataare at hand. It is equivalent to:list(zip(v.adjacent(), v.out_edges()))
but is built in a single pass, which is what the path-planning methods want when they expand a vertex.
Note
In graph-theory terms
adjacentis a vertex’s adjacency list,out_edgesits incidence list, and this is the two joined.For a directed graph the pairs are for the edges leaving this vertex. The ones entering it are
in_edges, and the vertices at their tails arepredecessors.There is one pair per edge, so parallel edges to the same vertex give repeated vertices with different edges, and an undirected self-loop gives the pair twice, once for each end.
>>> from pgraph import UGraph >>> g = UGraph() >>> v1 = g.add_vertex(coord=[0,0], name='v1') >>> v2 = g.add_vertex(coord=[1,1], name='v2') >>> v3 = g.add_vertex(coord=[2,2], name='v3') >>> g.add_edge(v1, v2, cost=1.5) Edge{[v1] -- [v2], cost=1.5} >>> g.add_edge(v1, v3, cost=2.5) Edge{[v1] -- [v3], cost=2.5} >>> for vertex, edge in v1.incidences(): ... print(vertex.name, edge.cost) v2 1.5 v3 2.5
- Seealso:
adjacentisadjacentsuccessorsout_edgesin_edgespredecessorsedgetoedges_toedgesedgetodegreeGraph.adjacency