This simple model in continuous space starts with one dead (immobile) object and 500 live (moving ) ones. If a live object gets close to a dead one, it dies. The result should be a growing pattern. The control panel shows, but the model does not run. Any ideas?
using Agents
using Random
xMax = 100
yMax = 100
extent = (xMax, yMax)
touchDist = 10
println( "Starting here ======================" )
@agent struct Thing( ContinuousAgent{ 2, Float64 } )
separation::Float64
alive::Bool
end
rng = Random.MersenneTwister()
function initialize_model(;
separation = touchDist,
alive = true, )
space2d = ContinuousSpace( extent; spacing = 1.0, periodic = false )
model = StandardABM( Thing, space2d;
rng,
agent_step!,
scheduler = Schedulers.Randomly() )
vel = SVector( -1, -1 )
for i = 1:501
newAgent = add_agent!( model, vel, touchDist, alive )
newAgent.pos = SVector( xMax/2, 1 )
end
model[ 1 ].pos = SVector( xMax/2, yMax/2 )
model[ 1 ].alive = false
return model
end
function agent_step!( thing, model )
if ( !thing.alive ) return
end
nums = rand( rng ) * 360
dx = cosd( nums )
dy = sind( nums )
newX::Float64 = thing.pos[ 1 ] + dx
newY::Float64 = thing.pos[ 2 ] + dy
if ( newX < 1 ) newX = xMax end
if ( newX > xMax ) newX = 1 end
if ( newY < 1 ) newY = yMax end
if ( newY > yMax ) newY = 1 end
thing.pos = SVector( newX, newY )
move_agent!( thing, thing.pos, model )
nextThing = nearest_neighbor(thing, model::ABM{<:ContinuousSpace}, touchDist ) → nearest
if( ( nextThing = !isnothing ) && ( !nextThing.alive ) )
thing.alive = false
end
end
using GLMakie
model = initialize_model()
plotkwargs = (;
agent_marker = :circle,
agent_color = :red,
agent_size = 12
)
fig, ax, abmobs = abmplot( model; add_controls = true, plotkwargs...)
fig