Exemplo n.º 1
0
    def testConnectedComponents(self):
        G = DiGraph(undirected=True, DEBUG=False)
        G.populateFromFile('samples/connected-components-infoarena.txt')

        assert G.connectedComponents() == [[1, 2, 4], [3, 5], [6]]
Exemplo n.º 2
0
        G.removeVertex(x)
    elif command == '8':
        source = int(input("source: "))
        target = int(input("target: "))
        weight = int(input("weight: "))
        G.addEdge(source, target, weight)
    elif command == '9':
        source = int(input("source: "))
        target = int(input("target: "))
        G.removeEdge(source, target)
    elif command == '10':
        source = int(input("source: "))
        target = int(input("target: "))
        print(G.Dijkstra(source)[target])
    elif command == '11':
        components = G.connectedComponents()
        for comp in components:
            print(comp)
        print("There are %i connected components." % len(components))
    elif command == '12':
        components = G.scc()
        for comp in components:
            print(comp)
        print("There are %i strongly connected components." % len(components))
    elif command == '0':
        exit(0)
    else:
        print("bad command.")

    command = input("> ")
    showMenu()