Method Error object of type AgentBasedModel is not callable

Hi I am having the following error when I call the step!() or abmvideo!() functions and not sure what the cause of it is. Any ideas?

ERROR: MethodError: objects of type AgentBasedModel{Agents.OSM.OpenStreetMapSpace, Union{Casualty, Hospital, PMA, Rescuer}, typeof(Agents.Schedulers.fastest), Dict{Symbol, Real}, Random.TaskLocalRNG} are not callable
Stacktrace:
 [1] step!(model::AgentBasedModel{Agents.OSM.OpenStreetMapSpace, Union{Casualty, Hospital, PMA, Rescuer}, typeof(Agents.Schedulers.fastest), Dict{Symbol, Real}, Random.TaskLocalRNG}, agent_step!::AgentBasedModel{Agents.OSM.OpenStreetMapSpace, Union{Casualty, Hospital, PMA, Rescuer}, typeof(Agents.Schedulers.fastest), Dict{Symbol, Real}, Random.TaskLocalRNG}, model_step!::typeof(dummystep), n::Int64, agents_first::Bool)
   @ Agents ~/.julia/packages/Agents/nnELw/src/simulations/step.jl:55
 [2] step! (repeats 2 times)
   @ ~/.julia/packages/Agents/nnELw/src/simulations/step.jl:45 [inlined]
 [3] top-level scope
   @ ~/github/CRTT-lite/crtt_lite_osm.jl:234

— Part of the code —

#Initialisation
begin
    include("agent_types.jl")
    include("vis_agents.jl")
    using .Agent_Types: Casualty, Rescuer, PMA, Hospital
    using .Vis_Agents: agent_color, agent_markers, agent_size
end

function initialise(;map_path=OSM.test_map(),num_casualties, num_rescuers, num_pma, num_hospitals, properties)
    model = AgentBasedModel(
        Union{Casualty, Rescuer,PMA,Hospital},
        OpenStreetMapSpace(map_path),
        scheduler = Schedulers.fastest;
        properties = properties
    )
    # Add casualties to Model
    for i=1:num_casualties
        pos = random_position(model)
        casualty = Casualty(nextid(model),pos,trauma = rand([1,2,3]))
        add_agent_pos!(casualty,model)
    end
    
    #Add Rescuers to Model 
    for i=1:num_rescuers
        init_pos=(775,775,0.0)
        rescuer=Rescuer(nextid(model),init_pos) 
        add_agent_pos!(rescuer,model)
    end

    # Add other agents (PMA,Hospital) ...


    return model
end

#agent step functions

@doc "Return casualties/rescuers by their boolean attributes only" ->
function agent_by_property(model::ABM, agent_type::DataType, prop::Symbol, prop_value::Bool)::Union{Vector{Casualty}, Vector{Rescuer}}
    if prop_value
        return [model[id] for id in 1:length(model.agents) if model[id] isa agent_type && getproperty(model[id], prop)]
    else
        return [model[id] for id in 1:length(model.agents) if model[id] isa agent_type && !getproperty(model[id], prop)]
    end
end

# Updating agent attributes
@doc "Update agent attributes" ->
function update_agent_attributes!(agent::Union{Casualty,Rescuer},attr::Dict{Symbol,T}) where T <: Any
    for (k,v) in attr
        setfield!(agent,k,v)
    end 
end

# Assigns casualties to each rescuer "awaiting instructions"
@doc "Rescuers : awaiting_instructions, locate casualties" ->
function find_casualties!(agent,model)
    # Locate a random casualty who is awaiting rescue
    casualty_to_be_rescued = agent_by_property(model, Casualty, :awaiting_rescue, true) |> rand
    # Update rescuer attributes
    rescuer_attributes = Dict(
        :travel_to => casualty_to_be_rescued.id, 
        :destination => casualty_to_be_rescued.pos,
        :awaiting_instructions => false,
        :rescuing_in_progress => true
    )
    update_agent_attributes!(agent, rescuer_attributes)
    # update casualty attributes
    casualty_to_be_rescued_attributes = Dict(
        :awaiting_rescue => false,
        :rescued_by => agent.id
    )
    update_agent_attributes!(casualty_to_be_rescued, casualty_to_be_rescued_attributes)
end

function go2!()
    for (id,agent) in model.agents
        # Are there any casualties to be rescued
        any_to_be_rescued = filter(x -> x isa Casualty && x.awaiting_rescue == true, model.agents |> values |> collect)
        # Rescuers : awaiting_instructions --> find_casualties
        if (agent isa Rescuer) && (agent.awaiting_instructions) && length(any_to_be_rescued) > 0
            find_casualties!(agent,model)
        end

    end
    return model
end
step!(
    model,
    go2!(),
    1
)

ERROR: MethodError: objects of type AgentBasedModel{Agents.OSM.OpenStreetMapSpace, Union{Casualty, Hospital, PMA, Rescuer}, typeof(Agents.Schedulers.fastest), Dict{Symbol, Real}, Random.TaskLocalRNG} are not callable
Stacktrace:

Without having a closer look at your code

should probably be function go2!(model).

should probably be step!(model, dummystep, go2!, 1).

2 Likes

Yeap, these are standard Julia syntax mistakes, not really related with Agents.jl. go2!() returns a model. BTW thanks a lot @fbanning for being around and answering questions about Agents.jl here!

1 Like