def test_get_distance_between_endlessly_long(self):
        """building the vessel takes ages, as calculating
        the shadow seems to be pretty expencive,
        small scale huge ship

        for sure has an evil impact on the pathfinding"""

        scale = 0.25
        start = (10, 10, 0)
        end = (20, 10, 0)
        myFlaeche = main.Flaeche(xdim=30, ydim=30, scale=scale)

        vessel = main.Vessel(myFlaeche, [(0, 0), (40, 40), (40, 200),
                                         (-40, 200), (-40, 40), (0, 0)])
    def test_ada_no_hindrances_circle_horisontal_from_down_to_up_outside_canvas(
            self):
        """

        The vessel has a radius of 40 and moves over
        an open space from __down_to_up__ without any hindrances.
        The radius is pretty much the vertical distance
        between the start and destination so the vessel moves
        allong its turning circle and then moves straight
        forward (horisontally) to destination. 

        In this configuration the vessel  __does_leave_the_canvas__.
        Hence it shall fail somewhen in the future.

        This test used to be a bug.
        """

        visual = VISUAL
        visual = True
        image_name = self.__dict__['_testMethodName']
        myFlaeche = main.Flaeche(xdim=500,
                                 ydim=500,
                                 scale=10,
                                 output=image_name)
        vessel = main.Vessel(myFlaeche, [(0, 0), (-10, 10), (-30, 10),
                                         (-30, -10), (-10, -10), (0, 0)])
        vessel.r = 40
        vessel.speed = 10  # m/s

        # start = (5,  11, 8)  # cell coordinates
        #        end   = (16, 19, 0)
        start = (5, 21, 8)  # cell coordinates
        end = (16, 13, 0)

        myD = main.AdAStar(vessel=vessel, start_node=start, end_node=end)
        myD.run()
        myD.rebuild_path()
        #        myD.patch_path()

        if False:  # print results
            sys.exit(sorted(ANList(myD.path, 'tuples').get_tuples()))

        expected_result = [(1, 16, 13), (2, 20, 10), (5, 21, 8), (6, 13, 0),
                           (7, 13, 0), (10, 13, 0), (13, 13, 0), (16, 13, 0)]
        result = sorted(ANList(myD.path, 'tuples').get_tuples())
        self.assertEqual(expected_result, result)

        if visual:
            myD.draw_path(vessel=vessel)
        del (myD)
    def test_ada_run_and_rebuild_hindrance_one_spot_shadowed_improve(self):
        """algo simply ignores the blocked node!!!"""
        visual = VISUAL
        visual = True

        image_name = self.__dict__['_testMethodName']

        myFlaeche = main.Flaeche(xdim=500,
                                 ydim=340,
                                 scale=10,
                                 output=image_name)
        vessel = main.Vessel(myFlaeche, [(0, 0), (-10, 10), (-30, 10),
                                         (-30, -10), (-10, -10), (0, 0)])

        vessel.r = 40
        vessel.speed = 10

        blocked_nodes = [
            (20, 18),
            (21, 18),
            (22, 18),
            (23, 18),  # (24, 18),
            (20, 19),
            (21, 19),
            (22, 19),
            (23, 19),
            (24, 19),
            (20, 20),
            (21, 20),
            (22, 20),
            (23, 20),  # (24, 20),
            #                         (20, 21), (21, 21), (22, 21), (23, 21), (24, 21),
        ]
        myFlaeche.load_node_data(blocked_nodes)

        start = (10, 17, 0)  # cell coordinates
        end = (40, 17, 0)

        myD = main.AdAStar(vessel=vessel, start_node=start, end_node=end)

        myD.run()
        myD.rebuild_path()

        path = ANList(myD.path, 'tuples').get_tuples()

        if visual:
            myD.draw_path(vessel=vessel)
        del (myD)
示例#4
0
    def test_dijsktra_step_internals_rebuild_error(self):
        myFlaeche = main.Flaeche(xdim=500,
                                 ydim=500,
                                 scale=10,
                                 output='result_ada_star')
        vessel = main.Vessel(
            myFlaeche,
            # wrong orientation of the vessel shape
            # [(0, 0), (40, 40), (40, 200), (-40, 200), (-40, 40), ( 0, 0)])
            [(0, 0), (-40, 40), (-140, 40), (-140, -40), (-40, -40), (0, 0)])
        vessel.r = 20

        myD = main.AdAStar((0, 0, 0), (10, 10, 0), vessel=vessel)
        self.assertRaisesRegexp(StandardError,
                                "algorithm must be run first successfully",
                                myD.rebuild_path)
    def test_ada_run_and_rebuild_hindrance_one_spot_ignored(self):
        """algo simply ignores the blocked node!!!"""
        visual = VISUAL
        visual = True

        image_name = self.__dict__['_testMethodName']

        myFlaeche = main.Flaeche(xdim=500,
                                 ydim=500,
                                 scale=10,
                                 output=image_name)
        #        vessel = main.Vessel(myFlaeche,
        # wrong orientation of the vessel shape
        # [(0, 0), (40, 40), (40, 200), (-40, 200), (-40, 40), ( 0, 0)])
        #                             [(0, 0), (-40, 40), (-140, 40), (-140, -40), (-40, -40), ( 0, 0)])

        vessel = main.Vessel(myFlaeche, [(0, 0), (-10, 10), (-30, 10),
                                         (-30, -10), (-10, -10), (0, 0)])

        vessel.r = 20
        vessel.speed = 10
        #       vessel.x = 300; vessel.y = 305; vessel.rotation = 0;

        #        blocked_nodes = [(20, 10)]
        blocked_nodes = [(20, 11)]
        myFlaeche.load_node_data(blocked_nodes)

        start = (10, 10, 0)  # cell coordinates
        end = (40, 10, 0)

        myD = main.AdAStar(vessel=vessel, start_node=start, end_node=end)

        myD.run()
        myD.rebuild_path()

        path = ANList(myD.path, 'tuples').get_tuples()

        #        self.assertEqual(path, [
        #            (30, 10, 0), (31, 10, 0), (32, 10, 0), (33, 10, 0),
        #            (34, 10, 0), (35, 10, 0), (36, 10, 0), (37, 10, 0),
        #            (38, 10, 0), (39, 10, 0), (40, 10, 0)
        #        ])

        if visual:
            myD.draw_path(vessel=vessel)
        del (myD)
