ABM - Scheduler.bytype just for 1 agent function

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).

  1. Make it sardine_step(sardine, model)
  2. Consider moving reset_engaged(model) (or just its content, i.e. the for-loop) into your evolve_model(model) function.
  3. Make it adultspawn(sardine, model)
  4. Separate the sorting logic for sorted_female and sorted_males from the actual agent stepping function. The sorted_female list should be your scheduler function (i.e. which agents get activated in which order) and the sorted_males list could for example be stored as a model property that gets updated once per timestep inside the evolve_model function.
  5. 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.
  6. To first have your model reset the engaged status of your sardines, add the agents_first keyword argument to your run! call: run!(model, sardine_step, evolve_model,100; adata, agents_first = false) This now first executes your evolve_model function once and then your sardine_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.

2 Likes