pygraphs.graph_to_adjacency_list#
- graph_to_adjacency_list(graph, *, weighted=False, weight_key='weight', dicted=True, skip_validation=False)[source]#
Convert a graph represented as a dictionary (
GraphRepresentation) to a graph represented as an adjacency list (AdjacencyList).AdjacencyList:
List[List[Integral]]]: A list of lists, where the outer list has a length equal to the number of vertices in the graph, and each inner list contains the neighbors (i.e.,[v1, v2, ...]) of the corresponding vertex (from outer vertex to inner vertex). For a weighted graph, the formList[List[Tuple[Integral, Real]]]is used where the inner lists contain tuples of the form \((v, w)\), where \(v\) is a neighbor vertex and \(w\) is the weight of the edge connecting the vertex to its neighbor. To store more than weight, the formList[List[Tuple[Integral, Dict[str, Any]]]]is used.
GraphRepresentation:
Dict[int, Dict[int, Dict[str, Any]]]: A dictionary where the keys are vertex identifiers and the values are dictionaries mapping neighboring vertex identifiers to edge attributes (e.g.,weight). This is the internal representation used by thepygraphs.Graphclass.
- Parameters:
graph (GraphRepresentation) – The graph represented as a dictionary.
weighted (bool, optional (default:
False)) – Whether to represent the graph asList[List[Tuple[Integral, Real]]].weight_key (Optional[str], optional (default:
'weight')) – The key to use for accessing the weight of an edge in the graph representation. Ignored ifweightedis False.dicted (bool, optional (default:
False)) – Whether to represent the graph asList[List[Tuple[Integral, Dict[str, Any]]]].
- Returns:
adjacency_list – The graph represented as an adjacency list.
- Return type:
AdjacencyList