Landmark.connect#

Landmark.connect(dest: Vertex, edge: Edge | None = None, cost: float | None = None, data: Any = None) → Edge#

Connect two vertices with an edge

Parameters:
  • dest (Vertex subclass) – The vertex to connect to

  • edge (Edge subclass, optional) – Use this as the edge object, otherwise a new object of the graph’s Graph.edge_class is created from the vertices being connected, and the cost and data parameters, defaults to None

  • cost (float, optional) – the cost to traverse this edge, defaults to None

  • data (Any, optional) – reference to arbitrary data associated with the edge, defaults to None

Raises:
  • ValueError – either vertex has not been added to a graph, the vertices belong to different graphs, or edge already connects other vertices

  • TypeError – edge is not an instance of the graph’s Graph.edge_class

Returns:

the edge connecting the vertices

Return type:

Edge

v1.connect(v2) connects vertex v1 to vertex v2.

Note

  • In an undirected graph the edge is recorded in the edge list of both vertices, so it is found from either end. In a directed graph it is recorded as leaving this, the start, vertex and entering dest.

  • A supplied edge built without vertices has its v1 and v2 set to the vertices being connected. One built with vertices must agree with them: in either order if undirected, exactly self then dest if directed.

  • Both vertices must already have been added to the same graph, e.g. via Graph.add_vertex.

>>> from pgraph import UGraph
>>> g = UGraph()
>>> v1 = g.add_vertex(coord=[0,0], name='v1')
>>> v2 = g.add_vertex(coord=[1,1], name='v2')
>>> e = v1.connect(v2, cost=1.414)
>>> print(e)
Edge{[v1] -- [v2], cost=1.414}
Seealso:

Edge Edge.connect