| 3335 | def RandomInterval(self,n): |
| 3336 | """ |
| 3337 | Returns a random interval graph. |
| 3338 | |
| 3339 | An interval graph is built from a list `(a_i,b_i)_{1\leq i \leq n}` |
| 3340 | of intervals : to each interval of the list is associated one |
| 3341 | vertex, two vertices being adjacent if the two corresponding |
| 3342 | intervals intersect. |
| 3343 | |
| 3344 | A random interval graph of order `n` is generated by picking |
| 3345 | random values for the `(a_i,b_j)`, each of the two coordinates |
| 3346 | being generated from the uniform distribution on the interval |
| 3347 | `[0,1]`. |
| 3348 | |
| 3349 | This definitions follows [boucheron2001]_. |
| 3350 | |
| 3351 | INPUT: |
| 3352 | |
| 3353 | - ``n`` (integer) -- the number of vertices in the random |
| 3354 | graph. |
| 3355 | |
| 3356 | EXAMPLE: |
| 3357 | |
| 3358 | As for any interval graph, the chromatic number is equal to |
| 3359 | the clique number :: |
| 3360 | |
| 3361 | sage: g = graphs.RandomInterval(15) |
| 3362 | sage: g.clique_number() == g.chromatic_number() |
| 3363 | True |
| 3364 | |
| 3365 | REFERENCE: |
| 3366 | |
| 3367 | - [boucheron2001] Boucheron, S. and FERNANDEZ de la VEGA, W., |
| 3368 | On the Independence Number of Random Interval Graphs, |
| 3369 | Combinatorics, Probability and Computing v10, issue 05, |
| 3370 | Pages 385--396, |
| 3371 | Cambridge Univ Press, 2001 |
| 3372 | """ |
| 3373 | |
| 3374 | from sage.misc.prandom import random |
| 3375 | |
| 3376 | s = lambda x,y : (x,y) if x<=y else (y,x) |
| 3377 | intervals = [s(random(), random()) for i in range(n)] |
| 3378 | intervals.sort(key=lambda x:x[0]) |
| 3379 | edges = [] |
| 3380 | while intervals: |
| 3381 | x = intervals.pop() |
| 3382 | for y in intervals: |
| 3383 | if y[0] <= x[1]: |
| 3384 | edges.append((x,y)) |
| 3385 | else: |
| 3386 | break |
| 3387 | g=graph.Graph(vertices=intervals) |
| 3388 | g.add_edges(edges) |
| 3389 | return g |
| 3390 | |