I tried replicating the results of social distancing example in Agents.jl Example Zoo. And the agents (balls) moved faster and faster in the output video. I was using Julia 1.8.0-rc3 (I’ve tried Julia 1.7.3, but the results were the same.)
using Agents
using Random
using InteractiveDynamics
using CairoMakie
mutable struct Ball <: AbstractAgent
id::Int # Mandatory Agent identifier
pos::NTuple{2,Float64} # Position, required for agents in the ContinuousSpace
vel::NTuple{2,Float64} # Moving speeds
mass::Float64 # Can move or not
end
function ball_model(; speed = 0.002, seed = 42)
space2d = ContinuousSpace((1, 1); spacing = 0.02)
model = ABM(Ball, space2d, properties = Dict(:dt => 1.0), rng = MersenneTwister(seed))
# Add agents to the model
for i in 1:500
pos = Tuple(rand(model.rng, 2))
vel =sincos(2π * rand(model.rng)) .* speed
mass = 1.0
add_agent!(pos, model, vel, mass)
end
return model
end
agent_step!(agent, model) = move_agent!(agent, model, model.dt)
# Billiard-like interaction
function model_step!(model)
for (a1, a2) in interacting_pairs(model, 0.012, :nearest)
elastic_collision!(a1, a2, :mass)
end
end
model2 = ball_model()
abmvideo(
"socialdist2.mp4",
model2,
agent_step!,
model_step!;
title = "Billiard-like",
frames = 50,
spf = 2,
framerate = 25,
)
Package version
[46ada45e] Agents v5.4.2
[13f3f980] CairoMakie v0.8.12
[a93c6f00] DataFrames v1.3.4
[31c24e10] Distributions v0.25.66
[86223c79] Graphs v1.7.1
[ec714cd0] InteractiveDynamics v0.21.10