示例#6
0
    def test_flaeche_sector_id_is_legal(self):
        """test to vertify if a sector_id is conform with what is expected """

        myFlaeche = main.Flaeche(xdim=100, ydim=100, scale=1, sectors=16)

        self.assertRaisesRegexp(AssertionError, "sector_id must be an integer",
                                myFlaeche.is_valid_sector_id, '1')

        self.assertRaisesRegexp(AssertionError, "sector_id must be greater equal zero",
                                myFlaeche.is_valid_sector_id, -1)

        self.assertRaisesRegexp(AssertionError, "sector_id is greater then the number of sectors",
                                myFlaeche.is_valid_sector_id, 16)
        self.assertRaisesRegexp(AssertionError, "sector_id is greater then the number of sectors",
                                myFlaeche.is_valid_sector_id, 17)

        self.assertTrue(myFlaeche.is_valid_sector_id(1))
        self.assertTrue(myFlaeche.is_valid_sector_id(15))
    def test_dijsktra_step_internals_find_final__bug_c(self):
        """ unclear bug

        this combo and end point combo does not work,
        algo seaches for ever and finally
        ends with an error after some 2.5 min  """
        myFlaeche = main.Flaeche(xdim=500, ydim=500, scale=10,
                                 output='result_hindrance_punctual_ada__c')
        vessel = main.Vessel(myFlaeche,
                             [(0, 0), (-10, 10), (-30, 10), (-30, -10), (-10, -10), (0, 0)])
        vessel.r = 20
        vessel.speed = 10  # m/s

        start = (5,  11, 0)  # cell coordinates
        end = (20, 11, 0)

        myD = main.AdAStar(vessel=vessel, start_node=start, end_node=end)
        myD.run()
    def test_ada_no_hindrances_circle_diagonal_down_to_up_right(self):
        """

        The vessel has a radius of __only_20__ and moves over
        an open space from __down_to_up__ __with_different_start_orientation__
        without any hindrances.
        It follows it's turning cirle and then leaves it
        to get to the destination on a diagonal path.

        This test used to be a bug.
        """

        visual = VISUAL
        visual = True
        image_name = self.__dict__['_testMethodName']
        myFlaeche = main.Flaeche(xdim=500,
                                 ydim=500,
                                 scale=10,
                                 output=image_name)
        vessel = main.Vessel(myFlaeche, [(0, 0), (-10, 10), (-30, 10),
                                         (-30, -10), (-10, -10), (0, 0)])
        vessel.r = 20
        vessel.speed = 10  # m/s

        end = (5, 11, 8)  # cell coordinates
        start = (16, 19, 8)

        myD = main.AdAStar(vessel=vessel, start_node=start, end_node=end)
        myD.run(verbose=True, visual=True)
        myD.rebuild_path()

        if False:  # print results
            sys.exit(sorted(ANList(myD.path, 'tuples').get_tuples()))

        expected_result = [(5, 11, 10), (8, 13, 9), (12, 16, 10), (14, 18, 10),
                           (16, 19, 8)]

        result = sorted(ANList(myD.path, 'tuples').get_tuples())

        self.assertEqual(expected_result, result)

        if visual:
            myD.draw_path(vessel=vessel)
        del (myD)
    def test_get_reachable_center_points_spooky(self):
        visual = VISUAL
        visual = True
        myFlaeche = main.Flaeche(xdim=500,
                                 ydim=500,
                                 scale=10,
                                 output='result_hindrance_punctual_ada_spooky')
        vessel = main.Vessel(
            myFlaeche,  # nosy:
            [(0, 0), (-10, 10), (-30, 10), (-30, -10), (-10, -10), (0, 0)])
        vessel.r = 20

        vessel.x, vessel.y = myFlaeche.get_possition_from_cell_center_id(
            (5, 11))
        vessel.rotation = myFlaeche.get_angle_from_sector(8)

        print
        # self.vessel.get_reachable_center_points(( 55.0 115.0 ) 8 )))

        result = vessel.get_reachable_center_points(
            (vessel.x, vessel.y),
            vessel.rotation,
        )
        #                                                    test_result='get_all_center_points')
        # !!                                                  test_result='get_zone_zero_center_points')
        #                                                    test_result='get_zone_one_center_points')
        #                                                    test_result='get_zone_two_center_points')
        #                                                    test_result='get_zone_three_center_points')
        #                                                     test_result='get_extention_center_points')

        for ii in result:
            if ii[0] == 45:
                print ii

        print 'counted points', len(result)

        for pp in result:
            myFlaeche.vis_add_single_point(pp[0:2], 'blue')

        myFlaeche.vis_add_colored_point((5, 11), 'red')
        myFlaeche.vis_add_colored_point((5, 12), 'grey')

        if visual:
            myFlaeche.vis_show()
示例#10
0
    def test_ada_run_and_rebuild_hindrance_at_nodes_behind_start(self):
        """start node is blocked"""
        visual = VISUAL
        visual = True

        image_name = self.__dict__['_testMethodName']

        myFlaeche = main.Flaeche(xdim=500,
                                 ydim=500,
                                 scale=10,
                                 output=image_name)

        vessel = main.Vessel(myFlaeche, [(0, 0), (-10, 10), (-30, 10),
                                         (-30, -10), (-10, -10), (0, 0)])

        vessel.r = 20
        vessel.speed = 10
        #       vessel.x = 300; vessel.y = 305; vessel.rotation = 0;

        blocked_nodes = [(10, 10), (11, 10), (12, 10), (13, 10), (14, 10)]
        myFlaeche.load_node_data(blocked_nodes)

        start = (10, 10, 0)  # cell coordinates
        end = (40, 10, 0)

        myD = main.AdAStar(vessel=vessel, start_node=start, end_node=end)

        myD.run()
        myD.rebuild_path()

        path = ANList(myD.path, 'tuples').get_tuples()

        assert (False)

        #        self.assertEqual(path, [
        #            (30, 10, 0), (31, 10, 0), (32, 10, 0), (33, 10, 0),
        #            (34, 10, 0), (35, 10, 0), (36, 10, 0), (37, 10, 0),
        #            (38, 10, 0), (39, 10, 0), (40, 10, 0)
        #        ])

        if visual:
            myD.draw_path(vessel=vessel)
        del (myD)
示例#11
0
    def test_all_nodes_in_list_are_valid(self):
        """check if all nodes in a list are valid"""

        myFlaeche = main.Flaeche(xdim=100, ydim=100, scale=10)
        # self.assertEqual((12,12,5), myFlaeche.convert_cell_id_to_tuple("12_12_5"))

        node_list = [(5, 5, 0), (5, 6, 0)]
        self.assertTrue(myFlaeche.all_nodes_in_list_are_valid(node_list))

        node_list = [(5, 5), (5, 6)]
        self.assertTrue(myFlaeche.all_nodes_in_list_are_valid(node_list))

        node_list = [(15, 5), (5, 6)]
        self.assertFalse(myFlaeche.all_nodes_in_list_are_valid(node_list))

        node_list = [(5, 5), (5, 16)]
        self.assertFalse(myFlaeche.all_nodes_in_list_are_valid(node_list))

        node_list = [(5, 5), (-5, 16)]
        self.assertFalse(myFlaeche.all_nodes_in_list_are_valid(node_list))
