(n, shift_list, repeats, create_using=None)
| 98 | |
| 99 | @patch_docstring(nxa.LCF_graph) |
| 100 | def LCF_graph(n, shift_list, repeats, create_using=None): |
| 101 | if n <= 0: |
| 102 | return empty_graph(0, create_using) |
| 103 | |
| 104 | # start with the n-cycle |
| 105 | G = cycle_graph(n, create_using) |
| 106 | if G.is_directed(): |
| 107 | raise NetworkXError("Directed Graph not supported") |
| 108 | G.name = "LCF_graph" |
| 109 | nodes = sorted(list(G)) |
| 110 | |
| 111 | n_extra_edges = repeats * len(shift_list) |
| 112 | # edges are added n_extra_edges times |
| 113 | # (not all of these need be new) |
| 114 | if n_extra_edges < 1: |
| 115 | return G |
| 116 | |
| 117 | for i in range(n_extra_edges): |
| 118 | shift = shift_list[i % len(shift_list)] # cycle through shift_list |
| 119 | v1 = nodes[i % n] # cycle repeatedly through nodes |
| 120 | v2 = nodes[(i + shift) % n] |
| 121 | G.add_edge(v1, v2) |
| 122 | return G |
| 123 | |
| 124 | |
| 125 | # ------------------------------------------------------------------------------- |
no test coverage detected