dynetworkx.ImpulseGraph.edges

ImpulseGraph.edges(u=None, v=None, begin=None, end=None, inclusive=(True, True), data=False, default=None)

Returns a list of Interval objects of the IntervalGraph edges.

All edges which are present within the given interval.

All parameters are optional. u and v can be thought of as constraints. If no node is defined, all edges within the interval are returned. If one node is defined, all edges which have that node as one end, will be returned, and finally if both nodes are defined then all edges between the two nodes are returned.

Parameters:
  • v (u,) – Nodes can be, for example, strings or numbers. Nodes must be hashable (and not None) Python objects. If the node does not exist in the graph, a key error is raised.
  • begin (int or float, optional (default= beginning of the entire impulse graph)) –
  • end (int or float, optional (default= end of the entire impulse graph)) – Must be bigger than or equal to begin.
  • inclusive (2-tuple boolean that determines inclusivity of begin and end) –
  • data (string or bool, optional (default=False)) – If True, return 2-tuple (Edge Tuple, dict of attributes). If False, return just the Edge Tuples. If string (name of the attribute), return 2-tuple (Edge Tuple, attribute value).
  • default (value, optional (default=None)) – Default Value to be used for edges that don’t have the requested attribute. Only relevant if data is a string (name of an attribute).
Returns:

An edge tuple has the following format: (u, v, edge_id, timestamp)

When called, if data is False, a list of edge tuples. If data is True, a list of 2-tuples: (Edge Tuple, dict of attribute(s) with values), If data is a string, a list of 2-tuples (Edge Tuple, attribute value).

Return type:

List of Edge Tuples

Examples

To get a list of all edges:

>>> G = dnx.IntervalGraph()
>>> G.add_edges_from([(1, 2, 10), (2, 4, 11), (6, 4, 19), (2, 4, 15)])
>>> G.edges()
[(1, 2, 10), (2, 4, 11), (2, 4, 15), (6, 4, 19)]

To get edges which appear in a specific interval:

>>> G.edges(begin=10)
[(1, 2, 10), (2, 4, 11), (2, 4, 15), (6, 4, 19)]
>>> G.edges(end=11)
[(1, 2, 10), (2, 4, 11)]
>>> G.edges(begin=11, end=15)
[(2, 4, 11), (2, 4, 15)]

To get edges with either of the two nodes being defined:

>>> G.edges(u=2)
[(2, 4, 11), (2, 4, 15)]
>>> G.edges(u=2, begin=11)
[(2, 4, 11), (2, 4, 15)]
>>> G.edges(u=2, v=4, end=11)
[(2, 4, 11)]
>>> G.edges(u=1, v=6)
[]

To get a list of edges with data:

>>> G = dnx.ImpulseGraph()
>>> G.add_edge(1, 3, 4, weight=8, height=18)
>>> G.add_edge(1, 2, 10, weight=10)
>>> G.add_edge(2, 6, 10)
>>> G.edges(data="weight")
[((1, 3, 4), 8), ((1, 2, 10), 10), ((2, 6, 10), None)]
>>> G.edges(data="weight", default=5)
[((1, 3, 4), 8), ((1, 2, 10), 10), ((2, 6, 10), 5)]
>>> G.edges(data=True)
[((1, 3, 4), {'weight': 8, 'height': 18}), ((1, 2, 10), {'weight': 10}), ((2, 6, 10), {})]
>>> G.edges(u=1, begin=2, end=9, data="weight")
[((1, 3, 4), 8)]