Landmark.degree#

property Landmark.degree: int#

Degree of vertex

Returns:

degree of the vertex

Return type:

int

The number of edge ends at this vertex: the edges leaving it plus the edges entering it, so a self-loop counts twice. The degrees of all the vertices of a graph sum to twice its number of edges.

For an undirected graph this is the number of incident edges. For a directed graph it is in_degree + out_degree.

Changed in version 1.0: For a DGraph this used to count only the edges leaving the vertex. It is now the graph-theory degree, in plus out. Use out_degree for the previous value.

>>> from pgraph import DGraph
>>> g = DGraph()
>>> v1 = g.add_vertex(coord=[0,0], name='v1')
>>> v2 = g.add_vertex(coord=[1,1], name='v2')
>>> v3 = g.add_vertex(coord=[2,2], name='v3')
>>> g.add_edge(v1, v2)
Edge{[v1] -> [v2], cost=1.414}
>>> g.add_edge(v1, v3)
Edge{[v1] -> [v3], cost=2.828}
>>> g.add_edge(v3, v1)
Edge{[v3] -> [v1], cost=2.828}
>>> print(v1.degree, v1.in_degree, v1.out_degree)
3 1 2

For graphs with parallel edges or loops

Every edge is counted, so k parallel edges to the same vertex add k. A self-loop adds 2, for both kinds of graph: it has two ends.

Seealso:

in_degree out_degree edges Graph.degree Graph.connectivity