I am trying to explore using Makie for some interactive applications and I have a hurdle that I am not sure how to get over. When following the tutorial for Schelling’s Segregation model on the Agents.jl page, Makie just creates a blank screen and then vanishes (picture attached). I am not sure how to debug the problem.
I am running Ubuntu 20.04 LTS with Julia 1.6.0.
Code
using Agents
using Random
using Statistics:mean
using InteractiveDynamics
using GLMakie
mutable struct SchellingAgent <: AbstractAgent
id::Int
pos::NTuple{2,Int}
mood::Bool
group::Int
end
function initialise(; numagents=320, griddims=(20, 20), min_to_be_happy=3, seed=125)
space = GridSpace(griddims, periodic=false)
properties = Dict(:min_to_be_happy => min_to_be_happy)
rng = Random.MersenneTwister(seed)
model = ABM(
SchellingAgent, space;
properties, rng, scheduler=Schedulers.randomly
)
for n in 1:numagents
agent = SchellingAgent(n, (1, 1), false, n < numagents / 2 ? 1 : 2)
add_agent_single!(agent, model)
end
return model
end
function agent_step!(agent, model)
minhappy = model.min_to_be_happy
count_neighbours_same_group = 0
for neighbour in nearby_agents(agent, model)
if agent.group == neighbour.group
count_neighbours_same_group += 1
end
end
if count_neighbours_same_group >= minhappy
agent.mood = true
else
move_agent_single!(agent, model)
end
return
end
x(agent) = agent.pos[1]
groupcolor(a) = a.group == 1 ? :blue : :orange
groupmarker(a) = a.group == 1 ? :circle : :rect
parange = Dict(:min_to_be_happy => 0:8)
adata = [(:mood, sum), (x, mean)]
alabels = ["happy", "avg. x"]
model = initialise(; numagents=300)
figure, adf, mdf = abm_data_exploration(
model, agent_step!, dummystep, parange;
ac=groupcolor, am=groupmarker, as=10,
adata, alabels
)