Skip to content

bug in ContinuousSpace.get_neighbors #2592

@quaquel

Description

@quaquel

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 is True, this will return all agents on the position. If if include_center is False, it will return no agents. However, in case of 2 agents on the same location, neither is correct.

        neighbors = [
            self._index_to_agent[x] for x in idxs if include_center or dists[x] > 0
        ]

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.

model = Model(seed=42)
space = ContinuousSpace(1, 1, torus=False)
agent1 = Agent(model)
space.place_agent(agent1, (0.5, 0.5))

agent2 = Agent(model)
space.place_agent(agent2, (0.5, 0.5))

# returns no agents, should return agent2
space.get_neighbors(agent1.pos, radius=1, include_center=False)

# returns both agents, should return only agent2
space.get_neighbors(agent1.pos, radius=1, include_center=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugRelease notes label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions