dynetworkx.IntervalGraph.to_snapshots

IntervalGraph.to_snapshots(number_of_snapshots, multigraph=False, edge_data=False, edge_interval_data=False, node_data=False, return_length=False)

Return a list of networkx Graph or MultiGraph objects as snapshots of the interval graph in consecutive order.

Parameters:
  • number_of_snapshots (integer) – Number of snapshots to divide the interval graph into. Must be bigger than 1.
  • multigraph (bool, optional (default= False)) – If True, a networkx MultiGraph will be returned. If False, networkx Graph.
  • edge_data (bool, optional (default= False)) – If True, edges will keep their attributes.
  • edge_interval_data (bool, optional (default= False)) – If True, each edge’s attribute will also include its begin and end interval data. If edge_data= True and there already exist edge attributes with names begin and end, they will be overwritten.
  • node_data (bool, optional (default= False)) – if True, each node’s attributes will be included.
  • return_length (bool, optional (default= False)) – If true, the length of snapshots will be returned as the second argument.

See also

to_subgraph()
subgraph based on an interval

Notes

In order to create snapshots, begin and end interval objects of the interval graph must be numbers.

If multigraph= False, and edge_data=True or edge_interval_data=True, in case there are multiple edges, only one will show with one of the edge’s attributes.

Examples

Snapshots of NetworkX Graph

>>> G = dnx.IntervalGraph()
>>> G.add_edges_from([(1, 2, 3, 10), (2, 4, 1, 11), (6, 4, 12, 19), (2, 4, 8, 15)])
>>> S, l = G.to_snapshots(2, edge_interval_data=True, return_length=True)
>>> S
[<networkx.classes.graph.Graph object at 0x100000>, <networkx.classes.graph.Graph object at 0x150d00>]
>>> l
9.0
>>> for g in S:
>>> ... g.edges(data=True))
[(1, 2, {'begin': 3, 'end': 10}), (2, 4, {'begin': 8, 'end': 15})]
[(2, 4, {'begin': 8, 'end': 15}), (4, 6, {'begin': 12, 'end': 19})]

Snapshots of NetworkX MultiGraph

>>> S, l = G.to_snapshots(3, multigraph=True, edge_interval_data=True, return_length=True)
>>> S
[<networkx.classes.multigraph.MultiGraph object at 0x1060d40b8>, <networkx.classes.multigraph.MultiGraph object at 0x151020c9e8>, <networkx.classes.multigraph.MultiGraph object at 0x151021d390>]
>>> l
6.0
>>> for g in S:
>>> ... g.edges(data=True))
[(1, 2, {'end': 10, 'begin': 3}), (2, 4, {'end': 11, 'begin': 1})]
[(1, 2, {'end': 10, 'begin': 3}), (2, 4, {'end': 11, 'begin': 1}), (2, 4, {'end': 15, 'begin': 8}), (4, 6, {'end': 19, 'begin': 12})]
[(2, 4, {'end': 15, 'begin': 8}), (4, 6, {'end': 19, 'begin': 12})]