Comments (8)
This is great. This is truly great. The only thing we need to make sure is that add_agent!
plays well with it and works as expected, so that
add_agent!(Wolf, only_wolf_fields...)
does what it should and initializes an Animal with correct id, pos, and type
.
SHould we add this option for v6, or you want to do it later? The benefit of doing it at v6 would be that this rather important perforamnce feature would be included in the v6 announcement post.
from agents.jl.
You are right, this doesn't totally resolve the multi-agent "problem". But it gives a very important option of having only one agent type. I think in the majority of use cases this option would have performance gains.
from agents.jl.
It would be cool to have this in v6 I agree, but it needs some more work, so I don't promise to finish it up in the very near future :D
from agents.jl.
This looks great. Haven't tried to clone the branch for testing, but if Wolf
and Hawk
are not defined as types, does this mean that instead of dispatching as f(::Wolf)
and f(::Hawk)
one would always need to check against Animal.type
following a structure of the form f(a::Animal) = a.type == :hawk ? f_hawk(a) : f_wolf(a)
?
I wonder, if it would make sense to dispatch on the value of type
? E.g. f(::Val{:hawk})
, f(::Val{:wolf})
... I'm a bit clueless here, would this have negative performance impacts?
from agents.jl.
I know you like macros @mastrof :D
I think that it is an interesting idea, it will costs more because this is dynamic dispatch vs branching and branching wins, but in reality the real perf benefit here is to avoid abstract containers, so it will not change much adding that for only agent_step!, I will try it out on the benchmark I re-setuped for testing the macro on the PR.
from agents.jl.
tried:
Seems fine to me
branching:
561.657 ms (23076750 allocations: 1001.82 MiB)
with Val
589.242 ms (23076750 allocations: 1001.82 MiB)
(Referring to branching_faster_than_dispatch.jl
file)
Mod Version:
function agent_step!(agent::GridAgentAll, model2)
agent_step!(agent, model2, Val(agent.type))
end
agent_step!(agent, model2, ::Val{:gridagentone}) = randomwalk!(agent, model2)
function agent_step!(agent, model2, ::Val{:gridagenttwo})
agent.one += rand(abmrng(model2))
agent.two = rand(abmrng(model2), Bool)
end
function agent_step!(agent, model2, ::Val{:gridagentthree})
if any(a-> a.type == :gridagenttwo, nearby_agents(agent, model2))
agent.two = true
randomwalk!(agent, model2)
end
end
function agent_step!(agent, model2, ::Val{:gridagentfour})
agent.one += sum(a.one for a in nearby_agents(agent, model2))
end
function agent_step!(agent, model2, ::Val{:gridagentfive})
targets = filter!(a->a.one > 1.0, collect(nearby_agents(agent, model2, 3)))
if !isempty(targets)
idx = argmax(map(t->euclidean_distance(agent, t, model2), targets))
farthest = targets[idx]
walk!(agent, sign.(farthest.pos .- agent.pos), model2)
end
end
function agent_step!(agent, model2, ::Val{:gridagentsix})
agent.eight += sum(rand(abmrng(model2), (0, 1)) for a in nearby_agents(agent, model2))
end
from agents.jl.
But if you do something like this inside the step itself I expect it will have a noticeable impact on performance
from agents.jl.
Actually I created a package which does more than what it is described here and it could allow memory efficiency to approach the one of multiple types in many cases! It is at https://github.com/Tortar/MixedStructTypes.jl if you want to take a look
from agents.jl.
Related Issues (20)
- Changelog for v6 needs a dedcated deprecations section
- New DevDoc entry for making new ABM types HOT 2
- Models.jl removed from main in current build? HOT 6
- Discuss redefining agent types in the docs
- "MethodError: no method matching..." with default agent attribute values. HOT 1
- Bugs due to Makie 0.20 update HOT 1
- [DOCS] add multithreading discussion in performance tips HOT 3
- `@multiagent` doesn't work when agents have no extra properties HOT 1
- [docs] Missing heading? HOT 1
- Scheduler equivalent to `ByType` but for `@multiagent` models. HOT 1
- Make `EventQueueABM` work with `Union` types HOT 7
- `random_nearby_position()` might return out-of-bounds positions HOT 3
- Can the open street map graph be altered during the simulation? HOT 8
- SIR video is completely white HOT 1
- Agents.jl examples plot in the highlight section should be regenerated HOT 1
- `abmplot` fails when 1) number of agents changes over time and 2) custom `agent_size` function is used HOT 11
- Does EventQueueABM require @multiagent? HOT 1
- BoundsError when inspecting agents in 3D visualisation
- Conflict between nearest_neighbor() function and euclidean distance for agent pair. HOT 6
- Flocking model video doesn't work after update to Makie 0.21 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from agents.jl.