Edge
- class PGraph.Edge(v1=None, v2=None, cost=None, data=None)[source]
Bases:
object
Edge class
Is used to represent directed directed and undirected edges.
Each edge has: -
cost
cost of traversing this edge, required for planning methods -data
reference to arbitrary data associated with the edge -v1
first vertex, start vertex for a directed edge -v2
second vertex, end vertex for a directed edgeNote
An undirected graph is created by having a single edge object in the edgelist of _each_ vertex.
This class can be inherited to provide user objects with graph capability.
Inheritance is an alternative to providing arbitrary user data.
An Edge points to a pair of vertices. At
connect
time the vertices get references back to the Edge object.graph.add_edge(v1, v2)
callsv1.connect(v2)
- __init__(v1=None, v2=None, cost=None, data=None)[source]
Create an edge object
- Parameters:
v1 (Vertex subclass, optional) – start of the edge, defaults to None
v2 (Vertex subclass, optional) – end of the edge, defaults to None
cost (any, optional) – edge cost, defaults to None
data (any, optional) – edge data, defaults to None
Creates an edge but does not connect it to the vertices or add it to the graph.
If vertices are given, and have associated coordinates, the edge cost will be computed according to the distance measure associated with the graph.
data
is a way of associating any object with the edge, its value can be found as the.data
attribute of the edge. An alternative approach is to subclass theEdge
class.Note
To compute edge cost from the vertices, the vertices must have been added to the graph.
- Seealso:
- connect(v1, v2)[source]
Add edge to the graph
- Parameters:
v1 (Vertex subclass) – start of the edge
v2 (Vertex subclass) – end of the edge
The edge is added to the graph and connects vertices
v1
andv2
.Note
The vertices must already be added to the graph.
- property endpoints
- next(vertex)[source]
Return other end of an edge
- Parameters:
vertex (Vertex subclass) – one vertex on the edge
- Raises:
ValueError –
vertex
is not on the edge- Returns:
the other vertex on the edge
- Return type:
Vertex subclass
e.next(v1)
is the vertex at the other end of edgee
, ie. the vertex that is notv1
.