Exemple #1
0
    def test_ada_step_internals_update_open_list(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')
#        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)

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

        # make a first step
        myD_fake_open.step()

        # put a fake dummy of a node which will be found into the open list
        # put bad data for the dummy so the real one will be better and
        # the node data has to be  updated

        test_node_tuple = (31, 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=4,
                           estimated_remaining_costs=180,
                           previous_node=None
                           )

        myD_fake_open.open_nodes_list.append(myDN_2)

        # make sure that the fake one is realy in the open list
        self.assertTrue((31, 10, 0) in myD_fake_open.get_open_nodes('tuples'))

        faked_node_data = ANList(
            myD_fake_open.open_nodes_list).get_by_tuple(test_node_tuple)
        self.assertEqual(faked_node_data.full_costs, 184)

        # make a step
        myD_fake_open.step()

        # make sure the node data has been updated
        self.assertTrue((31, 10, 0) in myD_fake_open.get_open_nodes('tuples'))
        faked_node_data = ANList(
            myD_fake_open.open_nodes_list).get_by_tuple(test_node_tuple)
        self.assertEqual(faked_node_data.full_costs, 10)
    def test_ada_no_hindrances_circle_horisontal_from_down_to_up_inside_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  __never_leaves_the_canvas__.
        Hence it __should_allways_pass__ 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 = (15, 21, 8)  # cell coordinates
        end = (26, 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 = [(11, 16, 13), (12, 20, 10), (15, 21, 8),
                           (16, 13, 0), (17, 13, 0), (20, 13, 0), (23, 13, 0),
                           (26, 13, 0)]

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

        if visual:
            myD.draw_path(vessel=vessel)
        del (myD)
Exemple #3
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)
    def test_ada_run_and_rebuild_hindrance_one_spot_ignored_still_oczil(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,
                             [(0, 0), (-10, 10), (-30, 10), (-30, -10),
                              (-10, -10), (0, 0)])

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

        blocked_nodes = [(20, 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()
        if visual:
            myD.draw_path(vessel=vessel)
        del(myD)
    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_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)
    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)
    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)
Exemple #9
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
Exemple #10
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)
Exemple #11
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