Skip to content

Commit

Permalink
Update multiagent_vs_union.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Aug 9, 2024
1 parent 7a1a11b commit c588c7c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/performance/multiagent_vs_union.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,31 +93,31 @@ end

################### DEFINITION 2 ###############

agent_step!(agent, model2) = agent_step!(agent, model2, variant(agent))
@inline agent_step!(agent, model2) = agent_step!(agent, model2, variant(agent))

agent_step!(agent, model2, ::GridAgentOne) = randomwalk!(agent, model2)
function agent_step!(agent, model2, ::GridAgentTwo)
@inline agent_step!(agent, model2, ::GridAgentOne) = randomwalk!(agent, model2)
@inline function agent_step!(agent, model2, ::GridAgentTwo)
agent.one += rand(abmrng(model2))
agent.two = rand(abmrng(model2), Bool)
end
function agent_step!(agent, model2, ::GridAgentThree)
@inline function agent_step!(agent, model2, ::GridAgentThree)
if any(a-> variant(a) isa GridAgentTwo, nearby_agents(agent, model2))
agent.two = true
randomwalk!(agent, model2)
end
end
function agent_step!(agent, model2, ::GridAgentFour)
@inline function agent_step!(agent, model2, ::GridAgentFour)
agent.one += sum(a.one for a in nearby_agents(agent, model2))
end
function agent_step!(agent, model2, ::GridAgentFive)
@inline function agent_step!(agent, model2, ::GridAgentFive)
targets = filter!(a->a.one > 1.0, collect(GridAgentAll, 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, ::GridAgentSix)
@inline function agent_step!(agent, model2, ::GridAgentSix)
agent.eight += sum(rand(abmrng(model2), (0, 1)) for a in nearby_agents(agent, model2))
end

Expand Down

0 comments on commit c588c7c

Please sign in to comment.