-
Notifications
You must be signed in to change notification settings - Fork 944
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
bug in ContinuousSpace.get_neighbors #2592
Comments
Upon looking at code I found that it is impossible to find the agent which is passed in the method, because you are passing the position, and since every agent has the same position, if you try to remove the so called current agent, you will have to remove a random one or none at all. To maybe overcome this one can change the type of the Can something like this work? if isinstance(pos, Agent):
self.current_agent = pos
pos = pos.pos
else:
self.current_agent = None
...
neighbors = [
self._index_to_agent[x] for x in idxs
]
if not self.current_agent:
return neighbors
else:
neighbors.remove(self.current_agent)
return neighbors |
You are absolutely right that this bug cannot be fixed inside the method as it currently stands. However, changing the method signature is a breaking change and could have a profound impact on existing models. So, that is not an ideal solution. Practically speaking, with #2584 almost ready to go, I am thinking of the following
|
# returns no agents, should return agent2
space.get_neighbors(agent1.pos, radius=1, include_center I don't think I agree this is unintended behavior. The argument is called That said, it might be helpful to have an include/exclude self argument. We could add that to the new API. |
Let's agree to disagree. The documentation just clarifies the behavior even more.
The problem cannot occur there because I draw a sharp distinction between getting agents from a space and getting neighbors from an agent. |
Describe the bug
Currently,
get_neighbors
will fail to identify neighbors if two agents occupy the exact same position.The line that causes the issue is shown below. if
include_center
isTrue
, this will return all agents on the position. If ifinclude_center
isFalse
, it will return no agents. However, in case of 2 agents on the same location, neither is correct.Expected behavior
Return any neighbors that are not the agent for which you are calling
get_neighbors
.To Reproduce
Create a space with 2 agents in the same location and call get_neighbors with the position of either agent.
The text was updated successfully, but these errors were encountered: