In Agents.jl the idea of agent_step!
and model_step!
functions are used. The former describes what a single agent should do each time step when they’re activated. The latter describes everything else that should happen in the model each time step. That’s why their function signatures are agent_step!(agent, model)
and model_step!(model)
respectively. The order by which agents are activated (i.e. do the thing inside your agent_step!
function) is determined by the scheduler function. Of course you can call your own agent_step! and model_step! functions whatever you want (like you already did in your code) but you should stick to the arguments they take in.
You’ve put Sardine
here instead of sardine
. Note the capital S
which references your agent type that you’ve defined at the beginning of the file. You want to use sardine
(or any other name for that argument) to reference an instance of Sardine
which is one of your agents. If you want to define that the reset_engaged
function can only be called with Sardine
agents, you can specify the type reset_engaged(sardine::Sardine, model)
.
- Make it
sardine_step(sardine, model)
- Consider moving
reset_engaged(model)
(or just its content, i.e. the for-loop) into yourevolve_model(model)
function. - Make it
adultspawn(sardine, model)
- Separate the sorting logic for
sorted_female
andsorted_males
from the actual agent stepping function. Thesorted_female
list should be your scheduler function (i.e. which agents get activated in which order) and thesorted_males
list could for example be stored as a model property that gets updated once per timestep inside theevolve_model
function. - Now that you’re scheduling according to your sorted list of adult females, you can remove the for-loop from inside the
adultspawn
function. This is now handled by Agents.jl in the background, so you don’t have to take care about looping over the set of agents anymore. - To first have your model reset the engaged status of your sardines, add the
agents_first
keyword argument to yourrun!
call:run!(model, sardine_step, evolve_model,100; adata, agents_first = false)
This now first executes yourevolve_model
function once and then yoursardine_step
function for each agent. See here in the documentation.
I probably forgot a few things but hopefully this information gets you started and helps you get your model running correctly. Feel free to share your progress on this and also feel free to ask if you have further questions.