Observation.connect#

Observation.connect(v1: Vertex, v2: Vertex) → None#

Attach this edge to a pair of vertices

Parameters:
  • v1 (Vertex subclass) – start of the edge

  • v2 (Vertex subclass) – end of the edge

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

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

The edge connects vertices v1 and v2, and is added to the graph that those vertices belong to.

Warning

Intended for an edge that is not yet part of a graph. The edge’s v1 and v2 are overwritten without checking, so connecting an edge that is already in a graph leaves it referenced from its old vertices as well.

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

Note

The vertices must already be added to the graph.

Seealso:

Vertex.connect