dynetworkx.IntervalGraph.edges

IntervalGraph.edges(u=None, v=None, begin=None, end=None, 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 interval graph)) – Inclusive beginning time of the edge appearing in the interval graph.
  • end (int or float, optional (default= end of the entire interval graph + 1)) – Non-inclusive ending time of the edge appearing in the interval graph. Must be bigger than or equal to begin. Note that the default value is shifted up by 1 to make it an inclusive end.
  • data (string or bool, optional (default=False)) – If True, return 2-tuple (Interval object, dict of attributes). If False, return just the Interval objects. If string (name of the attribute), return 2-tuple (Interval object, 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 interval object has the following format: (begin, end, (u, v))

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

Return type:

List of Interval objects

Examples

To get a list of all edges:

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

To get edges which appear in a specific interval:

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

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

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

To get a list of edges with data:

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