I am playing with the Agents.jl Flocking example here (Flocking model · Agents.jl). I would like to add a new agent and kill the oldest agent every time step. I can kill an agent by including
age::Int
as a property of Bird and the following inside the function agent_step!
max_age=100
bird.age += 1
bird.age >= max_age && kill_agent!(bird, model)
I had thought the following would add a single new agent to a random position at each timestep:
n_steps = 10
model = initialize_model()
for t=1:n_steps
print(allids(model))
vel = Tuple(rand(2) * 2 .- 1)
add_agent!(
Tuple(rand(2) * 2 .- 1),
model,
vel,
speed,
cohere_factor,
separation,
separate_factor,
match_factor,
visual_distance,
age,
)
step!(model, agent_step!, 1)
end
But unfortunately it is adding one new agent and then doubling this number as can be seen with the output printed in the loop. i.e. If I start with 10 agents I will have 2*(10+1) in the next tilmestep etc.
I’m fairly new to Julia so this is possibly the wrong approach. Does anyone have any ideas?
Thank you for your time!