1+ """
2+ This file implements a grid with a 3d reservation matrix with dimensions for x, y, and time. There
3+ is also infrastructure to generate dynamic obstacles that move around the grid. The obstacles' paths
4+ are stored in the reservation matrix on creation.
5+ """
16import numpy as np
27import matplotlib .pyplot as plt
38from enum import Enum
9+ from dataclasses import dataclass
410
11+ @dataclass (order = True )
512class Position :
613 x : int
714 y : int
815
9- def __init__ (self , x : int , y : int ):
10- self .x = x
11- self .y = y
12-
1316 def as_ndarray (self ) -> np .ndarray :
1417 return np .array ([self .x , self .y ])
1518
@@ -27,14 +30,6 @@ def __sub__(self, other):
2730 f"Subtraction not supported for Position and { type (other )} "
2831 )
2932
30- def __eq__ (self , other ):
31- if isinstance (other , Position ):
32- return self .x == other .x and self .y == other .y
33- return False
34-
35- def __repr__ (self ):
36- return f"Position({ self .x } , { self .y } )"
37-
3833
3934class ObstacleArrangement (Enum ):
4035 # Random obstacle positions and movements
@@ -46,7 +41,7 @@ class ObstacleArrangement(Enum):
4641class Grid :
4742 # Set in constructor
4843 grid_size : np .ndarray
49- grid : np .ndarray
44+ reservation_matrix : np .ndarray
5045 obstacle_paths : list [list [Position ]] = []
5146 # Obstacles will never occupy these points. Useful to avoid impossible scenarios
5247 obstacle_avoid_points : list [Position ] = []
@@ -68,7 +63,7 @@ def __init__(
6863 self .obstacle_avoid_points = obstacle_avoid_points
6964 self .time_limit = time_limit
7065 self .grid_size = grid_size
71- self .grid = np .zeros ((grid_size [0 ], grid_size [1 ], self .time_limit ))
66+ self .reservation_matrix = np .zeros ((grid_size [0 ], grid_size [1 ], self .time_limit ))
7267
7368 if num_obstacles > self .grid_size [0 ] * self .grid_size [1 ]:
7469 raise Exception ("Number of obstacles is greater than grid size!" )
@@ -83,8 +78,8 @@ def __init__(
8378 for t , position in enumerate (path ):
8479 # Reserve old & new position at this time step
8580 if t > 0 :
86- self .grid [path [t - 1 ].x , path [t - 1 ].y , t ] = obs_idx
87- self .grid [position .x , position .y , t ] = obs_idx
81+ self .reservation_matrix [path [t - 1 ].x , path [t - 1 ].y , t ] = obs_idx
82+ self .reservation_matrix [position .x , position .y , t ] = obs_idx
8883
8984 """
9085 Generate dynamic obstacles that move around the grid. Initial positions and movements are random
@@ -191,7 +186,7 @@ def valid_position(self, position: Position, t: int) -> bool:
191186 return False
192187
193188 # Check if new position is not occupied at time t
194- return self .grid [position .x , position .y , t ] == 0
189+ return self .reservation_matrix [position .x , position .y , t ] == 0
195190
196191 """
197192 Returns True if the given position is valid at time t and is not in the set of obstacle_avoid_points
0 commit comments