General Graph Functions¶
This module provides some general graph functionality.
- pyrigi.graph._general.adjacency_matrix(graph, vertex_order=None)[source]¶
Return the adjacency matrix of the graph.
- Parameters:
graph (
Graph)vertex_order (
Sequence[Vertex]) – By listing vertices in the preferred order, the adjacency matrix can be computed in a way the user expects. If no vertex order is provided,vertex_list()is used.
- Return type:
Examples
>>> G = Graph([(0,1), (1,2), (1,3)]) >>> adjacency_matrix(G) Matrix([ [0, 1, 0, 0], [1, 0, 1, 1], [0, 1, 0, 0], [0, 1, 0, 0]])
Notes
networkx.linalg.graphmatrix.adjacency_matrix()requiresscipy. To avoid unnecessary imports, the function is implemented here.
- pyrigi.graph._general.degree_sequence(graph, vertex_order=None)[source]¶
Return a list of degrees of the vertices of the graph.
- Parameters:
graph (
Graph)vertex_order (
Sequence[Vertex]) – By listing vertices in the preferred order, the degree_sequence can be computed in a way the user expects. If no vertex order is provided,vertex_list()is used.
- Return type:
Examples
>>> G = Graph([(0,1), (1,2)]) >>> degree_sequence(G) [1, 2, 1]
- pyrigi.graph._general.edge_list(graph, as_tuples=False)[source]¶
Return the list of edges.
The output is sorted if possible, otherwise, the internal order is used instead.
- Parameters:
- Return type:
Examples
>>> G = Graph([[0, 3], [3, 1], [0, 1], [2, 0]]) >>> edge_list(G) [[0, 1], [0, 2], [0, 3], [1, 3]]
>>> G = Graph.from_vertices(['a', 'c', 'b']) >>> edge_list(G) []
>>> G = Graph([['c', 'b'], ['b', 'a']]) >>> edge_list(G) [['a', 'b'], ['b', 'c']]
>>> G = Graph([['c', 1], [2, 'a']]) # incomparable vertices >>> edge_list(G) [('c', 1), (2, 'a')]
- pyrigi.graph._general.max_degree(graph)[source]¶
Return the maximum of the vertex degrees.
Examples
>>> G = Graph([(0,1), (1,2)]) >>> max_degree(G) 2
- pyrigi.graph._general.min_degree(graph)[source]¶
Return the minimum of the vertex degrees.
Examples
>>> G = Graph([(0,1), (1,2)]) >>> min_degree(G) 1
- pyrigi.graph._general.vertex_list(graph)[source]¶
Return the list of vertices.
The output is sorted if possible, otherwise, the internal order is used instead.
Examples
>>> G = Graph.from_vertices_and_edges([2, 0, 3, 1], [[0, 1], [0, 2], [0, 3]]) >>> vertex_list(G) [0, 1, 2, 3]
>>> G = Graph.from_vertices(['c', 'a', 'b']) >>> vertex_list(G) ['a', 'b', 'c']
>>> G = Graph.from_vertices(['b', 1, 'a']) # incomparable vertices >>> vertex_list(G) ['b', 1, 'a']