# When to update agent property that depends on moves of all other agents

**URL:** <https://discourse.julialang.org/t/when-to-update-agent-property-that-depends-on-moves-of-all-other-agents/92695>\
**Category:** Modelling & Simulations\
**Tags:** agents\
**Created:** [January 9, 2023, 6:40am UTC](https://discourse.julialang.org/t/when-to-update-agent-property-that-depends-on-moves-of-all-other-agents/92695 "2023-01-09T06:40:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDA](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@SDA](https://discourse.julialang.org/u/SDA)\
**Post date:** [January 9, 2023, 6:40am UTC](https://discourse.julialang.org/t/when-to-update-agent-property-that-depends-on-moves-of-all-other-agents/92695/1 "2023-01-09T06:40:23Z")

</div>

Hi everyone,

I’m confused about how an agent property should be best updated within the `Agents.jl` package.

At each time step, each agent does some computation and then moves to a new location. The agent property should then be calculated (in this case the area of the agent’s Voronoi area). This necessarily depends on the moves of all other agents. I’m currently using the random scheduler but the same issue applies for other schedulers.

Given all agents need to have completed their move before the individual properties can be computed, how should I best gather this information?

Thank you for any discussion or helpful hints.

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [January 9, 2023, 11:11am UTC](https://discourse.julialang.org/t/when-to-update-agent-property-that-depends-on-moves-of-all-other-agents/92695/2 "2023-01-09T11:11:50Z")

</div>

Tell me if I’m not understanding your question, but `model_step!` will be called (by default) after you’ve completed you agent step computation?  
See, e.g.: [4. Evolving the model](https://juliadynamics.github.io/Agents.jl/stable/tutorial/#.-Evolving-the-model-1), and also the `Advanced Stepping` section there.

---

<div class="post-metadata">

**Author:** ![fbanning](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fbanning/32/14972_2.png) [@fbanning](https://discourse.julialang.org/u/fbanning)\
**Post date:** [January 9, 2023, 11:20am UTC](https://discourse.julialang.org/t/when-to-update-agent-property-that-depends-on-moves-of-all-other-agents/92695/3 "2023-01-09T11:20:25Z")

</div>

This is the correct approach.

You let your agents do their stuff (e.g. moving around) in your `agent_step!` function. Then you also add a `model_step!` function that iterates over your agents again (e.g. `for id in allids(model); calculate_voronoi(model[id]); end`) and you should be golden.

---

<div class="post-metadata">

**Author:** ![SDA](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@SDA](https://discourse.julialang.org/u/SDA)\
**Post date:** [January 10, 2023, 1:46am UTC](https://discourse.julialang.org/t/when-to-update-agent-property-that-depends-on-moves-of-all-other-agents/92695/5 "2023-01-10T01:46:36Z")

</div>

Thank you for your help and for the link. 🙂

---

<div class="post-metadata">

**Author:** ![SDA](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@SDA](https://discourse.julialang.org/u/SDA)\
**Post date:** [January 10, 2023, 1:47am UTC](https://discourse.julialang.org/t/when-to-update-agent-property-that-depends-on-moves-of-all-other-agents/92695/6 "2023-01-10T01:47:12Z")

</div>

Thank you very much for responding and putting me on the right path. Can I just check - am I able to update an agent property within the `model_step` function. Or is this something that should be collected as a model property. Say as a vector the size of the number of agents?

---

<div class="post-metadata">

**Author:** ![fbanning](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fbanning/32/14972_2.png) [@fbanning](https://discourse.julialang.org/u/fbanning)\
**Post date:** [January 10, 2023, 11:53am UTC](https://discourse.julialang.org/t/when-to-update-agent-property-that-depends-on-moves-of-all-other-agents/92695/7 "2023-01-10T11:53:30Z")

</div>

> [@SDA](#):
>
> am I able to update an agent property within the `model_step` function

Yes.
