Esempio n. 1
0
def main():
    v1 = Vertex('1')
    v1.pos = (1, 0)
    v2 = Vertex('2')
    v2.pos = (0, 1)
    rw = TspRW()
    A = BNB([v1, v2])

    print('Testing read_file in TspRW class..')
    rw.read_file('tsp-test.tsp')
    test(rw.header == [
        'NAME: tsp-test.tsp\n',
        'COMMENT: agarwali and ramax. 6 vertices. Note that vertex 1 is at (1, 5); vertex 2 is at (3, 7), etc.\n',
        'TYPE: TSP\n', 'DIMENSION: 6\n', 'EDGE_WEIGHT_TYPE: EUC_2D\n',
        'NODE_COORD_SECTION\n'
    ])
    test(rw.coordinates == [v1, v2])

    print('Testing explore in BNB class.. ')
    A.explore()
    test(A.tour == [v1, v2])

    print('Testing chop in BNB class.. ')
    test(A.chop() == None)

    print('Testing distance in BNB class..')
    test(A.distance(v1, v2) == sqrt(2))

    print('Testing compute_bound in BNB class..')
    test(A.compute_bound(v2) == float(
        'inf'))  # resets self.best_tour to an empty graph containing vertices
Esempio n. 2
0
def main():
    
    read_write = TspRW()    # create a read_write object
    read_write.read_file(raw_input('Enter file to read from: '))    # reads all the coordinates of citties from an ASCII file

    # solver is an BNB object
    solver = BNB(read_write.coordinates)
    solver.explore()    # explores all the vertex using BNB algorithm

    # write the tour in .tour ASCII file
    read_write.coordinates = solver.tour
    read_write.write_file()
    
    # The following two lines allows to switch the layout of the graph displayed
    layout = CartesianLayout(solver.tourGraph)
    # layout = RandomLayout(solver.tourGraph)
    # layout = CircleLayout(solver.tourGraph)
    # draw the graph
    gw = GraphWorld()
    gw.show_graph(solver.tourGraph, layout)
    gw.mainloop()
Esempio n. 3
0
def main():
    v1 = Vertex("1")
    v1.pos = (1, 0)
    v2 = Vertex("2")
    v2.pos = (0, 1)
    rw = TspRW()
    A = BNB([v1, v2])

    print("Testing read_file in TspRW class..")
    rw.read_file("tsp-test.tsp")
    test(
        rw.header
        == [
            "NAME: tsp-test.tsp\n",
            "COMMENT: agarwali and ramax. 6 vertices. Note that vertex 1 is at (1, 5); vertex 2 is at (3, 7), etc.\n",
            "TYPE: TSP\n",
            "DIMENSION: 6\n",
            "EDGE_WEIGHT_TYPE: EUC_2D\n",
            "NODE_COORD_SECTION\n",
        ]
    )
    test(rw.coordinates == [v1, v2])

    print("Testing explore in BNB class.. ")
    A.explore()
    test(A.tour == [v1, v2])

    print("Testing chop in BNB class.. ")
    test(A.chop() == None)

    print("Testing distance in BNB class..")
    test(A.distance(v1, v2) == sqrt(2))

    print("Testing compute_bound in BNB class..")
    test(A.compute_bound(v2) == float("inf"))  # resets self.best_tour to an empty graph containing vertices
Esempio n. 4
0
def main():

    read_write = TspRW()  # create a read_write object
    read_write.read_file(
        raw_input('Enter file to read from: '
                  ))  # reads all the coordinates of citties from an ASCII file

    # solver is an BNB object
    solver = BNB(read_write.coordinates)
    solver.explore()  # explores all the vertex using BNB algorithm

    # write the tour in .tour ASCII file
    read_write.coordinates = solver.tour
    read_write.write_file()

    # The following two lines allows to switch the layout of the graph displayed
    layout = CartesianLayout(solver.tourGraph)
    # layout = RandomLayout(solver.tourGraph)
    # layout = CircleLayout(solver.tourGraph)
    # draw the graph
    gw = GraphWorld()
    gw.show_graph(solver.tourGraph, layout)
    gw.mainloop()