Agents Based Modeling (using Agents.jl)

I am trying to use Agents.jl package to model my system. I use the following code

using Agents
using LightGraphs
using Distributions

mutable struct MyAgent{T<:Integer,Y<:AbstractFloat} <: AbstractAgent
    id::T ;
    pos::Y ; 
    W::Y ; 
end

mutable struct MyNet{T<:Integer,Y<:AbstractArray} <: AbstractSpace
    dimensions::T ; 
    space::SimpleDiGraph{Int64} ; 
    agent_positions::Y ;
end

mutable struct MyModel{T<:AbstractArray,Y<:AbstractFloat,Z<:AbstractSpace} <: AbstractModel
    space::Z ; 
    agents::T ;
    scheduler::Function ; 
    activation_prob::Y ; 
    interaction_prob::Y ; 
end
function instantiate_model(;num_agents,mean,sd,out_deg,prob_rew,prob_up,prob_int)
    agents = [MyAgent(i,rand(Normal(mean,sd))*pi/180,rand(Uniform(0.5,0.9))) for i in 1:num_agents] ;
    ntwk = MyNet(num_agents,watts_strogatz(num_agents,out_deg,prob_rew,is_directed=true),collect(1:num_agents)) ;
    model = MyModel(ntwk,agents,partial_activation,prob_up,prob_int) ;
    return model
end

function agent_step!(agent::AbstractAgent,model::AbstractModel)
agent.pos = agent.pos + agent[rand].pos ;
end

I want to make sure that the quantities used on the RHS agent[rand].pos are all from [t-1] time step. On using the step!(agent_step!,model) function, this is not possible as everything inside agent_step! gets executed, updated and no exceptions can be made. How can I have a copy of values of agent.pos from [t-1] ?

Agents.jl is now in version 2.0, with a massively more simplified API. See Agents.jl : Agent based modelling

1 Like

It is a bit late reply. You need to specify a “model_step!” function, instead of an agent_step! to achieve your goal. In a model step function, you define what happens to the model in a single time step. So you can create an array of all agent positions, then update the positions from that array.

The forest fire example in the documentations uses a model step function.

Make sure to check the version 2 of Agents.jl, building the model and collecting data is much simpler now.

1 Like

hi, this link no longer works. Could you please resend it…

Check this page for all the example models, including forest fire.

1 Like

thank you so much. Have you ever tried modelling the vacuum problem in Julia? I am very new to Julia and AI and have no idea how to solve my problem.

Hi,

As a newbie for Julia too, and a new user of Agents.jl, I believe it would be beneficial if you tag the question with “agents” under modeling and simulation category, otherwise potential interested members of the community may not be notified.

No, not this specific model and I don’t know the problem either. I would read through the tutorial section first. Then if you have specific questions, such as how to write a specific behavior or how to design a specific model, people will be able to help.

1 Like