def test_wiki(self):
        visual = VISUAL
#        visual = True
        """run the aglo like in the wikipedia example"""
        myFlaeche = main.Flaeche(
            xdim=300, ydim=300, scale=10, output='result_mediawiki_example')
        myD = Dijkstra(myFlaeche, (17, 3), (3, 17))

        blocked_nodes = [(xx, 7) for xx in range(4, 16)]
        blocked_nodes[0:0] = [(xx, 8) for xx in range(4, 16)]
        blocked_nodes[0:0] = [(xx, 9) for xx in range(4, 16)]
        blocked_nodes[0:0] = [(xx, 10) for xx in range(13, 16)]
        blocked_nodes[0:0] = [(xx, 11) for xx in range(13, 16)]
        blocked_nodes[0:0] = [(xx, 12) for xx in range(13, 16)]
        blocked_nodes[0:0] = [(xx, 13) for xx in range(13, 16)]
        blocked_nodes[0:0] = [(xx, 14) for xx in range(13, 16)]

        myFlaeche.load_node_data(blocked_nodes)
        myD = Dijkstra(myFlaeche, (3, 19), (18, 3))
        myD.run(visual=visual)
        myD.rebuild_path()
        self.assertEqual(DNList(myD.path, 'tuples').get_tuples(),
                         [(3, 19), (4, 18), (5, 17), (6, 16), (7, 15), (8, 15),
                          (9, 15), (10, 15), (11, 15), (12,
                                                        15), (13, 15), (14, 15),
                          (15, 15), (16, 14), (16, 13), (16,
                                                         12), (16, 11), (16, 10),
                          (16, 9), (16, 8), (16, 7), (17, 6), (17, 5), (17, 4), (18, 3)])

        if visual:
            myD.draw_path(final=True)
            main.make_movie(myFlaeche.output)
Beispiel #2
0
    def test_wiki(self):
        visual = VISUAL
        #        visual = True
        """run the aglo like in the wikipedia example"""
        myFlaeche = main.Flaeche(xdim=300,
                                 ydim=300,
                                 scale=10,
                                 output='result_mediawiki_example')
        myD = Dijkstra(myFlaeche, (17, 3), (3, 17))

        blocked_nodes = [(xx, 7) for xx in range(4, 16)]
        blocked_nodes[0:0] = [(xx, 8) for xx in range(4, 16)]
        blocked_nodes[0:0] = [(xx, 9) for xx in range(4, 16)]
        blocked_nodes[0:0] = [(xx, 10) for xx in range(13, 16)]
        blocked_nodes[0:0] = [(xx, 11) for xx in range(13, 16)]
        blocked_nodes[0:0] = [(xx, 12) for xx in range(13, 16)]
        blocked_nodes[0:0] = [(xx, 13) for xx in range(13, 16)]
        blocked_nodes[0:0] = [(xx, 14) for xx in range(13, 16)]

        myFlaeche.load_node_data(blocked_nodes)
        myD = Dijkstra(myFlaeche, (3, 19), (18, 3))
        myD.run(visual=visual)
        myD.rebuild_path()
        self.assertEqual(
            DNList(myD.path, 'tuples').get_tuples(),
            [(3, 19), (4, 18), (5, 17), (6, 16), (7, 15), (8, 15), (9, 15),
             (10, 15), (11, 15), (12, 15), (13, 15), (14, 15), (15, 15),
             (16, 14), (16, 13), (16, 12), (16, 11), (16, 10), (16, 9),
             (16, 8), (16, 7), (17, 6), (17, 5), (17, 4), (18, 3)])

        if visual:
            myD.draw_path(final=True)
            main.make_movie(myFlaeche.output)
    def test_dijsktra_run_and_rebuild(self):
        """run the algorithm on a simple example"""
        visual = VISUAL
        visual = True
        myFlaeche = main.Flaeche(
            xdim=300, ydim=300, scale=10, output='result_hindrance_punctual')
        myD = Dijkstra(myFlaeche, (0, 0), (10, 10))
        myD.run()
        myD.rebuild_path()
        path = DNList(myD.path, 'tuples').get_tuples()
        self.assertEqual(path, [(0, 0), (1, 1), (2, 2), (3, 3),
                                (4, 4), (5, 5), (6, 6), (7, 7),
                                (8, 8), (9, 9), (10, 10)])
        if visual:
            myD.draw_path()
        del(myD)

        myD = Dijkstra(myFlaeche, (0, 0), (10, 10))
        self.assertRaisesRegexp(
            StandardError, "algorithm must be run first successfully", myD.rebuild_path)

        del(myD)
        blocked_nodes = [(xx, 15) for xx in range(5, 25)]
        myFlaeche.load_node_data(blocked_nodes)
        myD = Dijkstra(myFlaeche, (3, 11), (16, 19))
        myD.run()
        myD.rebuild_path()
        self.assertEqual(DNList(myD.path, 'tuples').get_tuples(),
                         [(3, 11), (4, 12), (4, 13), (4, 14), (4, 15),
                          (5, 16), (6, 16), (7, 16), (8, 16), (9, 16),
                          (10, 16), (11, 17), (12, 17), (13, 18),
                          (14, 18), (15, 18), (16, 19)])

        if visual:
            myD.draw_path()
    def test_dijsktra_run_and_rebuild(self):
        """run the algorithm on a simple example"""
        visual = VISUAL
        visual = True
        myFlaeche = main.Flaeche(
            xdim=300, ydim=300, scale=10, output='result_hindrance_punctual')
        myD = Dijkstra(myFlaeche, (0, 0), (10, 10))
        myD.run()
        myD.rebuild_path()
        path = DNList(myD.path, 'tuples').get_tuples()
        self.assertEqual(path, [(0, 0), (1, 1), (2, 2), (3, 3),
                                (4, 4), (5, 5), (6, 6), (7, 7),
                                (8, 8), (9, 9), (10, 10)])
        if visual:
            myD.draw_path()
        del(myD)

        myD = Dijkstra(myFlaeche, (0, 0), (10, 10))
        self.assertRaisesRegexp(
            StandardError, "algorithm must be run first successfully", myD.rebuild_path)

        del(myD)
        blocked_nodes = [(xx, 15) for xx in range(5, 25)]
        myFlaeche.load_node_data(blocked_nodes)
        myD = Dijkstra(myFlaeche, (3, 11), (16, 19))
        myD.run()
        myD.rebuild_path()
        self.assertEqual(DNList(myD.path, 'tuples').get_tuples(),
                         [(3, 11), (4, 12), (4, 13), (4, 14), (4, 15),
                          (5, 16), (6, 16), (7, 16), (8, 16), (9, 16),
                          (10, 16), (11, 17), (12, 17), (13, 18),
                          (14, 18), (15, 18), (16, 19)])

        if visual:
            myD.draw_path()