# Agent Based Modeling in Julia

**URL:** <https://discourse.julialang.org/t/agent-based-modeling-in-julia/12431>\
**Category:** New to Julia\
**Created:** [July 17, 2018, 11:07am UTC](https://discourse.julialang.org/t/agent-based-modeling-in-julia/12431 "2018-07-17T11:07:50Z")\
**Posts on this page:** 8\
**Page:** 3

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [July 14, 2019, 12:43pm UTC](https://discourse.julialang.org/t/agent-based-modeling-in-julia/12431/41 "2019-07-14T12:43:44Z")

</div>

@bkamins Are you aware of the package [Agents.jl](https://github.com/kavir1698/Agents.jl) ?

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [July 14, 2019, 1:01pm UTC](https://discourse.julialang.org/t/agent-based-modeling-in-julia/12431/42 "2019-07-14T13:01:04Z")

</div>

Yes, I am aware of it, but this package was started in Nov 2018, and this thread is from Aug 2018 😄.

This is a very nice package (I especially like that it has a full modelling and analysis workflow inbuilt).

However, the problem of dynamic dispatch is still there. Take e.g. an example from the docs:

```julia
mutable struct SchellingModel <: AbstractModel # A model object should always be a subtype of AbstractModel
 space::AbstractSpace # A space object, which is a field of the model object is always subtype of AbstractSpace
 agents::Array{AbstractAgent} # a list of agents
 scheduler::Function
 min_to_be_happy::Integer # minimum number of neighbors to be of the same kind so that they are happy
end

```

And you see that you will have dynamic dispatch any time you access `space` and `scheduler` variables or when you access elements of `agents` array.

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [July 14, 2019, 1:17pm UTC](https://discourse.julialang.org/t/agent-based-modeling-in-julia/12431/43 "2019-07-14T13:17:37Z")

</div>

Do you see any way to overcome this problem?  
I am going to do an ABM for my PhD and normally I will use `NetLogo`and `R`but I wanted to try to use `Julia` even if there is no good GUI to show the simulation. The problem is that this package is so new that using it is risky. Maybe I should try both tools in parallel.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [July 14, 2019, 2:47pm UTC](https://discourse.julialang.org/t/agent-based-modeling-in-julia/12431/44 "2019-07-14T14:47:10Z")

</div>

I can see that [@kavir](https://github.com/kavir1698) actively maintains it so I think you should get response to your potential problems pretty fast. The “dynamic dispatch” issue is really a problem in very special cases - most of the time it should be OK.

Also if you run into something problematic that you have problem solving you can always ask on Discourse and most likely get some advice really fast.

---

<div class="post-metadata">

**Author:** ![mhinsch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mhinsch/32/26676_2.png) [@mhinsch](https://discourse.julialang.org/u/mhinsch)\
**Post date:** [July 16, 2019, 7:08am UTC](https://discourse.julialang.org/t/agent-based-modeling-in-julia/12431/45 "2019-07-16T07:08:28Z")

</div>

Have a look at [this](https://discourse.julialang.org/t/speed-of-dispatch-with-heterogeneous-functions-and-types/26282) discussion. I have been worried about the same problem but according to the benchmark (see link in the first post of the linked discussion) it’s actually not that terrible as soon as your methods are non-trivial.

---

<div class="post-metadata">

**Author:** ![Ali\_Vahdati](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ali_vahdati/32/38715_2.png) [@Ali\_Vahdati](https://discourse.julialang.org/u/Ali_Vahdati)\
**Post date:** [July 16, 2019, 8:49am UTC](https://discourse.julialang.org/t/agent-based-modeling-in-julia/12431/46 "2019-07-16T08:49:50Z")

</div>

Hi and thanks. Just to clarify, dynamic dispatch can happen only when you access the `agents` array. The `space` object contains an array of numbers representing agent positions. So it doesn’t matter whether there are multiple agents or not. As for the `scheduler`, its only reference to the list of agents is getting their length. I am not sure, but I don’t think getting the length of an `Any` array is slower than a fixed-type array.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [July 16, 2019, 10:46am UTC](https://discourse.julialang.org/t/agent-based-modeling-in-julia/12431/47 "2019-07-16T10:46:32Z")

</div>

Hi - this is what I meant (i.e. that there is “some dynamic dispatch”, but most likely it is not a problem in typical cases). Thank you 😄.

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [December 9, 2019, 11:32am UTC](https://discourse.julialang.org/t/agent-based-modeling-in-julia/12431/48 "2019-12-09T11:32:20Z")

</div>

We have updated Agents.jl to version 2.0. It is faster, simpler, more consice and more extendable. We hope that it can now become the standard for agent-based modelling in Julia.

For details: Agents.jl is now in version 2.0, with a massively more simplified API. See [Agents.jl : Agent based modelling](https://discourse.julialang.org/t/agents-jl-agent-based-modelling/32043)

[Previous page](https://discourse.julialang.org/t/agent-based-modeling-in-julia/12431.md?page=2)
