예제 #1
0
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
예제 #2
0
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
예제 #3
0
파일: Main.py 프로젝트: brijsavla/Project2
 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
예제 #4
0
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
예제 #5
0
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
예제 #6
0
파일: Main.py 프로젝트: brijsavla/Project2
 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