@@ -81,6 +81,7 @@ def __init__(
8181 self .obstacle_paths = self .generate_narrow_corridor_obstacles (num_obstacles )
8282
8383 for i , path in enumerate (self .obstacle_paths ):
84+ # TODO: i think this is a bug. obstacle indices will overlap with robot indices
8485 obs_idx = i + 1 # avoid using 0 - that indicates free space in the grid
8586 for t , position in enumerate (path ):
8687 # Reserve old & new position at this time step
@@ -282,20 +283,36 @@ def get_obstacle_positions_at_time(self, t: int) -> tuple[list[int], list[int]]:
282283 """
283284 Returns safe intervals for each cell.
284285 """
285- def get_safe_intervals (self ) -> np .ndarray :
286+ def get_safe_intervals (self , agent_idx : int ) -> np .ndarray :
286287 intervals = empty_2d_array_of_lists (self .grid_size [0 ], self .grid_size [1 ])
287288 for x in range (intervals .shape [0 ]):
288289 for y in range (intervals .shape [1 ]):
289- intervals [x , y ] = self .get_safe_intervals_at_cell (Position (x , y ))
290+ intervals [x , y ] = self .get_safe_intervals_at_cell (Position (x , y ), agent_idx )
290291
291292 return intervals
292293
293294 """
294295 Generate the safe intervals for a given cell. The intervals will be in order of start time.
295296 ex: Interval (2, 3) will be before Interval (4, 5)
296297 """
297- def get_safe_intervals_at_cell (self , cell : Position ) -> list [Interval ]:
298+ def get_safe_intervals_at_cell (self , cell : Position , agent_idx : int ) -> list [Interval ]:
298299 vals = self .reservation_matrix [cell .x , cell .y , :]
300+
301+ had_constraints = False
302+ # ct: AppliedConstraint
303+ for constraint_set in self .constraint_points [cell .x , cell .y ]:
304+ for constraint in constraint_set :
305+ if constraint .constrained_agent != agent_idx :
306+ continue
307+ if constraint .constraint .position != cell :
308+ continue
309+ had_constraints = True
310+ vals [constraint .constraint .time ] = 99999 # TODO: no magic numbers
311+
312+ # TODO: hack
313+ # if constraint.constraint.time + 1 < self.time_limit:
314+ # vals[constraint.constraint.time + 1] = 99999 # TODO: no magic numbers
315+
299316 # Find where the array is zero
300317 zero_mask = (vals == 0 )
301318
@@ -321,6 +338,10 @@ def get_safe_intervals_at_cell(self, cell: Position) -> list[Interval]:
321338 # move into and out of the cell each take 1 time step, and the cell is considered occupied during
322339 # both the time step when it is entering the cell, and the time step when it is leaving the cell.
323340 intervals = [interval for interval in intervals if interval .start_time != interval .end_time ]
341+
342+ # if had_constraints:
343+ # print("\t\tconstraints: ", self.constraint_points[cell.x, cell.y])
344+ # print("\t\tintervals: ", intervals)
324345 return intervals
325346
326347 """
0 commit comments