示例#12
0
    def test_get_cell_and_sector(self):
        """test to vertify if a node is inside a Flaeche"""

        myFlaeche = main.Flaeche(xdim=100, ydim=100, scale=1)
        self.assertEqual(myFlaeche.get_cell_and_sector((1.5, 1.5), 0)[1],  0)
        self.assertEqual(
            myFlaeche.get_cell_and_sector((1.5, 1.5), 0.0001)[1],  0)
        self.assertEqual(
            myFlaeche.get_cell_and_sector((1.5, 1.5), 2 * math.pi / 16 / 2)[1],  0)
        self.assertEqual(myFlaeche.get_cell_and_sector(
            (1.5, 1.5), 2 * math.pi / 16 / 2 + 0.001)[1], 1)
        self.assertEqual(
            myFlaeche.get_cell_and_sector((1.5, 1.5), 2 * math.pi - 0.001)[1],  0)
        self.assertEqual(
            myFlaeche.get_cell_and_sector((1.5, 1.5), math.pi - 0.001)[1],  8)

        # multi_turn
        self.assertEqual(
            myFlaeche.get_cell_and_sector((1.5, 1.5), 2 * math.pi)[1],  0)
        self.assertEqual(myFlaeche.get_cell_and_sector(
            (1.5, 1.5), 4 * math.pi / 16 / 2 + 0.001)[1], 1)
示例#13
0
    def test_all_nodes_in_list_are_valid_and_not_blocked(self):
        """check if all nodes in a list are valid"""

        myFlaeche = main.Flaeche(xdim=100, ydim=100, scale=10)
        blocked_nodes = [(5, 9)]
        myFlaeche.load_node_data(blocked_nodes)

        #        node_list = [(5, 5, 0), (5, 6, 0)]
        #        self.assertFalse(myFlaeche.all_nodes_in_list_are_valid(node_list))

        node_list = [(5, 5), (5, 6)]
        self.assertTrue(
            myFlaeche.all_nodes_in_list_are_valid_and_not_blocked(node_list))

        node_list = [(5, 5), (5, 6), (5, 12)]
        self.assertFalse(
            myFlaeche.all_nodes_in_list_are_valid_and_not_blocked(node_list))

        node_list = [(5, 5), (5, 6), (5, 9)]
        self.assertFalse(
            myFlaeche.all_nodes_in_list_are_valid_and_not_blocked(node_list))
示例#14
0
    def test_dijkstra_to_do(self):
        """test for illegal start or end possitions"""

        start = (0, 0)
        end = (20, 10)
        myFlaeche = main.Flaeche(xdim=10, ydim=10, scale=1)
        #    self.assertRaises(StandardError, Dijkstra, myFlaeche, ( 1,  1), ( 1,  1) )

        self.assertRaises(
            StandardError, Dijkstra, myFlaeche, (1,  1), (11, 11))
        self.assertRaises(
            StandardError, Dijkstra, myFlaeche, (1,  1), (11,  1))
        self.assertRaises(StandardError, Dijkstra, myFlaeche, (1,  1), (1, 11))

        self.assertRaises(
            StandardError, Dijkstra, myFlaeche, (1, 11), (11, 11))
        self.assertRaises(
            StandardError, Dijkstra, myFlaeche, (1, 11), (11,  1))
        self.assertRaises(StandardError, Dijkstra, myFlaeche, (1, 11), (1,  1))
        self.assertRaises(StandardError, Dijkstra, myFlaeche, (1, 11), (1, 11))

        self.assertRaises(
            StandardError, Dijkstra, myFlaeche, (11,  1), (11, 11))
        self.assertRaises(
            StandardError, Dijkstra, myFlaeche, (11,  1), (11,  1))
        self.assertRaises(
            StandardError, Dijkstra, myFlaeche, (11,  1), (1,  1))
        self.assertRaises(
            StandardError, Dijkstra, myFlaeche, (11,  1), (1, 11))

        self.assertRaises(
            StandardError, Dijkstra, myFlaeche, (11, 11), (11, 11))
        self.assertRaises(
            StandardError, Dijkstra, myFlaeche, (11, 11), (11,  1))
        self.assertRaises(
            StandardError, Dijkstra, myFlaeche, (11, 11), (1,  1))
        self.assertRaises(
            StandardError, Dijkstra, myFlaeche, (11, 11), (1, 11))

        self.assertRaises(StandardError, Dijkstra, myFlaeche, (11, 11), (0, 0))
    def test_dijsktra_step_internals_find_final__bug_a_s_archive_version(self):
        """ unclear bug

        the result of this test is odd.
        when looking at the graphical output,
        it seem like the vehilce starts and ends in
        the wrong positions.
        """

        myFlaeche = main.Flaeche(xdim=500, ydim=500, scale=10,
                                 output='result_hindrance_punctual_ada__a_A')
        vessel = main.Vessel(myFlaeche,
                             [(0, 0), (-10, 10), (-30, 10), (-30, -10), (-10, -10), (0, 0)])
        vessel.r = 20
        vessel.speed = 10  # m/s

        start = (5,  11, 8)  # cell coordinates
        end = (16, 19, 0)

        myD = main.AdAStar(vessel=vessel, start_node=start, end_node=end)
        myD.run()
        myD.rebuild_path()
        myD.patch_path()
示例#16
0
    def test_dikstra_get_nodes_list(self):
        """test the getter of the nodes lists"""

        start = (10, 10)
        end = (20, 10)
        myFlaeche = main.Flaeche(xdim=30, ydim=30, scale=1)
        myD = Dijkstra(myFlaeche, start, end)
        self.assertEqual(myD.get_open_nodes(), [])
        myDN_1 = StarNode(xx=3, yy=3, tt=4, dd=5, lastNode=None)
        myDN_2 = StarNode(xx=4, yy=3, tt=4, dd=5, lastNode=None)
        myDN_3 = StarNode(xx=5, yy=5, tt=4, dd=5, lastNode=None)
        myDN_4 = StarNode(xx=5, yy=6, tt=4, dd=5, lastNode=None)
        """get the nodes tuples"""
        myD.open_nodes_list[0:0] = [myDN_1, myDN_2]
        self.assertEqual(sorted(myD.get_open_nodes('tuples')),
                         sorted([(3, 3), (4, 3)]))
        """get the node them self """
        self.assertEqual(sorted(myD.get_open_nodes()), sorted([myDN_1,
                                                               myDN_2]))
        """get the node tuples of closed list """
        myD.closed_nodes_list[0:0] = [myDN_3, myDN_4]
        self.assertEqual(sorted(myD.get_closed_nodes('tuples')),
                         sorted([(5, 5), (5, 6)]))
示例#17
0
    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()
示例#18
0
    def test_dijsktra_run_and_rebuild(self):
        """run the algorithm on a simple example - straight from left to right"""
        visual = VISUAL
        visual = True

        myFlaeche = main.Flaeche(xdim=500,
                                 ydim=500,
                                 scale=10,
                                 output='result_ada_star_full_run_straight')
        vessel = main.Vessel(
            myFlaeche,
            # wrong orientation of the vessel shape
            # [(0, 0), (40, 40), (40, 200), (-40, 200), (-40, 40), ( 0, 0)])
            [(0, 0), (-40, 40), (-140, 40), (-140, -40), (-40, -40), (0, 0)])
        vessel.r = 20
        vessel.speed = 10
        #       vessel.x = 300; vessel.y = 305; vessel.rotation = 0;

        start = (30, 10, 0)  # cell coordinates
        end = (40, 10, 0)

        myD = main.AdAStar(vessel=vessel, start_node=start, end_node=end)

        myD.run()
        myD.rebuild_path()
        myD.patch_path()

        path = ANList(myD.path, 'tuples').get_tuples()
        self.assertEqual(path, [(30, 10, 0), (31, 10, 0), (32, 10, 0),
                                (33, 10, 0), (34, 10, 0), (35, 10, 0),
                                (36, 10, 0), (37, 10, 0), (38, 10, 0),
                                (39, 10, 0), (40, 10, 0)])

        if visual:
            myD.draw_path(vessel=vessel)
        del (myD)
