Hi I am new to Agents.jl and Julia, I am following the official online tutorial on the Shelling’s model, however I am facing a hard time with the step! function, I tried to use the same source code as in the tutorial but I always get an Error from the stepping function and a warning(see image below). Note that the custom step function I created works fine I tested it in the REPL, and also when I use step!(model, n=5) I get MethodError.
I really appreciate your help and time.
using Agents
mutable struct Schelling <: AbstractAgent
id::Int
pos::Tuple{Int,Int}
group::Int
happy::Bool
end
function agent_step!(agent,model,)
#println("checking agent: ",agent.id)
#println("Happy: ",agent.happy)
if agent.happy == true
println("I am happy")
return
end
nearby_same = 0
for neighbor in nearby_agents(agent,model)
println("nearby_same: ",nearby_same," neighbor: ",neighbor.id," neighbor group: ",neighbor.group)
if neighbor.group == agent.group
nearby_same += 1
end
end
if nearby_same >= model.min_to_be_happy
println("nearby_same:00 ",nearby_same)
agent.happy = true
else
move_agent_single!(agent,model)
println("jumped to: ",agent.pos)
end
return
end
function initilize(;N = 10, M = 4, min_to_be_happy = 2,steppingFunction = agent_step!)
space = GridSpace((M,M))
properties = Dict(:min_to_be_happy => min_to_be_happy)
scheduler = Schedulers.Randomly
model = AgentBasedModel(Schelling,space;properties = properties, scheduler = scheduler,agent_step! = steppingFunction)
for n in 1:N
agent = Schelling(n,(1,1),n < N/2 ? 1 : 2,false)
add_agent_single!(agent,model) #This adds agents at a random and empty location in the space
end
return model
end
model = initilize()
step!(model,agent_step!,dummystep)
And here is the warning I face:
┌ Warning: Passing agent_step! and model_step! to step! is deprecated. Use
the new version
│ step!(model, n = 1, agents_first = true)
The Error:
ERROR: MethodError: Cannot `convert` an object of type StandardABM{GridSpace{2, true}, Schelling, Dict{Int64, Schelling}, Tuple{DataType}, typeof(agent_step!), typeof(dummystep), DataType, Dict{Symbol, Int64}, Random.TaskLocalRNG} to an object of type Vector{Int64}