mdata = [:Social] returns the same graph over and over without updating, I can’t seem to find the reason, any ideas?
From what you’ve posted it seems as if you only create your graph once and never change it. Do you ever update
model.Social during your
Of course we don’t know what your use case/model purpose is, so this is a bit of a wild guess but are you sure you want to use a
GridSpace and then create a graph from the present agents? Perhaps look at our SIR example to see how you can directly use a
Please note that reading code on screenshots is a bit unpleasant. You might want to consider using backticks
`` to fence your code and allow for nice formatting like this:
using Agents model = create_model(; dims=(L,L), density) # and so on
Welcome! To make it easer to help you, please consult this short post with some tips & tricks:
I will fence from now on, thanks for the tip!
I do update model.Social, but I do this during the agent_step!
This is another thing I am confused about, as far as I understand you can only have
run!(model,agent_step!,model_step!,etc...), but I need something like
(model,agent_step1!,model_step1!,agent_step2!,model_step2!,etc...), this is just the way my model needs to be updated. Regarding the use of`
GraphSpace, I don’t need the agents walking over a network per-say, but rather a grid torus topology, then I construct social networks based on some other criterion. Anyways the code that updates model.Social is here:
for i = 1:numagents for j = 1:numagents if i==j continue else add_edge!(model.Social, i, j, (model[i].probability + model[j].probability) * (1-abs(model[j].probability-model[i].probability))/2) end end end end
Note that i’ve fixed the issue by including
obtainer = copy at the end of my
run!(), I saw someone having similar trouble and this seemed to be the trick, but is this the best solution? Sorry I am new to using agents / julia and I’m still figuring things out, thanks for the advice!
This can be easily done if you implement your
agent_step! logic inside the
model_step! function. Just iterate over the agents (or a subset) in whichever way you like: either by using a predefined scheduler from the
Schedulers submodule or by simply defining your own iteration specifications. Something like this:
function model_step!(model) for agent in allagents(model) agent.variable += rand() end model.variable = mean(agent.variable for agent in allagents(model)) for agent in allagents(model) agent.variable2 = agent.variable / model.variable end end
For reference, see Tutorial · Agents.jl.
From the docs of
obtainer = identity: method to transfer collected data to the
DataFrame. Typically only change this to
copyif some data are mutable containers (e.g.
Vector) which change during evolution, or
deepcopyif some data are nested mutable containers. Both of these options have performance penalties.
So yes, I think this is the correct approach. Note that I haven’t faced a case like yours yet, so I’m not totally sure if there are other or even better ways to do it.
This lightgraphs integration example in the docs may also help you out.
I suppose I will be doing a lot of testing and might end up preprocessing the data to avoid the performance penalties attributed to using
obtainer = copy. Thanks for your speedy replies @fbanning, I’m writing my masters thesis (coding it all in Julia), so I’m sure you will see me on the forums again haha…