示例#19
0
    def test_dijsktra_step_internals_find_final(self):
        """ Test for adastar's results after the first step        """
        """test that the algo stops if the end is reached - manipulated lists"""

        myFlaeche = main.Flaeche(xdim=500,
                                 ydim=500,
                                 scale=10,
                                 output='result_ada_star')
        vessel = main.Vessel(myFlaeche, [(0, 0), (40, 40), (40, 200),
                                         (-40, 200), (-40, 40), (0, 0)])
        vessel.r = 20
        vessel.speed = 10

        start = (30, 10, 0)  # cell coordinates
        end = (40, 10, 0)

        myD_fake_open = main.AdAStar(vessel=vessel,
                                     start_node=start,
                                     end_node=end)

        myD_fake_open.step()
        myD_fake_open.step()

        test_node_tuple = (40, 10, 0)

        dn_2d = myFlaeche.get_node_data(
            (test_node_tuple[0], test_node_tuple[1]))
        myDN_2 = StarNodeC(node_data=dn_2d,
                           sector_id=0,
                           reached_by_angle=0,
                           costs_till_here=1,
                           estimated_remaining_costs=1,
                           previous_node=None)

        myD_fake_open.open_nodes_list.append(myDN_2)
        self.assertTrue(myD_fake_open.step())
    def test_wiki(self):
        visual = VISUAL
        """run the aglo like in the wikipedia example"""
        myFlaeche = main.Flaeche(
            xdim=300, ydim=300, scale=10, output='result_mediawiki_example')
        myD = main.AdAStar(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 = main.AdAStar(myFlaeche, (3, 19), (18, 3))
        myD.run(visual=visual)
        myD.rebuild_path()
        self.assertEqual(myD.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)


##############
#     this test is not realy usefull now, because it catches an error for
#     both: not giving the coorrect coordinates or giving coordinates without angle
#     Maybe make the teste better later or remove in 2016 :-)

#    @unittest.skipIf(devel_run, 'done')
#    def test_adastar_to_do(self):
#        """test for illegal start or end possitions"""
#
#        start = (0, 0, 0)
#        end = (20, 10, 0)
#        myFlaeche = main.Flaeche(xdim=10,ydim=10,scale=1)
        #    self.assertRaises(StandardError, main.AdAStar, myFlaeche, ( 1,  1), ( 1,  1) )


#        self.assertRaises(StandardError, main.AdAStar, myFlaeche, ( 1,  1), (11, 11) )
#        self.assertRaises(StandardError, main.AdAStar, myFlaeche, ( 1,  1), (11,  1) )
#        self.assertRaises(StandardError, main.AdAStar, myFlaeche, ( 1,  1), ( 1, 11) )

#        self.assertRaises(StandardError, main.AdAStar, myFlaeche, ( 1, 11), (11, 11) )
#        self.assertRaises(StandardError, main.AdAStar, myFlaeche, ( 1, 11), (11,  1) )
#        self.assertRaises(StandardError, main.AdAStar, myFlaeche, ( 1, 11), ( 1,  1) )
#        self.assertRaises(StandardError, main.AdAStar, myFlaeche, ( 1, 11), ( 1, 11) )

#        self.assertRaises(StandardError, main.AdAStar, myFlaeche, (11,  1), (11, 11) )
#        self.assertRaises(StandardError, main.AdAStar, myFlaeche, (11,  1), (11,  1) )
#        self.assertRaises(StandardError, main.AdAStar, myFlaeche, (11,  1), ( 1,  1) )
#        self.assertRaises(StandardError, main.AdAStar, myFlaeche, (11,  1), ( 1, 11) )

#        self.assertRaises(StandardError, main.AdAStar, myFlaeche, (11, 11), (11, 11) )
        # self.assertRaises(StandardError, main.AdAStar, myFlaeche, (11, 11), (11,  1) )
        1
    def test_dijsktra_step_internals_find_final__b(self):
        visual = VISUAL
        visual = True
        myFlaeche = main.Flaeche(xdim=500, ydim=500, scale=10,
                                 output='result_hindrance_punctual_ada')
        vessel = main.Vessel(myFlaeche,
                             #                             [(10, 0), (0, 10), (-20, 10), (-20, -10), (0, -10), ( 10, 0)])
                             # nosy:
                             [(0, 0), (-10, 10), (-30, 10), (-30, -10), (-10, -10), (0, 0)])
# mistaken one:                [(0, 0), (10, 10), (10, 30), (-10, 30),
# (-10, 10), ( 0, 0)])
        vessel.r = 20

       ## blocked_nodes = [(xx, 15) for xx in range(10, 28)]
       # blocked_nodes = [(xx, 15) for xx in range(7, 28)]
       # myFlaeche.load_node_data(blocked_nodes)

        # start = (3,  11, 8)  # cell coordinates
        #end   = (16, 19, 0)

        start = (5,  20, 8)  # cell coordinates
        end = (22, 19, 0)

        # unclear bug
        # this combo does not work,
        # ending with an error after some 2.5 min
        start = (5,  11, 8)  # cell coordinates
        end = (16, 19, 0)

        start = (5,  11, 8)  # cell coordinates
        end = (20, 11, 0)

        myD = main.AdAStar(vessel=vessel, start_node=start, end_node=end)

# myD.run(verbose=True, visual=visual) #        myD.run(visual=visual)


####### surgery cut ####
        if False:

            myD.step()
            myD.step()
            print myD.get_open_nodes('tuples')

            print len(myD.get_open_nodes('tuples'))

            assert False
            #        self.assertEqual(myD_step_zero.get_open_nodes('tuples'), [( 30, 10, 0) ])
            #        self.assertEqual(myD_step_zero.get_closed_nodes('tuples'), [])


####### surgery glue ####

        myD.run()
        if False:
            myD.rebuild_path()

            for bla in myD.path:
                print bla.id, bla.reached_by_angle * 180 / math.pi

                expected_result = [(3, 11, 0), (5, 12, 2), (8, 15, 6), (9, 15, 1), (10, 16, 1),
                                   (11, 17, 1), (12, 18, 1), (13, 19, 1), (15, 20, 3), (22, 19, 0)]
#        self.assertEqual(ANList(myD.path, 'tuples').get_tuples(), expected_result)
#        main.make_movie(myFlaeche.output)
#        if visual:
                myD.draw_path(vessel=vessel)
示例#22
0
    def test_dijsktra_step_internals_find_final__bug_a_s(self):
        """ unclear bug

        the result of this test is odd.
        when looking at the graphical output,
        it seem like the vehilce starts and ends in
        the wrong positions.
        """

        visual = VISUAL
        visual = True
        myFlaeche = main.Flaeche(xdim=500, ydim=500, scale=10,
                                 output='result_ada_non_straight')
        vessel = main.Vessel(myFlaeche,
                             [(0, 0), (-10, 10), (-30, 10), (-30, -10), (-10, -10), (0, 0)])
        vessel.r = 20
        vessel.speed = 10  # m/s

        start = (5,  11, 8)  # cell coordinates
        end = (16, 19, 0)

        myD = main.AdAStar(vessel=vessel, start_node=start, end_node=end)

        if False:

            myD.step()
            open_list = ANList(myD.open_nodes_list, 'tuples').get_tuples()
            print open_list

            myD.step()
            open_list = ANList(myD.open_nodes_list, 'tuples').get_tuples()
            print open_list

            print
            print

            myD.step()
            open_list = ANList(myD.open_nodes_list, 'tuples').get_tuples()
            print open_list

            print
            print

            myD.step()
            open_list = ANList(myD.open_nodes_list, 'tuples').get_tuples()
            print open_list

            print
            print

            myD.step()
            open_list = ANList(myD.open_nodes_list, 'tuples').get_tuples()
            print open_list

        myD.run(verbose=True, visual=True)
        myD.rebuild_path()
#        myD.patch_path()

        for ii in myD.path:
            print ii.id

        if visual:
            myD.draw_path(vessel=vessel)
#            myD.flaeche.vis_show()

        del(myD)
示例#23
0
    def test_get_distance_between(self):
        """test the correct disstance between two points"""

        myId = 12
        myFlaeche = main.Flaeche(xdim=30, ydim=30, scale=1)
        myD = Dijkstra(myFlaeche, (10, 10), (20, 10))
        # points are equal
        self.assertEqual(myD.get_distance_between_points((2, 2), (2, 2)), 0)
        # point a outside
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (-3, -3), (10, 10))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (-3, 8), (10, 10))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (8, -3), (10, 10))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (8, 40), (10, 10))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (40, 8), (10, 10))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (40, 40), (10, 10))

        # point b outside
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (10, 10), (-3, -3))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (10, 10), (-3, 8))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (10, 10), (8, -3))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (10, 10), (8, 40))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (10, 10), (40, 8))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (10, 10), (40, 40))

        # both points outside - check if both are different illegal values and check
        # that even if twice the same illegal point is submitted it will not be
        # accepted
        illegal_points = [(-3, -3), (-3, 8), (8, -3), (40, 40), (40, 8),
                          (8, 40)]
        for ilpt_1 in illegal_points:
            for ilpt_2 in illegal_points:
                # print ilpt_1, ilpt_2
                self.assertRaises(StandardError,
                                  myD.get_distance_between_points, ilpt_1,
                                  ilpt_2)

        # both points are next to each other / all around
        self.assertEqual(myD.get_distance_between_points((10, 10), (10, 9)),
                         myFlaeche.scale)
        self.assertEqual(myD.get_distance_between_points((10, 10), (10, 11)),
                         myFlaeche.scale)
        self.assertEqual(myD.get_distance_between_points((10, 10), (9, 10)),
                         myFlaeche.scale)
        self.assertEqual(myD.get_distance_between_points((10, 10), (11, 10)),
                         myFlaeche.scale)

        self.assertAlmostEqual(
            myD.get_distance_between_points((10, 10), (9, 9)),
            myFlaeche.scale * 1.41421356)
        self.assertAlmostEqual(
            myD.get_distance_between_points((10, 10), (9, 11)),
            myFlaeche.scale * 1.41421356)
        self.assertAlmostEqual(
            myD.get_distance_between_points((10, 10), (11, 9)),
            myFlaeche.scale * 1.41421356)
        self.assertAlmostEqual(
            myD.get_distance_between_points((10, 10), (11, 11)),
            myFlaeche.scale * 1.41421356)

        # 2 points a bit off
        self.assertAlmostEqual(
            myD.get_distance_between_points((10, 10), (20, 10)), 10)
        self.assertAlmostEqual(
            myD.get_distance_between_points((10, 10), (21, 15)), 12, 0)
        # 121 + 25 = 145  appox 12 * 12

        # same again with a driffent scale
        myFlaeche = main.Flaeche(xdim=9, ydim=9, scale=0.25)
        myD = Dijkstra(myFlaeche, (10, 10), (20, 10))
        # points are equal
        self.assertEqual(myD.get_distance_between_points((2, 2), (2, 2)), 0)
        # point a outside
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (-3, -3), (10, 10))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (-3, 8), (10, 10))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (8, -3), (10, 10))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (8, 40), (10, 10))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (40, 8), (10, 10))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (40, 40), (10, 10))

        # point b outside
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (10, 10), (-3, -3))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (10, 10), (-3, 8))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (10, 10), (8, -3))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (10, 10), (8, 40))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (10, 10), (40, 8))
        self.assertRaises(StandardError, myD.get_distance_between_points,
                          (10, 10), (40, 40))

        # both points outside - check if both are different illegal values and check
        # that even if twice the same illegal point is submitted it will not be
        # accepted
        illegal_points = [(-3, -3), (-3, 8), (8, -3), (40, 40), (40, 8),
                          (8, 40)]
        for ilpt_1 in illegal_points:
            for ilpt_2 in illegal_points:
                # print ilpt_1, ilpt_2
                self.assertRaises(StandardError,
                                  myD.get_distance_between_points, ilpt_1,
                                  ilpt_2)

        # both points are next to each other all around
        self.assertEqual(myD.get_distance_between_points((10, 10), (10, 9)),
                         myFlaeche.scale)
        self.assertEqual(myD.get_distance_between_points((10, 10), (10, 11)),
                         myFlaeche.scale)
        self.assertEqual(myD.get_distance_between_points((10, 10), (9, 10)),
                         myFlaeche.scale)
        self.assertEqual(myD.get_distance_between_points((10, 10), (11, 10)),
                         myFlaeche.scale)

        self.assertAlmostEqual(
            myD.get_distance_between_points((10, 10), (9, 9)),
            myFlaeche.scale * 1.41421356)
        self.assertAlmostEqual(
            myD.get_distance_between_points((10, 10), (9, 11)),
            myFlaeche.scale * 1.41421356)
        self.assertAlmostEqual(
            myD.get_distance_between_points((10, 10), (11, 9)),
            myFlaeche.scale * 1.41421356)
        self.assertAlmostEqual(
            myD.get_distance_between_points((10, 10), (11, 11)),
            myFlaeche.scale * 1.41421356)

        # 2 points a bit off
        self.assertAlmostEqual(
            myD.get_distance_between_points((10, 10), (20, 10)), 2.5)
        self.assertAlmostEqual(
            myD.get_distance_between_points((10, 10), (21, 15)), 3, 0)
