def disjointUnion(g: graph, h: graph): f = graph(len(g.V()) + len(h.V())) combinedList = g.V() + h.V() for i in range(len(combinedList)): v = combinedList[i] for e in v.inclist(): if e.tail() == v: f.addedge(f[i], f[combinedList.index(e.head())]) return f
def disjointUnionMulti(graphList, holdColor=False): f = graph(sum([len(g.V()) for g in graphList])) inclist = dict() combinedList = [v for g in graphList for v in g] for g in graphList: inclist.update(generateNeighbourList(g, inclists=True)) for i in range(len(combinedList)): v = combinedList[i] if holdColor: f.V()[i].colornum = v.colornum for e in inclist[v]: if e.tail() == v: f.addedge(f[i], f[combinedList.index(e.head())]) return f
def createGraph(n, edges): g = graph(n) for edge in edges: (head, tail) = edge g.addedge(g[head], g[tail]) return g