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]
?