def tests():
        graph1AL = DigraphAL(3)
        graph1AL.insert(0, 1, 5)
        graph1AL.insert(1, 2, 10)
        graph1AL.insert(2, 0, 40)

        graph1AM = DigraphAM(3)
        graph1AM.insert(0, 1, 5)
        graph1AM.insert(1, 2, 10)
        graph1AM.insert(2, 0, 40)

        graph2AL = DigraphAL(3)
        graph2AL.insert(0, 1, 3)
        graph2AL.insert(1, 2, 50)

        graph2AM = DigraphAM(3)
        graph2AM.insert(0, 1, 3)
        graph2AM.insert(1, 2, 50)

        if GraphAlgorithms.dijkstra(graph1AL, 0) == GraphAlgorithms.dijkstra(graph1AM, 0):
            print("First test passed!")
        else:
            print("First test failed!")

        if GraphAlgorithms.dijkstra(graph2AL, 0) == GraphAlgorithms.dijkstra(graph2AM, 0):
            print("Second test passed!")
        else:
            print("Second test failed!")
Beispiel #2
0
    def readFile():
        f1 = open('medellin.txt','r') #Format -> ID  CoordX  CoordY  Name
        IDs = []
        n = [i for i in range(310153)]
        nodes = [] #Info
        for line in f1:
            lineL1 = line.split(' ')
            nodes.append(City.nodeObj(lineL1[0],float(lineL1[1]),float(lineL1[2]),lineL1[3]))
            IDs.append(float(lineL1[0]))
        IDs_Index = dict(zip(IDs,n))

        G = DigraphAL(310153) #Initialize the graph
        f2 = open('connection.rtf','r') #Format -> ID ID distancia nombre
        for line in f2:
            lineL2 = line.split(' ')
            G.insert(IDs_Index[float(lineL2[0])], IDs_Index[float(lineL2[1])], float(lineL2[2]), Name=lineL2[3])