示例#24
0
    def test_flaeche(self):
        """constuctor test"""

        myFlaeche = main.Flaeche(xdim=20, ydim=10, scale=1)
        self.assertEqual(myFlaeche.cluster_length_x, 20)
        self.assertEqual(myFlaeche.cluster_length_y, 10)
示例#25
0
    def test_convert_cell_id_to_tuple(self):
        """convering cell id strings to tuples"""

        myFlaeche = main.Flaeche(xdim=100, ydim=100, scale=1)
        self.assertEqual((12, 12, 5),
                         myFlaeche.convert_cell_id_to_tuple("12_12_5"))
示例#26
0
    def test_get_distance_between(self):
        """test the correct disstance between two points"""

# scales = [1, 0.25] # 0.25 is to slow
        # compare speed with c++
        scales = [1, 2]

        for scale in scales:
            start = (10, 10, 0)
            end = (20, 10, 0)
            myFlaeche = main.Flaeche(xdim=60, ydim=60, scale=scale)

            vessel = main.Vessel(myFlaeche,
                                 [(0, 0), (40, 40), (40, 200), (-40, 200),
                                     (-40, 40), (0, 0)])

            myD = main.AdAStar(start_node=start, end_node=end, vessel=vessel)

            # points are equal
            self.assertEqual(0,
                             myD.get_distance_between_points((2, 2, 0), (2, 2, 0)))

            self.assertEqual(0,
                             myD.get_distance_between_points((2, 2, 0), (2, 2, 2)))

            # make sure that for ADA are allway 3-tuples used
            self.assertRaises(StandardError,
                              myD.get_distance_between_points, (2, 2), (2, 2))

        # needs more implementation
        # what to do if i want to know how far i am form my own point,
        # but under a different angle

            self.assertEqual(0,
                             myD.get_distance_between_points((2, 2, 0), (2, 2, 2)))

            self.assertRaises(StandardError,
                              myD.get_distance_between_points, (-3, -3, 0), (10, 10, 0))

            # point a outside
            self.assertRaises(StandardError,
                              myD.get_distance_between_points, (-3,  -3, 0), (10, 10, 0))
            self.assertRaises(StandardError,
                              myD.get_distance_between_points, (-3,   8, 0), (10, 10, 0))
            self.assertRaises(StandardError,
                              myD.get_distance_between_points, (8,  -3, 0), (10, 10, 0))
            self.assertRaises(StandardError,
                              myD.get_distance_between_points, (8, 400, 0), (10, 10, 0))
            self.assertRaises(StandardError,
                              myD.get_distance_between_points, (400,   8, 0), (10, 10, 0))
            self.assertRaises(StandardError,
                              myD.get_distance_between_points, (400, 400, 0), (10, 10, 0))

            # point b outside
            self.assertRaises(StandardError,
                              myD.get_distance_between_points, (10, 10, 0), (-3,  -3, 0))
            self.assertRaises(StandardError,
                              myD.get_distance_between_points, (10, 10, 0), (-3,   8, 0))
            self.assertRaises(StandardError,
                              myD.get_distance_between_points, (10, 10, 0), (8,  -3, 0))
            self.assertRaises(StandardError,
                              myD.get_distance_between_points, (10, 10, 0), (8, 400, 0))
            self.assertRaises(StandardError,
                              myD.get_distance_between_points, (10, 10, 0), (400,   8, 0))
            self.assertRaises(StandardError,
                              myD.get_distance_between_points, (10, 10, 0), (400, 400, 0))

            # both points outside - check if both are different illegal values and check
            # that even if twice the same illegal point is submitted it will
            # not be accepted
            illegal_points = [(-3, -3, 0), (-3,   8, 0),
                              (8, -3, 0), (400, 400, 0),
                              (400,  8, 0), (8, 400, 0)]

            for ilpt_1 in illegal_points:
                for ilpt_2 in illegal_points:
                    self.assertRaises(StandardError,
                                      myD.get_distance_between_points, ilpt_1, ilpt_2)

            # both points are next to each other / all around
            self.assertEqual(myD.get_distance_between_points((10, 10, 0), (10,  9, 0)),
                             myFlaeche.scale)

            self.assertEqual(myFlaeche.scale,
                             myD.get_distance_between_points((10, 10, 0), (10, 11, 0)))

            self.assertEqual(myFlaeche.scale,
                             myD.get_distance_between_points((10, 10, 0), (9, 10, 0)))

            self.assertEqual(myFlaeche.scale,
                             myD.get_distance_between_points((10, 10, 0), (11, 10, 0)))

            self.assertAlmostEqual(myFlaeche.scale * 1.41421356,
                                   myD.get_distance_between_points((10, 10, 0), (9,  9, 0)))

            self.assertAlmostEqual(myFlaeche.scale * 1.41421356,
                                   myD.get_distance_between_points((10, 10, 0), (9, 11, 0)))

            self.assertAlmostEqual(myFlaeche.scale * 1.41421356,
                                   myD.get_distance_between_points((10, 10, 0), (11,  9, 0)))

            self.assertAlmostEqual(myFlaeche.scale * 1.41421356,
                                   myD.get_distance_between_points((10, 10, 0), (11, 11, 0)))

            # 2 points a bit off
            self.assertAlmostEqual(10 * scale,
                                   myD.get_distance_between_points((10, 10, 0), (20, 10, 0)))

            # 121 + 25 = 145  appox 12 * 12
            self.assertAlmostEqual(12 * scale,
                                   myD.get_distance_between_points(
                                       (10, 10, 0), (21, 15, 0)),
                                   0)
