interval_graph#
- interval_graph(intervals)[source]#
Generates an interval graph for a list of intervals given.
In graph theory, an interval graph is an undirected graph formed from a set of closed intervals on the real line, with a vertex for each interval and an edge between vertices whose intervals intersect. It is the intersection graph of the intervals.
More information can be found at: https://en.wikipedia.org/wiki/Interval_graph
- Parameters:
- intervalsa sequence of intervals, say (l, r) where l is the left end,
- and r is the right end of the closed interval.
- Returns:
- Gnetworkx graph
- Raises:
TypeError
if
intervals
contains None or an element which is not collections.abc.Sequence or not a length of 2.ValueError
if
intervals
contains an interval such that min1 > max1 where min1,max1 = interval
Examples
>>> intervals = [(-2, 3), [1, 4], (2, 3), (4, 6)] >>> G = nx.interval_graph(intervals) >>> sorted(G.edges) [((-2, 3), (1, 4)), ((-2, 3), (2, 3)), ((1, 4), (2, 3)), ((1, 4), (4, 6))]