class_docstr: This class provides a very high level route plan.
class_docstr_tok: ["This","class","provides","a","very","high","level","route","plan","."]
docstr: This function builds a networkx graph representation of topology, creating several class attributes:
  - graph (networkx.DiGraph): networkx graph representing the world map, with:
      Node properties:
          vertex: (x,y,z) position in world map
      Edge properties:
          entry_vector: unit vector along tangent at entry point
          exit_vector: unit vector along tangent at exit point
          net_vector: unit vector of the chord from entry to exit
          intersection: boolean indicating if the edge belongs to an  intersection
  - id_map (dictionary): mapping from (x,y,z) to node id
  - road_id_to_edge (dictionary): map from road id to edge in the graph
docstr_tok: ["This","function","builds","a","networkx","graph","representation","of","topology",",","creating","several","class","attributes",":","-","graph","(","networkx.DiGraph",")",":","networkx","graph","representing","the","world","map",",","with",":","Node","properties",":","vertex",":","(","x",",","y",",","z",")","position","in","world","map","Edge","properties",":","entry_vector",":","unit","vector","along","tangent","at","entry","point","exit_vector",":","unit","vector","along","tangent","at","exit","point","net_vector",":","unit","vector","of","the","chord","from","entry","to","exit","intersection",":","boolean","indicating","if","the","edge","belongs","to","an","intersection","-","id_map","(","dictionary",")",":","mapping","from","(","x",",","y",",","z",")","to","node","id","-","road_id_to_edge","(","dictionary",")",":","map","from","road","id","to","edge","in","the","graph"]
code: def _build_graph(self):
      """
      This function builds a networkx graph representation of topology, creating several class attributes:
      - graph (networkx.DiGraph): networkx graph representing the world map, with:
          Node properties:
              vertex: (x,y,z) position in world map
          Edge properties:
              entry_vector: unit vector along tangent at entry point
              exit_vector: unit vector along tangent at exit point
              net_vector: unit vector of the chord from entry to exit
              intersection: boolean indicating if the edge belongs to an  intersection
      - id_map (dictionary): mapping from (x,y,z) to node id
      - road_id_to_edge (dictionary): map from road id to edge in the graph
      """
  
      self._graph = nx.DiGraph()
      self._id_map = dict()  # Map with structure {(x,y,z): id, ... }
      self._road_id_to_edge = (
          dict()
      )  # Map with structure {road_id: {lane_id: edge, ... }, ... }
  
      for segment in self._topology:
          entry_xyz, exit_xyz = segment["entryxyz"], segment["exitxyz"]
          path = segment["path"]
          entry_wp, exit_wp = segment["entry"], segment["exit"]
          intersection = entry_wp.is_junction
          road_id, section_id, lane_id = (
              entry_wp.road_id,
              entry_wp.section_id,
              entry_wp.lane_id,
          )
  
          for vertex in entry_xyz, exit_xyz:
              # Adding unique nodes and populating id_map
              if vertex not in self._id_map:
                  new_id = len(self._id_map)
                  self._id_map[vertex] = new_id
                  self._graph.add_node(new_id, vertex=vertex)
          n1 = self._id_map[entry_xyz]
          n2 = self._id_map[exit_xyz]
          if road_id not in self._road_id_to_edge:
              self._road_id_to_edge[road_id] = dict()
          if section_id not in self._road_id_to_edge[road_id]:
              self._road_id_to_edge[road_id][section_id] = dict()
          self._road_id_to_edge[road_id][section_id][lane_id] = (n1, n2)
  
          entry_carla_vector = (
              entry_wp.transform.rotation.get_forward_vector()
          )
          exit_carla_vector = (
              exit_wp.transform.rotation.get_forward_vector()
          )
  
          # Adding edge with attributes
          self._graph.add_edge(
              n1,
              n2,
              length=len(path) + 1,
              path=path,
              entry_waypoint=entry_wp,
              exit_waypoint=exit_wp,
              entry_vector=np.array(
                  [
                      entry_carla_vector.x,
                      entry_carla_vector.y,
                      entry_carla_vector.z,
                  ]
              ),
              exit_vector=np.array(
                  [
                      exit_carla_vector.x,
                      exit_carla_vector.y,
                      exit_carla_vector.z,
                  ]
              ),
              net_vector=vector(
                  entry_wp.transform.location,
                  exit_wp.transform.location,
              ),
              intersection=intersection,
              type=RoadOption.LANEFOLLOW,
          )
  
file_path: carla/PythonAPI/carla/agents/navigation/global_route_planner.py
imports: import math
  import numpy
  import networkx
  import carla
  from agents.navigation.local_planner import RoadOption
  from agents.tools.misc import vector
label_desc: Use image node_id 4 for calling the GlobalRoutePlanner obj's underlying member method code with example usage: obj._build_graph() without return types