JuliaDynamics / ABMFrameworksComparison

Benchmarks and comparisons of leading ABM frameworks
Other
13 stars 8 forks source link

Use `random_nearby` in wolf sheep? #66

Open Datseris opened 1 year ago

Datseris commented 1 year ago

In Agents.jl we have spent considerable development effort optimizing functions that pick a "random nearby thing" but these aren't used here anywhere even though picking a "random nearby thing" is an extremely common ABM programming pattern.

Maybe we can use the random nearby in the wolf sheep model?

here: https://github.com/JuliaDynamics/ABM_Framework_Comparisons/blob/main/WolfSheep/Agents/WolfSheep.jl#L78

Tortar commented 1 year ago

Yes, indeed this is what I was referring to when I was saying that there is some other API calls to add there, but we need to add some new methods in Agents.jl before so, will do a pr there in a couple of days when I find the time!

Datseris commented 1 year ago

be careful though to only add API methods that are generally useful. We don't want to "cheat" and just add functions to Agents.jl API that would only be used in this comparison repo.

What is the method that is "missing" here?

Datseris commented 1 year ago

we already have filtering here: https://juliadynamics.github.io/Agents.jl/stable/api/#Agents.random_nearby_agent

Datseris commented 1 year ago

BTW this function seems to allocate the collection anyways: https://github.com/JuliaDynamics/Agents.jl/blob/main/src/core/space_interaction_API.jl#L414C30-L414C30

Which makes me think, how is it more performant than directly collecting the iterator and calling rand on it...?

Tortar commented 1 year ago

It is more performant since it doesn't test the condition on all the data, just on the part needed to find a value respecting the condition, some benchmarks we did saw some benefit doing that even for simple condition functions.

Yes, anyway I'm (almost) sure those functions will be beneficial for the users