def createRandomGraph(numVertices, numEdges): graph = Graph() #instantiate the graph all_edges = [] # for each of the nodes, it is possible to connect to each of the other nodes except for itself for i in range(numVertices): for j in range(i+1, numVertices): # start at i+1 because the vertex is not connected to itself all_edges.append( (i, j) ) random.shuffle(all_edges) # shuffle the array of edges edges = all_edges[:numEdges] if numEdges > len(all_edges): print("warning: Too many edges") for edge in edges: print(edge) # print all of the connections for i in range(numVertices): graph.add_vertex(i) for edge in edges: print(edge) graph.add_edge(edge[0], edge[1]) print(len(edges)) bg = BokehGraph(graph) bg.display()
def createDefaultGraph(): graph = Graph() # instantiate the graph using the Graph class graph.add_vertex('0') graph.add_vertex('1') graph.add_vertex('2') graph.add_vertex('3') graph.add_vertex('4') graph.add_edge('0', '1') graph.add_edge('0', '3') graph.add_edge('1', '2') graph.add_edge('1', '4') bg = BokehGraph(graph) bg.display()