-
Notifications
You must be signed in to change notification settings - Fork 929
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
space: Let move_agent choose from multiple positions #1920
Conversation
@jackiekazil @tpike3 @Corvince @rht @wang-boyu @quaquel please review |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1920 +/- ##
==========================================
+ Coverage 77.53% 79.62% +2.08%
==========================================
Files 15 15
Lines 1015 1124 +109
Branches 221 244 +23
==========================================
+ Hits 787 895 +108
- Misses 197 198 +1
Partials 31 31 ☔ View full report in Codecov by Sentry. |
I definitely like this PR and this is something we should implement. |
One thing that could be done is to introduce this as a now function that is simply called "move" and at some time deprecate the other one. |
Good point, I also noticed this in testing. What if we check if it's a sequence of numbers (sequence of int/float)? That way it would catch lists coordinate input, but still allow multiple coordinates (which would be sequences of sequences). |
b2f4406
to
0e8e42f
Compare
Implemented in 0e8e42f. None of the test are now needed to be modified. We should still steer to inputting tuples, it's also type hinted that way. But that can be another effort. |
This can be quite slow for long lists of agents. Could we just check the first element? |
That sounds correct. Either the first element is just a number or another iterable. |
Implemented, all tests pass. We have to think about how to process empty lists of possible positions. Either:
|
Good question. My first instinct would say don't move but issue a warning. I guess most of the time something went wrong when trying to move to an empty list of cells, but crashing the program seems a bit harsh. |
Having thought about it a bit, let’s keep it this way for now. Before this PR, you where required to input a location and your agent would always move. Now, that’s still the case, only multiple is also allowed. If empty lists become an issue that we can’t solve in usage, we can revisit this. |
Still thinking about the empty lists case. Currently, if you think you might have no target locations, you have to check manually if this is the case: possible_positions = some_selection_function()
if possible_positions >= 1:
move_agent(agent, possible_positions) Advantages:
Disatvantages:
We could add a However, then we fundamentally change the behavior of Another solution could be just to create a new method for these cases, and leave |
I like the clarity of
|
- Add move_agent_to_one_of method thats tries to move the agent from a list of positions. - Implement selection criteria: 'random' for random selection and 'closest' for selecting the nearest position. - Include error handling for invalid selection methods. - Optimize distance calculations using squared Euclidean distance, considering toroidal grid adjustments. - Update tests in TestSingleGrid to cover new move_agent functionalities, including tests for random and closest selection and handling of invalid selection methods.
Allow move_agent_to_one_of to handle an empty list by either passing silently (default), throwing an warning or an error.
Fully refactored the PR. There is now a new method Random is the default selection method and by default, empty lists are allowed. You can optionally enable warnings or errors on empty list input. Curious what everybody thinks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an example that demonstrates this functionality change beyond the testing?
(I am thinking of how people discover this.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @EwoutH
@jackiekazil I can add this to the CE tutorial. @EwoutH if you want to add examples to the |
Thanks for merging! Also nice to see that we can have critical discussions and still keep a certain velocity. It feels like a nice balance and flow in general. Agreed on the examples. I will try to rebase #1898 soon after Christmas. And then I think we can have an amazing release to start 2024! Have a great Christmas everyone! |
This PR enables the
move_agent
method to take a list of potential positions and offering two selection strategies: random and closest.This allows any subset of potential positions to be inputted, like an neighborhood, list of empty cells, etc.
Furthermore, it will help with #1898 when cells are selected based on properties.
New features
Flexible Position Handling: The
move_agent
method can now accept a single position or a list of possible positions for agent movement.Selection Strategies:
random
: Selects a position randomly from the provided list.closest
: Chooses the position closest to the agent's current location. In case of ties, a position is selected randomly from the closest ones.Usage examples
Moving to a Random Position:
Moving to the Closest Position:
Limitations