def createLinkedList(n): g = WeightedGraph() for i in range(1, n+1): g.addNode(createLabel(i)) nodes = g.getAllNodes() for i in range(len(nodes)-1): nodes[i].neighbors[nodes[i+1]] = 1 return g
def createLinkedList(n): graph = WeightedGraph() for newNode in range(0, n) graph.addNode(newNode) nodelist = graph.getAllNodes() nodelistlength = len(nodelist) for num in range(nodelistlength-1): graph.addWeightedEdge(nodelist[num], nodelist[num+1], 1) return graph
def createLinkedList(n): """Makes a weighted graph with n nodes, each having a single edge to the next node of uniform weight.""" graph = WeightedGraph() for i in range(n): graph.addNode(i) if i == 0: continue graph.addWeightedEdge(i-1, i, 1) return graph
def createLinkedList(n): linkedgraph = WeightedGraph() i = 0 while (i < n): linkedgraph.addNode(i) i += 1 j = 1 while (j < (n)): linkedgraph.addWeightedEdge(linkedgraph.nodesList[j - 1], linkedgraph.nodesList[j], 1) j += 1 return linkedgraph
def createRandomCompleteWeightedGraph(n): g = WeightedGraph() for i in range(1, n + 1): g.addNode(createLabel(i)) nodes = g.getAllNodes() for i in nodes: x = nodes.index(i) suggested = nodes[:x] + nodes[x + 1:] for j in suggested: randomWeight = randint(1, 15) g.addDirectedEdge(i, j, randomWeight) return g
def createRandomCompleteWeightedGraph(n): g = WeightedGraph() for i in range(1,n+1): g.addNode(createLabel(i)) nodes = g.getAllNodes() for i in nodes: x = nodes.index(i) # Make a list including all values but the current suggestedList = nodes[:x]+nodes[x+1:] for j in suggestedList: randomWeight = randint(1, 15) g.addDirectedEdge(i, j, randomWeight) return g
def createRandomCompleteWeightedGraph(n): """Makes a complete weighted graph where every node has an edge to every other node with randomly assigned weights.""" graph = WeightedGraph() for i in range(n): graph.addNode(i) for i in range(n): for j in range(n): if i == j: continue graph.addWeightedEdge(i, j, random.choice(range(1, n))) return graph
def createRandomCompleteWeightedGraph(n: int) -> WeightedGraph: graph = WeightedGraph() for i in range(0, n): graph.addNode(i) for node in graph.getAllNodes(): for neighbor in graph.getAllNodes(): if node is not neighbor: weight = random.randint(0, n) graph.addWeightedEdge(node, neighbor, weight) return graph
def createRandomCompleteWeightedGraph(n): graph = WeightedGraph() lst = [] for num in range(n): randomNum = random.randint(0, n); if randomNum not in lst: lst.append(randomNum) graph.addNode(num) nodelist = graph.getAllNodes() for node in nodelist: for node2 in range(n): if node != node2: randomWeight = random.randint(1, (n*n)) graph.addWeightedEdge(node, node2, randomWeight) return graph
def createRandomCompleteWeightedGraph(n): randgraph = WeightedGraph() i = 0 while (i < n): randgraph.addNode(i) i += 1 i = 0 while (i < n): j = 0 while (j < n): if i != j: x = randgraph.nodesList[i] y = randgraph.nodesList[j] z = random.randint(1, max(10, n / 2)) randgraph.addWeightedEdge(x, y, z) j += 1 i += 1 return randgraph
def createLinkedList(n: int) -> WeightedGraph: graph = WeightedGraph() prevNode = None for i in range(0, n): newNode = graph.addNode(i) if prevNode is not None: graph.addWeightedEdge(prevNode, newNode, 1) prevNode = newNode return graph