Skip to content

Adds move_to_optimal function in DiscreteSpaceDF class #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
df26a23
test commit
suryanshgargbpgc Mar 11, 2025
7afe600
Added move_to function in DiscreteSpaceDF class
suryanshgargbpgc Mar 17, 2025
1d75987
Merge branch 'main' into optimizefunction
suryanshgargbpgc Mar 17, 2025
d26561e
Revert "test commit"
suryanshgargbpgc Mar 18, 2025
94daca7
moving type hint to types_ module
adamamer20 Mar 19, 2025
4bd0533
tests for move_to function
suryanshgargbpgc Mar 21, 2025
25e3baf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 21, 2025
4859e2c
Update test_grid_polars.py
suryanshgargbpgc Mar 21, 2025
a9d9e8f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 21, 2025
06ac4eb
Update test_grid_polars.py
suryanshgargbpgc Mar 22, 2025
ab6f845
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 22, 2025
fc6be7c
Update space.py
suryanshgargbpgc Mar 22, 2025
3f7c26d
Merge branch 'optimizefunction' of https://github.com/suryanshgargbpg…
suryanshgargbpgc Mar 22, 2025
002a5d9
Update space.py
suryanshgargbpgc Mar 22, 2025
08c927d
Update agents.py
suryanshgargbpgc Mar 22, 2025
ec10744
adds blank line
suryanshgargbpgc Mar 22, 2025
0747f98
Update test_grid_polars.py
suryanshgargbpgc Mar 22, 2025
8cd426b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 22, 2025
5b8f8db
adds tests for move_to_optimal
suryanshgargbpgc Mar 23, 2025
3d28340
Update test_grid_polars.py
suryanshgargbpgc Mar 23, 2025
20b3968
Revert "Update test_grid_polars.py"
suryanshgargbpgc Mar 23, 2025
3a2dc16
update test_grid_polars
suryanshgargbpgc Mar 23, 2025
891f296
resolve conflicts
suryanshgargbpgc Mar 23, 2025
04246e8
Fix whitespace in AgentSetPandas docstring
suryanshgargbpgc Mar 24, 2025
f278e56
Fix docstring conflict in _prepare_cells method with proper format
suryanshgargbpgc Mar 24, 2025
56fdabc
Merge branch 'main' into optimizefunction
suryanshgargbpgc Mar 24, 2025
efc65e7
Merge branch 'main' into optimizefunction
adamamer20 Mar 29, 2025
f437548
update agenets.py
suryanshgargbpgc Mar 30, 2025
90351ba
Merge upstream changes and resolve conflicts
suryanshgargbpgc Apr 15, 2025
02e49c2
Revert "Merge upstream changes and resolve conflicts"
suryanshgargbpgc Apr 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/sugarscape_ig/ss_polars/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def get_best_moves(self, neighborhood: pl.DataFrame):
)
return best_moves

# Resolved method with proper docstring
def _prepare_cells(
self, neighborhood: pl.DataFrame
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
Expand All @@ -286,7 +287,14 @@ def _prepare_cells(
Returns
-------
tuple[np.ndarray, np.ndarray, np.ndarray]

A tuple containing:
- occupied_cells: Array of currently occupied cell positions
- free_cells: Boolean array indicating which cells are free
- target_cells: Array of target cell positions for each agent

occupied_cells, free_cells, target_cells

"""
occupied_cells = (
neighborhood[["agent_id_center", "agent_order"]]
Expand Down
38 changes: 38 additions & 0 deletions mesa_frames/abstract/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,19 @@
"""
...

@abstractmethod
def move_to_optimal(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a complete docstring like you did for GridPolars

self,
attr_names: str | list[str],
rank_order: str | list[str] = "max",
radius: int | Series | None = None,
include_center: bool = True,
shuffle: bool = True,
inplace: bool = True,
) -> Self:
"""Move agents to optimal cells based on neighborhood ranking."""
...

Check warning on line 630 in mesa_frames/abstract/agents.py

View check run for this annotation

Codecov / codecov/patch

mesa_frames/abstract/agents.py#L630

Added line #L630 was not covered by tests

@property
def model(self) -> ModelDF:
"""The model that the AgentContainer belongs to.
Expand Down Expand Up @@ -1039,6 +1052,31 @@
def __reversed__(self) -> Iterator:
return reversed(self._agents)

def move_to_optimal(
self,
attr_names: str | list[str],
rank_order: str | list[str] = "max",
radius: int | Series | None = None,
include_center: bool = True,
shuffle: bool = True,
inplace: bool = True,
) -> Self:
"""Move all agent sets to optimal cells based on neighborhood ranking."""
obj = self._get_obj(inplace)

Check warning on line 1065 in mesa_frames/abstract/agents.py

View check run for this annotation

Codecov / codecov/patch

mesa_frames/abstract/agents.py#L1065

Added line #L1065 was not covered by tests

# Apply move_to_optimal to each agent set in the container
for agent_set in obj:
agent_set.move_to_optimal(

Check warning on line 1069 in mesa_frames/abstract/agents.py

View check run for this annotation

Codecov / codecov/patch

mesa_frames/abstract/agents.py#L1068-L1069

Added lines #L1068 - L1069 were not covered by tests
attr_names=attr_names,
rank_order=rank_order,
radius=radius,
include_center=include_center,
shuffle=shuffle,
inplace=True,
)

return obj

Check warning on line 1078 in mesa_frames/abstract/agents.py

View check run for this annotation

Codecov / codecov/patch

mesa_frames/abstract/agents.py#L1078

Added line #L1078 was not covered by tests
Comment on lines +1068 to +1078
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, no actual implementation should go here becuase it's an abstract interface. remove it completely. For the AgentSet you should do the implementation for AgentSetPolars.


@property
def agents(self) -> DataFrame:
return self._agents
Expand Down
Loading