Find a threshold subgraph that is close to largest in G. Returns the labeled creation sequence of that threshold graph.
(G)
| 406 | |
| 407 | @nx._dispatchable |
| 408 | def find_creation_sequence(G): |
| 409 | """ |
| 410 | Find a threshold subgraph that is close to largest in G. |
| 411 | Returns the labeled creation sequence of that threshold graph. |
| 412 | """ |
| 413 | cs = [] |
| 414 | # get a local pointer to the working part of the graph |
| 415 | H = G |
| 416 | while H.order() > 0: |
| 417 | # get new degree sequence on subgraph |
| 418 | dsdict = dict(H.degree()) |
| 419 | ds = [(d, v) for v, d in dsdict.items()] |
| 420 | ds.sort() |
| 421 | # Update threshold graph nodes |
| 422 | if ds[-1][0] == 0: # all are isolated |
| 423 | cs.extend(zip(dsdict, ["i"] * (len(ds) - 1) + ["d"])) |
| 424 | break # Done! |
| 425 | # pull off isolated nodes |
| 426 | while ds[0][0] == 0: |
| 427 | (d, iso) = ds.pop(0) |
| 428 | cs.append((iso, "i")) |
| 429 | # find new biggest node |
| 430 | (d, bigv) = ds.pop() |
| 431 | # add edges of star to t_g |
| 432 | cs.append((bigv, "d")) |
| 433 | # form subgraph of neighbors of big node |
| 434 | H = H.subgraph(H.neighbors(bigv)) |
| 435 | cs.reverse() |
| 436 | return cs |
| 437 | |
| 438 | |
| 439 | # Properties of Threshold Graphs |
no test coverage detected
searching dependent graphs…