コード例 #1
0
ファイル: test.py プロジェクト: harababurel/homework
    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]]
コード例 #2
0
ファイル: main.py プロジェクト: harababurel/homework
#!/usr/bin/python3
import sys
from models.digraph import DiGraph
from tests.test import Test
import pprint


sys.setrecursionlimit(2*10**9)
DEBUG = "-d" in sys.argv or "--debug" in sys.argv

#Test().testConnectedComponents()

G = DiGraph(DEBUG=DEBUG, undirected=False)
G.populateFromFile("samples/topsort-infoarena.txt")
print(G.topSort())
#G.populateFromFile("samples/graph1m.txt")

def showMenu():
    print()
    print("1 - get number of vertices")
    print("2 - check if edge exists")
    print("3 - degrees of vertex")
    print("4 - show outbound edges of a vertex")
    print("5 - show inbound edges of a vertex")
    print("6 - add vertex")
    print("7 - remove vertex")
    print("8 - add edge")
    print("9 - remove edge")
    print("10 - get shortest path (Dijkstra)")
    print("11 - get connected components (if undirected)")
    print("12 - get strongly connected components (if directed)")