示例#27
0
    def test_ada_step_internals(self):
        """ Test for adastar's results after the first step        """

        """test if the start point is added to the open node list"""

        myFlaeche = main.Flaeche(
            xdim=500, ydim=500, scale=10, output='result_ada_star_internals')
        # vessel = main.Vessel(myFlaeche,
        #                     [(0, 0), (40, 40), (40, 200), (-40, 200), (-40, 40), ( 0, 0)])

        vessel = main.Vessel(myFlaeche,
                             [(0, 0), (-10, 10), (-30, 10), (-30, -10),
                              (-10, -10), (0, 0)])

        vessel.r = 20
        vessel.speed = 10  # m/s
#       vessel.x = 300; vessel.y = 305; vessel.rotation = 0;

        start = (30, 10, 0)  # cell coordinates
        end = (40, 10, 0)

        # do the first step and add the strat point to the open node list

        myD_step_zero = main.AdAStar(
            vessel=vessel, start_node=start, end_node=end)
        myD_step_zero.step()

        self.assertEqual([(30, 10, 0)],
                         myD_step_zero.get_open_nodes('tuples'))

        self.assertEqual([],
                         myD_step_zero.get_closed_nodes('tuples'))

        # now, do the second step and check the lists again
        expected_result_open_list = [
            (30, 6, 8), (30, 14, 8),
            (31, 6, 9), (31, 10, 0), (31, 14, 7),
            (32, 6, 10), (32, 7, 11), (32, 8, 12), (32, 9, 14),
            (32, 10, 0), (32, 11, 2), (32, 12, 4), (32, 13, 5), (32, 14, 6)]

        expected_result_closed_list = [(30, 10, 0)]

        myD_step_zero.step(visual=True)
        result_open_list = myD_step_zero.get_open_nodes('tuples')
        result_closed_list = myD_step_zero.get_closed_nodes('tuples')

        self.assertEqual(sorted(expected_result_open_list),
                         sorted(result_open_list))

        self.assertEqual(sorted(expected_result_closed_list),
                         sorted(result_closed_list))

        if visual:
            myFlaeche.draw_course_ghost_ship(vessel,
                                             myD_step_zero.current_node_copy.x_coord,
                                             myD_step_zero.current_node_copy.y_coord,
                                             myD_step_zero.current_node_copy.sector_id,
                                             vessel.r, 45)
            myFlaeche.vis_show()

        """test that nodes in the closed nodes list are omitted"""
        myD_fake_closed = main.AdAStar(
            vessel=vessel, start_node=start, end_node=end)

        # make a first step
        myD_fake_closed.step()

        # this is the second one to choose
        dn_2d = myFlaeche.get_node_data((31, 10))
        myDN_2 = StarNodeC(node_data=dn_2d,
                           sector_id=0,
                           reached_by_angle=0,
                           costs_till_here=4,
                           estimated_remaining_costs=5,
                           previous_node=None
                           )

        myD_fake_closed.closed_nodes_list.append(myDN_2)

        # should find myDN_2 as suspicious node
        # and reject as it already is in closed node list

        myD_fake_closed.step()
        self.assertTrue(
            (31, 10, 0) not in myD_fake_closed.get_open_nodes('tuples'))
