This class provides a very high level route plan. Instantiate the class by passing a reference to A GlobalRoutePlannerDAO object.
| 18 | |
| 19 | |
| 20 | class GlobalRoutePlanner(object): |
| 21 | """ |
| 22 | This class provides a very high level route plan. |
| 23 | Instantiate the class by passing a reference to |
| 24 | A GlobalRoutePlannerDAO object. |
| 25 | """ |
| 26 | |
| 27 | def __init__(self, dao): |
| 28 | """ |
| 29 | Constructor |
| 30 | """ |
| 31 | self._dao = dao |
| 32 | self._topology = None |
| 33 | self._graph = None |
| 34 | self._id_map = None |
| 35 | self._road_id_to_edge = None |
| 36 | self._intersection_end_node = -1 |
| 37 | self._previous_decision = RoadOption.VOID |
| 38 | |
| 39 | def setup(self): |
| 40 | """ |
| 41 | Performs initial server data lookup for detailed topology |
| 42 | and builds graph representation of the world map. |
| 43 | """ |
| 44 | self._topology = self._dao.get_topology() |
| 45 | self._graph, self._id_map, self._road_id_to_edge = self._build_graph() |
| 46 | self._find_loose_ends() |
| 47 | self._lane_change_link() |
| 48 | |
| 49 | def _build_graph(self): |
| 50 | """ |
| 51 | This function builds a networkx graph representation of topology. |
| 52 | The topology is read from self._topology. |
| 53 | graph node properties: |
| 54 | vertex - (x,y,z) position in world map |
| 55 | graph edge properties: |
| 56 | entry_vector - unit vector along tangent at entry point |
| 57 | exit_vector - unit vector along tangent at exit point |
| 58 | net_vector - unit vector of the chord from entry to exit |
| 59 | intersection - boolean indicating if the edge belongs to an |
| 60 | intersection |
| 61 | return : graph -> networkx graph representing the world map, |
| 62 | id_map-> mapping from (x,y,z) to node id |
| 63 | road_id_to_edge-> map from road id to edge in the graph |
| 64 | """ |
| 65 | graph = nx.DiGraph() |
| 66 | id_map = dict() # Map with structure {(x,y,z): id, ... } |
| 67 | road_id_to_edge = dict() # Map with structure {road_id: {lane_id: edge, ... }, ... } |
| 68 | |
| 69 | for segment in self._topology: |
| 70 | |
| 71 | entry_xyz, exit_xyz = segment['entryxyz'], segment['exitxyz'] |
| 72 | path = segment['path'] |
| 73 | entry_wp, exit_wp = segment['entry'], segment['exit'] |
| 74 | intersection = entry_wp.is_junction |
| 75 | road_id, section_id, lane_id = entry_wp.road_id, entry_wp.section_id, entry_wp.lane_id |
| 76 | |
| 77 | for vertex in entry_xyz, exit_xyz: |
no outgoing calls
no test coverage detected