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 (
Vertexsubclass) – The vertex to connect toedge (
Edgesubclass, optional) – Use this as the edge object, otherwise a new object of the graph’sGraph.edge_classis created from the vertices being connected, and thecostanddataparameters, defaults to Nonecost (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
edgealready connects other verticesTypeError –
edgeis not an instance of the graph’sGraph.edge_class
- Returns:
the edge connecting the vertices
- Return type:
Edge
v1.connect(v2)connects vertexv1to vertexv2.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
edgebuilt without vertices has itsv1andv2set to the vertices being connected. One built with vertices must agree with them: in either order if undirected, exactlyselfthendestif 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:
EdgeEdge.connect