JuliaDynamics/Agents.jl

add_agent!() adds agents with out-of-bounds coordinates despite BoundsError

オープン

#1,193 opened on 2026/01/13

 (2 件のコメント) (0 件のリアクション) (0 人の担当者)Julia (146 件のフォーク)batch import
bugdiscretegood first issue

Repository metrics

Stars
 (904 個のスター)
PR merge metrics
 (平均マージ 1d 7h) (30d で 4 merged PRs)

説明

Describe the bug When add_agent!() is called with out-of-bounds coordinates on a GridSpace, it throws a BoundsError but still adds the agent to the model's dictionary. This creates an inconsistent state where the agent exists in the model but it has an invalid position. Functions such as nearby_ids() do not return this agent's id. I have not tested with other functions though.

Minimal Working Example

using Agents

@agent struct Customer(GridAgent{2}) 
    age
end

space = GridSpace((100,100); periodic = false, metric = :euclidean)
model = StandardABM(Customer, space)
add_agent!((0,0), model,25) #similar behavior when using negative coordinates

Output:

BoundsError: attempt to access 100×100 Matrix{Vector{Int64}} at index [0, 0]

However when checking the agents in the model the agent has been added

allagents(model)

Output:

ValueIterator for a Dict{Int64, Customer} with 1 entry. Values:
  Customer(1, (0, 0), 25)

Agents.jl version

Agents v6.2.10

コントリビューターガイド