示例#28
0
    def test_dijkstra_nodes_basic_funtionality(self):
        """testing init, get_min,  the home brewn node list """
        """test the ways of initialiation of DNLists"""
        myFlaeche = main.Flaeche(xdim=30, ydim=30, scale=1)
        myD = Dijkstra(myFlaeche, start_node=(0, 0), end_node=(20, 10))

        myDN_1 = StarNode(xx=3, yy=3, tt=4, dd=5, lastNode=None)
        myDN_2 = StarNode(xx=4, yy=3, tt=4, dd=5, lastNode=None)
        myDN_3 = StarNode(xx=5, yy=3, tt=4, dd=5, lastNode=None)
        myDN_4 = StarNode(xx=20, yy=9, tt=2, dd=1, lastNode=None)

        myDD_1 = DNList([myDN_1, myDN_2, myDN_3])
        myDD_2 = DNList([myDN_1, myDN_2, myDN_3])

        myDNL = DNList([myDN_1, myDN_2, myDN_3])
        self.assertEqual([ii for ii in myDNL], [myDN_1, myDN_2, myDN_3])
        """insert a few nodes into the list, and iter over them by id"""
        myDNL_id_1 = DNList([myDN_1, myDN_2, myDN_3], 'id')
        self.assertEqual([ii for ii in myDNL_id_1], ['3_3', '4_3', '5_3'])
        """alter the order of the few nodes , and iter over them by id"""
        myDNL_id_2 = DNList([myDN_3, myDN_2, myDN_1], 'id')
        self.assertEqual([ii for ii in myDNL_id_2], ['5_3', '4_3', '3_3'])
        """insert a few nodes into the list, and iter over them by tuple"""
        myDNL_tuple = DNList([myDN_1, myDN_2, myDN_3], 'tuple')
        self.assertEqual([ii for ii in myDNL_tuple], [(3, 3), (4, 3), (5, 3)])
        """return a node by its id, if not exists return none """
        myDNL_ret_id = DNList([myDN_1, myDN_2, myDN_3], 'id')
        self.assertEqual(myDNL_ret_id.get_by_id('3_3'), myDN_1)
        self.assertIsNone(myDNL_ret_id.get_by_id('5_5'))
        """return a node by its tuple, if not exists return none """
        myDNL_ret_tup = DNList([myDN_1, myDN_2, myDN_3], 'tuple')
        self.assertEqual(myDNL_ret_id.get_by_tuple((3, 3)), myDN_1)
        self.assertIsNone(myDNL_ret_id.get_by_tuple((5, 5)))
        """return a node by its tuple, even if the DNodeList iters on ids """
        myDNL_ret_tup = DNList([myDN_1, myDN_2, myDN_3], 'id')
        self.assertEqual(myDNL_ret_id.get_by_tuple((3, 3)), myDN_1)
        """test to retrive the minimal node from List"""
        myDNL_get_min = DNList([myDN_1, myDN_2, myDN_3, myDN_4])
        self.assertEqual(myDNL_get_min.get_min_node(), myDN_4)
        """test to retrive the minimal node and remove it from the list"""
        myDNL_pop_min = DNList([myDN_1, myDN_2, myDN_3, myDN_4])
        self.assertEqual(myDNL_pop_min.get_min_node(pop=True), myDN_4)
        self.assertNotEqual(myDNL_pop_min.get_min_node(), myDN_4)
        """test to get back the tuples of all nodes in the list"""
        myDNL_tup_list = DNList([myDN_1, myDN_2, myDN_3])
        self.assertEqual(myDNL_tup_list.get_tuples(), [(3, 3), (4, 3), (5, 3)])
        """test to see what happens if the node list is empty"""
        """make sure that only each node id is only once in the list
           should be already managed in the initalization
           keep a 'global'/class list with all nodes

           * handling alternation after creation - maybe function_closurures
           * overwriting the append function

           """
        """make sure that only nodes from the same Dijkstra are added"""
        # currently there is only one Dijkstra at a time
        """test to make sure, the list only takes dijkstra nodes"""
        # this does not work - not too urgent now
        # self.assertRaises(AssertionError, Dijkstra.DNList, [myDN_1, myDN_2, 1] )

        """insert a few nodes into the list, and iter over them returning
           the distance traveled"""  # to be done when needed

        """insert a few nodes into the list, and iter over them returning
示例#29
0
    def test_adastar_nodes_basic_funtionality(self):
        """testing init, get_min,  the home brewn node list """

        """test the ways of initialiation of DNLists"""
        myFlaeche = main.Flaeche(xdim=30, ydim=30, scale=1)

        vessel = main.Vessel(myFlaeche,
                             [(0, 0), (40, 40), (40, 200), (-40, 200), (-40, 40), (0, 0)])

        myD = main.AdAStar(start_node=(0, 0, 0),
                           end_node=(20, 10, 0),
                           vessel=vessel)

        myDN_1 = StarNodeC(node_data=myFlaeche.get_node_data((3, 3)),
                           sector_id=0,
                           reached_by_angle=0,
                           costs_till_here=4,
                           estimated_remaining_costs=5,
                           previous_node=None
                           )

        myDN_2 = StarNodeC(node_data=myFlaeche.get_node_data((4, 3)),
                           sector_id=0,
                           reached_by_angle=0,
                           costs_till_here=4,
                           estimated_remaining_costs=5,
                           previous_node=None
                           )

        myDN_3 = StarNodeC(node_data=myFlaeche.get_node_data((5, 3)),
                           sector_id=0,
                           reached_by_angle=0,
                           costs_till_here=4,
                           estimated_remaining_costs=5,
                           previous_node=None
                           )

        myDN_4 = StarNodeC(node_data=myFlaeche.get_node_data((20, 9)),
                           sector_id=0,
                           reached_by_angle=0,
                           costs_till_here=3,
                           estimated_remaining_costs=0,
                           previous_node=None
                           )

        myDD_1 = ANList([myDN_1, myDN_2, myDN_3])

        """insert a few nodes into the list, and iter over them by id"""
        myANL_id_1 = ANList([myDN_1, myDN_2, myDN_3], 'id')
        self.assertEqual(
            [ii for ii in myANL_id_1], ['3_3_0', '4_3_0', '5_3_0'])

        """alter the order of the few nodes , and iter over them by id"""
        myANL_id_2 = ANList([myDN_3, myDN_2, myDN_1], 'id')
        self.assertEqual(
            [ii for ii in myANL_id_2], ['5_3_0', '4_3_0', '3_3_0'])

        """insert a few nodes into the list, and iter over them by tuple"""
        myANL_tuple = ANList([myDN_1, myDN_2, myDN_3], 'tuple')
        self.assertEqual(
            [ii for ii in myANL_tuple], [(3, 3, 0), (4, 3, 0), (5, 3, 0)])

        """return a node by its id, if not exists return none """
        myANL_ret_id = ANList([myDN_1, myDN_2, myDN_3], 'id')
        self.assertEqual(myANL_ret_id.get_by_id('3_3_0'), myDN_1)
        self.assertIsNone(myANL_ret_id.get_by_id('3_3_1'))

        """return a node by its tuple, if not exists return none """
        myANL_ret_tup = ANList([myDN_1, myDN_2, myDN_3], 'tuple')
        self.assertEqual(myANL_ret_id.get_by_tuple((3, 3, 0)), myDN_1)
        self.assertIsNone(myANL_ret_id.get_by_tuple((3, 3, 1)))

        """return a node by its tuple, even if the DNodeList iters on ids """
        myANL_ret_tup = ANList([myDN_1, myDN_2, myDN_3], 'id')
        self.assertEqual(myANL_ret_id.get_by_tuple((3, 3, 0)), myDN_1)

        """test to get back the tuples of all nodes in the list"""
        myANL_tup_list = ANList([myDN_1, myDN_2, myDN_3])
        self.assertEqual(
            myANL_tup_list.get_tuples(), [(3, 3, 0), (4, 3, 0), (5, 3, 0)])

        """test to retrive the minimal node from List"""
        myANL_get_min = ANList([myDN_1, myDN_2, myDN_3, myDN_4])
        self.assertEqual(myANL_get_min.get_min_node(), myDN_4)

        """test to retrive the minimal node and remove it from the list"""
        myANL_pop_min = ANList([myDN_1, myDN_2, myDN_3, myDN_4])
        self.assertEqual(myANL_pop_min.get_min_node(pop=True), myDN_4)
        self.assertNotEqual(myANL_pop_min.get_min_node(), myDN_4)

        """test to see what happens if the node list is empty"""

        """make sure that only each node id is only once in the list
           should be already managed in the initalization
           keep a 'global'/class list with all nodes

           * handling alternation after creation - maybe function_closurures
           * overwriting the append function

           """

        """make sure that only nodes from the same AdAStar are added"""
        # currently there is only one AdAStar at a time

        """test to make sure, the list only takes adastar nodes"""
        # this does not work - not too urgent now
        # self.assertRaises(AssertionError, main.AdAStar.ANList, [myDN_1, myDN_2, 1] )

        """insert a few nodes into the list, and iter over them returning
           the distance traveled"""  # to be done when needed

        """insert a few nodes into the list, and iter over them returning
