Directed graph vertex

class PGraph.DVertex(coord=None, name=None)[source]

Bases: Vertex

Vertex subclass for directed graphs

This class can be inherited to provide user objects with graph capability.

Inheritance diagram of DVertex
__init__(coord=None, name=None)
closest()
connect(other, **kwargs)[source]

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 Edge object is created from the vertices being connected, and the cost and edge 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:

TypeError – vertex types are different subclasses

Returns:

the edge connecting the vertices

Return type:

Edge

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

Note

  • If the vertices subclass UVertex the edge is undirected, and if they subclass DVertex the edge is directed.

  • Vertices must both be of the same Vertex subclass

Seealso:

Edge()

copy(cls=None)
property degree

Degree of vertex

Returns:

degree of the vertex

Return type:

int

Returns the number of edges connected to the vertex.

Note

For a DGraph only outgoing edges are considered.

Seealso:

edges()

distance(coord)

Distance from vertex to point

Parameters:

coord (ndarray(n) or Vertex) – coordinates of the point

Returns:

distance

Return type:

float

Distance is computed according to the graph’s metric.

Seealso:

metric()

edges()

All outgoing edges of vertex

Returns:

List of all edges leaving this vertex

Return type:

list of Edge

Note

  • For a directed graph the edges are those leaving this vertex

  • For a non-directed graph the edges are those leaving or entering

    this vertex

edgeto(dest)

Get edge connecting vertex to specific neighbour

Parameters:

dest (Vertex subclass) – a neigbouring vertex

Raises:

ValueErrordest is not a neighbour

Returns:

the edge from this vertex to dest

Return type:

Edge

Note

  • For a directed graph dest must be at the arrow end of the edge

heuristic_distance(v2)
incidences()

Neighbours and edges of a vertex

v.incidences() is a generator that returns a list of incidences, tuples of (vertex, edge) for all neighbours of the vertex v.

Note

For a directed graph the edges are those leaving this vertex

isneighbour(vertex)

Test if vertex is a neigbour

Parameters:

vertex (Vertex subclass) – vertex reference

Returns:

true if a neighbour

Return type:

bool

For a directed graph this is true only if the edge is from self to vertex.

neighbors()

Neighbors of a vertex

v.neighbors() is a list of neighbors of this vertex.

Note

For a directed graph the neighbours are those on edges leaving this vertex

neighbours()

Neighbours of a vertex

v.neighbours() is a list of neighbours of this vertex.

Note

For a directed graph the neighbours are those on edges leaving this vertex

remove()[source]
property x

The x-coordinate of an embedded vertex

Returns:

The x-coordinate

Return type:

float

property y

The y-coordinate of an embedded vertex

Returns:

The y-coordinate

Return type:

float

property z

The z-coordinate of an embedded vertex

Returns:

The z-coordinate

Return type:

float