Skip to content

Commit b247bfa

Browse files
committed
Fixed Error in update_road_ids
1 parent ea1d5a4 commit b247bfa

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

omega_prime/mapsemgents.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,23 @@ def update_road_ids(self):
8080
"""
8181
Updates the road_ids of the lane to the segment ID
8282
"""
83-
for i, lane in enumerate(self.lanes.values()):
83+
# Create a list of items to avoid modifying dictionary during iteration
84+
lanes_items = list(self.lanes.items())
85+
86+
for original_key, lane in lanes_items:
8487
lane_id = lane.idx.lane_id
8588
if lane_id in self.lane_segment_dict and self.lane_segment_dict[lane_id].segment is not None:
86-
lane.idx = OsiLaneId(road_id=self.lane_segment_dict[lane_id].segment.idx, lane_id=lane_id)
89+
# Create the new namedtuple with updated road_id
90+
new_idx = lane.idx._replace(road_id=self.lane_segment_dict[lane_id].segment.idx)
91+
92+
# Create a new lane object with the updated idx
93+
updated_lane = lane
94+
updated_lane.idx = new_idx
95+
96+
# Update the dictionary - remove old entry and add new one
97+
self.lanes[new_idx] = updated_lane
98+
if original_key != new_idx:
99+
del self.lanes[original_key] # Delete the old key if it's different
87100
else:
88101
# print(f"Lane {lane_id} is not part of an intersection, so it has no segment ID")
89102
pass

0 commit comments

Comments
 (0)