def test_adastar_nodes_id_creation(self): """test to check the id string and get_coords of a main.AdAStarNode""" 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)]) myAdA = main.AdAStar(start_node=(0, 0, 0), end_node=(20, 10, 0), vessel=vessel) dn_2 = myFlaeche.get_node_data((3, 3)) mySN = StarNodeC(node_data=dn_2, sector_id=0, reached_by_angle=4 * math.pi, costs_till_here=4, estimated_remaining_costs=5, previous_node=None ) self.assertEqual('3_3_0', mySN.id) self.assertEqual((3, 3, 0), mySN.get_coords()) self.assertEqual(9., mySN.full_costs) self.assertEqual(0, mySN.reached_by_angle)
def test_adastar_nodes_id_creation(self): """test to check the id string and get_coords of a main.AdAStarNode""" 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)]) myAdA = main.AdAStar(start_node=(0, 0, 0), end_node=(20, 10, 0), vessel=vessel) dn_2 = myFlaeche.get_node_data((3, 3)) mySN = StarNodeC(node_data=dn_2, sector_id=0, reached_by_angle=4 * math.pi, costs_till_here=4, estimated_remaining_costs=5, previous_node=None ) self.assertEqual('3_3_0', mySN.id) self.assertEqual((3, 3, 0), mySN.get_coords()) self.assertEqual(9., mySN.full_costs) self.assertEqual(0, mySN.reached_by_angle)
def test_get_nodes_list(self): """test the getter of the nodes lists""" start = (10, 10, 0) end = (20, 10, 0) 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=start, end_node=end, vessel=vessel) self.assertEqual(myD.get_open_nodes(), []) 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, 5)), 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((5, 6)), sector_id=0, reached_by_angle=0, costs_till_here=4, estimated_remaining_costs=5, previous_node=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, 0), (4, 3, 0)])) """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, 0), (5, 6, 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_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_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
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'))