Skip to content

Commit

Permalink
added propertygrid to experimental cell spaces, after ruff check
Browse files Browse the repository at this point in the history
  • Loading branch information
haleelsada committed Mar 4, 2024
1 parent 3c1aa19 commit 32680d0
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions mesa/experimental/cell_space/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from random import Random
from typing import Generic, TypeVar

from mesa.space import PropertyLayer
from mesa.experimental.cell_space import Cell, DiscreteSpace
from mesa.space import PropertyLayer

T = TypeVar("T", bound=Cell)

Expand Down Expand Up @@ -90,8 +90,7 @@ def _connect_single_cell_nd(self, cell: T, offsets: list[tuple[int, ...]]) -> No
for d_coord in offsets:
n_coord = tuple(c + dc for c, dc in zip(coord, d_coord))
if self.torus:
n_coord = tuple(nc % d for nc, d in zip(
n_coord, self.dimensions))
n_coord = tuple(nc % d for nc, d in zip(n_coord, self.dimensions))
if all(0 <= nc < d for nc, d in zip(n_coord, self.dimensions)):
cell.connect(self._cells[n_coord])

Expand Down Expand Up @@ -140,8 +139,13 @@ def __init__(
cell_klass: type[T] = Cell,
property_layers: None | PropertyLayer | list[PropertyLayer] = None,
) -> None:
super().__init__(dimensions=dimensions, torus=torus,
capacity=capacity, random=random, cell_klass=cell_klass)
super().__init__(
dimensions=dimensions,
torus=torus,
capacity=capacity,
random=random,
cell_klass=cell_klass,
)

self.properties = {}

Expand All @@ -166,9 +170,11 @@ def add_property_layer(self, property_layer: PropertyLayer):
ValueError: If the dimensions of the property layer do not match the grid's dimensions.
"""
if property_layer.name in self.properties:
raise ValueError(
f"Property layer {property_layer.name} already exists.")
if property_layer.width != self.dimensions[0] or property_layer.height != self.dimensions[1]:
raise ValueError(f"Property layer {property_layer.name} already exists.")
if (
property_layer.width != self.dimensions[0]
or property_layer.height != self.dimensions[1]
):
raise ValueError(
f"Property layer dimensions {property_layer.width}x{property_layer.height} do not match grid dimensions {self.dimensions[0]}x{self.dimensions[1]}."
)
Expand Down

0 comments on commit 32680d0

Please sign in to comment.