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_get_predefiend_shadow_shape(self): """why is the black shade missing one cell??""" 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 vessel.generate_predefiend_shadow_shapes() sector_to_inspect = 8 vessel.transform_hull_points(myFlaeche.get_angle_from_sector_id(sector_to_inspect), (105, 105)) result = vessel.predefined_shadow_shapes[sector_to_inspect] for ii in range(len(result)): print print ii, ': ', result[ii] result[ii] = (result[ii][0] + 10, result[ii][1] + 10) print ii, ': ', result[ii] if visual: myFlaeche.vis_reset() myFlaeche.vis_add_black(result) myFlaeche.vis_show(vessel.transformed_hull_points)
def test_get_distance_to_end(self): """ttel the distance heurisitics from the point to dest.""" 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(5, myD.get_distance_to_end((15, 10, 0))) # reach the end self.assertEqual(0, myD.get_distance_to_end((20, 10, 0))) # negaive root self.assertEqual(10, myD.get_distance_to_end((20, 20, 0))) # illegal point self.assertRaises(StandardError, myD.get_distance_to_end, (40, 40)) # illegal point self.assertRaises(StandardError, myD.get_distance_to_end, (40, 40, 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_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_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_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_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. """ visual = VISUAL visual = True 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()
def test_dijsktra_step_internals_find_final__bug_d(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 """ visual = VISUAL visual = True myFlaeche = main.Flaeche(xdim=500, ydim=500, scale=10, output='result_hindrance_punctual_ada__d') 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) ####### surgery cut #### if False: myD.step() myD.step() print myD.get_open_nodes('tuples') print len(myD.get_open_nodes('tuples')) assert False ####### surgery glue #### myD.run()
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 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
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_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 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_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)
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_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()
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)
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'))
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)
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)
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_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)