示例#30
0
    def test_convert_trajectroy_points_to_bypassed_cells(self):
        """test to find the propper cells of a series of points"""
        def get_trajectory(print_traj=True):
            vessel = main.Vessel(myFlaeche, [(0, 0), (-10, 10), (-30, 10),
                                             (-30, -10), (-10, -10), (0, 0)])
            result_pos = vessel.get_points_on_the_circle_ego(
                radius_to_point=40, angle_ego=0.5 * math.pi)

            result_pos = [(pp[0] + 5, pp[1] + 5, pp[2]) for pp in result_pos]

            if print_traj:
                print result_pos

            return result_pos

        visual = VISUAL

        # ########################
        # basic test
        myFlaeche = main.Flaeche(xdim=100, ydim=100, scale=10)
        trajectory = [(5, 5, 0), (6, 6, 0), (6, 11, 0)]

        expected_result = [(0, 0, 0), (0, 1, 0)]
        result = myFlaeche.convert_trajectroy_points_to_bypassed_cells(
            trajectory)
        self.assertEqual(expected_result, result)

        # ########################
        # test with graphical output

        image_name = self.__dict__['_testMethodName']
        myFlaeche = main.Flaeche(xdim=60, ydim=60, scale=10, output=image_name)

        # manualy reduced trajectory from:
        # trajectory = get_trajectory()

        trajectory = [

            # ### (0, 0, 0)
            (5.0, 5.0, 0.0),
            (9.046732879497288, 5.205227064324194, 0.10134169850289655),

            # ### (1, 0, 0)
            (10.053543796885169, 5.320512917970279, 0.1266771231286207),

            # ### (1, 0, 1)
            (12.056790650312337, 5.627399048098636, 0.17734797238006897),
            (19.837984034790708, 7.853880017109511, 0.3800313693858621),

            # ### (2, 0, 1)
            (20.774234204532743, 8.241687535190776, 0.4053667940115862),

            # ### (2, 1, 1)
            (24.412078501243244, 10.026135354216716, 0.5067084925144828),
            (27.011708609495656, 11.601127502703704, 0.5827147663916552),

            # ### (2, 1, 2)
            (27.850728603791694, 12.169462351708948, 0.6080501910173793),
            (28.67508187148069, 12.758869461839799, 0.6333856156431035),
            (29.484239301906513, 13.36897052249206, 0.6587210402688276),

            # ### (3, 1, 2)
            (30.27768153785216, 13.99937394066165, 0.6840564648945517),
            (32.558676763027464, 16.0082885108352, 0.7600627387717241),
            (35.35032490771164, 18.945100691111108, 0.8614044372746207),

            # ### (3, 2, 2)
            (36.63102947750794, 20.515760698093484, 0.912075286526069),

            # ### (3, 2, 3)
            (39.47088002974199, 24.708168392795713, 1.0387524096546898),
            (39.97386464578329, 25.587921498756767, 1.064087834280414),

            # ### (4, 2, 3)
            (40.45440130753634, 26.480134235795184, 1.0894232589061383),

            # ### (4, 3, 3)
            (43.723084754648184, 34.97389870965123, 1.3174420805376565),

            # ### (4, 3, 4)
            (44.53873297312447, 38.94288889981701, 1.4187837790405535),

            # ### (4, 4, 4)
            (44.98716301185723, 43.98669142747258, 1.5454609021691748)
        ]

        expected_result = [
            (0, 0, 0), (1, 0, 0), (1, 0, 1), (2, 0, 1), (2, 1, 1), (2, 1, 2),
            (3, 1, 2), (3, 2, 2), (3, 2, 3), (4, 2, 3), (4, 3, 3), (4, 3, 4),
            (4, 4, 4)
        ]

        result = myFlaeche.convert_trajectroy_points_to_bypassed_cells(
            trajectory)

        self.assertEqual(expected_result, result)

        if visual:
            myFlaeche.vis_reset()
            for pp in trajectory:
                myFlaeche.vis_add_single_point((pp[0], pp[1]), 'darkseagreen')
            myFlaeche.vis_add_red(result)
            myFlaeche.vis_show()