pygraphs.graph_to_edges_list#

graph_to_edges_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 edge list (Edges).

  • Edges: List[Tuple[Integral, Integral]]: A list of tuples, where each tuple represents an edge \((u, v)\) in the graph (from vertex \(u\) to vertex \(v\)). For a undirected graph consider converting in pygraphs.Graph class and use the to_undirected method to duplicate \((u, v)\) into \((u, v)\) and \((v, u)\). For a weighted graph, the form List[Tuple[Integral, Integral, Real]] containing \((u, v, w)\) is used, where \(u\) and \(v\) are the vertices connected by the edge and \(w\) is the weight of the edge. To store more than weight, the form List[Tuple[Integral, 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 the pygraphs.Graph class.

Parameters:
  • graph (GraphRepresentation) – The graph represented as a dictionary.

  • weighted (bool, optional (default: False)) – Whether to represent the graph as List[Tuple[Integral, 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 if weighted is False.

  • dicted (bool, optional (default: False)) – Whether to represent the graph as List[Tuple[Integral, Integral, Dict[str, Any]]].

Returns:

edge_list – The graph represented as an edge list.

Return type:

Edges