projectmesa / mesa-frames

Extension of mesa for performance and scalability
https://projectmesa.github.io/mesa-frames
Apache License 2.0
13 stars 4 forks source link

Abstract GridDF #41

Closed adamamer20 closed 1 month ago

adamamer20 commented 1 month ago

The GridDF class has been implemented as an abstract base class that extends DiscreteSpaceDF, specifically designed for grid-based spatial representations in mesa_frames. Key features and methods include:

  1. Initialization with model object, dimensions, torus property, capacity, and neighborhood type
  2. Grid-specific spatial operations:
    • get_directions: Calculate directions between grid positions or agents
    • get_distances: Calculate distances between grid positions or agents
    • get_neighbors: Find neighboring agents within a given radius on the grid
    • get_cells: Retrieve cell properties and agents for specified grid cells
    • move_agents: Place agents at specific grid positions
    • remove_agents: Remove agents from the grid
  3. Grid-specific utilities:
    • out_of_bounds: Check if positions are outside the grid boundaries (for non-toroidal grids)
    • torus_adj: Adjust coordinates for toroidal grids
  4. Internal grid management:
    • _calculate_differences: Calculate coordinate differences between positions or agents
    • _compute_offsets: Generate neighborhood offsets based on the specified type (Moore, von Neumann, or hexagonal)
    • _get_df_coords: Convert various input formats to a DataFrame of coordinates
    • _generate_empty_grid: Abstract method to create an empty grid with specified dimensions and capacity
    • _place_agents_df: Abstract method to place agents in the grid
  5. Properties:
    • dimensions: Get the grid dimensions
    • neighborhood_type: Get the type of neighborhood used
    • torus: Check if the grid is toroidal

This implementation provides a comprehensive framework for grid-based spatial environments in agent-based models. It handles various grid types (rectangular, toroidal) and neighborhood configurations (Moore, von Neumann, hexagonal). The class manages grid coordinates, agent positions, and cell properties efficiently using DataFrames.

GridDF builds upon the DiscreteSpaceDF class, adding grid-specific functionality while maintaining compatibility with the overall mesa_frames structure. It offers methods for common grid operations like calculating distances and directions, finding neighbors, and handling boundary conditions (toroidal or non-toroidal).

The abstract methods (_generate_empty_grid and _place_agents_df) allow for customization in concrete subclasses, potentially accommodating different backend implementations or optimizations for specific use cases.

This GridDF class provides a robust foundation for implementing various types of grid-based simulations within the mesa_frames library, offering flexibility and efficiency in managing spatial aspects of agent-based models.