interval_graph#
- graph_tool.generation.interval_graph(intervals)[git][source]#
Return the interval graph of a set of closed intervals.
- Parameters:
- intervalsiterable of pairs of
float Lower and upper bounds of every interval.
- intervalsiterable of pairs of
- Returns:
- g
Graph The undirected interval graph, where vertex \(i\) corresponds to interval \(i\).
- g
See also
generate_random_intersectionRandom intersection graph
graph_tool.structure.is_chordalTest for chordal graphs
Notes
Two vertices are connected if their closed intervals \([a_i, b_i]\) and \([a_j, b_j]\) intersect, i.e. if \(a_j \le b_i\) and \(a_i \le b_j\). After sorting the intervals by their lower bounds, the neighbors of \(i\) that come after it are the contiguous range of intervals with \(a_j \le b_i\), so that the algorithm runs in time \(O(N\log N + E)\). Repeated intervals are distinct vertices.
Examples
>>> g = gt.interval_graph([(0, 2), (1, 3), (2.5, 4), (5, 6)]) >>> print(sorted(tuple(sorted(e)) for e in g.get_edges().tolist())) [(0, 1), (1, 2)]
The interval graph of random intervals is drawn as follows:
>>> a = np.random.random(30) * 10 >>> g = gt.interval_graph(np.array([a, a + np.random.random(30)]).T) >>> gt.graph_draw(g, pos=gt.sfdp_layout(g), ... output="interval_graph-random.pdf") <...>
Interval graph of 30 intervals \([a_i, a_i + \ell_i]\), with \(a_i\) uniform in \([0, 10]\) and \(\ell_i\) uniform in \([0, 1]\).#