import igraph as ig import random import sys try: N = int(sys.argv[1]) except: N = 1000 random.seed(0) g = ig.Graph.Growing_Random(N, 5) components = g.connected_components(mode='weak') print(len(components)) with open(f"dataset/gen_{N}.txt", "w") as f: both_edges = [] for edge in g.es: both_edges.append((edge.source, edge.target)) both_edges.append((edge.target, edge.source)) num_edges = len(both_edges) f.write(f"{N} {num_edges}\n") for v1, v2 in sorted(both_edges): f.write(f"{v1} {v2}\n")