Exemplo n.º 1
0
def createRandomCompleteWeightedGraph(n: int) -> WeightedGraph:
    graph = WeightedGraph()
    for i in range(n):
        graph.addNode(i)
    nodes = graph.getAllNodes()
    for node in nodes:
        for _node in nodes:
            if node is not _node:
                graph.addWeightedEdge(node, _node, randint(0, 2000))
    return graph
Exemplo n.º 2
0
    def createRandomCompleteWeightedGraph(n):
        graph = WeightedGraph()
        for i in range(n):
            graph.addNode(i)
        weightUpperbound = n**2
        for node in graph.getAllNodes():
            for i in range(n):
                if node != i:
                    graph.addWeightedEdge(node, i, random.randint(1, weightUpperbound))

        return graph
Exemplo n.º 3
0
def runDijkstras(graph: WeightedGraph, start: int) -> Dict:
    print("--- Dijkstras From Node", start, "---")
    nodes = graph.getAllNodes()
    list_of_nodes = list(nodes)
    list_of_nodes.sort(key=lambda x: x.nodeVal)
    return dijkstras(list_of_nodes[start])