Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flocking behaviour #73

Merged
merged 7 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Flocking/Agents/Flocking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function flocking_agent_step!(bird, model)
match = separate = cohere = (0.0, 0.0)
for neighbor in neighbor_agents
N += 1
heading = neighbor.pos .- bird.pos
heading = get_direction(bird.pos, neighbor.pos, model)
cohere = cohere .+ heading
match = match .+ neighbor.vel
if sum(heading.^2) < bird.separation^2
Expand All @@ -48,7 +48,7 @@ function flocking_agent_step!(bird, model)
cohere = cohere .* bird.cohere_factor
separate = separate .* bird.separate_factor
match = match .* bird.match_factor
bird.vel = bird.vel .+ (cohere .+ separate .+ match) ./ N
bird.vel = bird.vel .+ (cohere .+ separate .+ match) ./ N
bird.vel = bird.vel ./ norm(bird.vel)
move_agent!(bird, model, bird.speed)
end
7 changes: 3 additions & 4 deletions Flocking/Mesa/boid.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ def step(self):
separation_vector -= heading
match_vector += neighbor.velocity
N = max(N, 1)
cohere = cohere / N * self.cohere_factor
cohere = cohere * self.cohere_factor
separation_vector = separation_vector * self.separate_factor
match_vector = match_vector / N * self.match_factor
#self.velocity = (self.velocity + cohere + separation_vector + match_vector) / 2
self.velocity += (cohere + separation_vector + match_vector) / 2
match_vector = match_vector * self.match_factor
self.velocity += (cohere + separation_vector + match_vector) / N
self.velocity /= np.linalg.norm(self.velocity)
new_pos = self.pos + self.velocity * self.speed
self.model.space.move_agent(self, new_pos)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ These are the results of the latest comparison:
|:------------------:|:---------------:|:------------:|:------------:|:---------------:|
| WolfSheep-small | 1 | 66.8x | 12.2x | 40.8x |
| WolfSheep-large | 1 | 21.3x | 8.3x | 28.5x |
| Flocking-small | 1 | 18.3x | 16.9x | 134.2x |
| Flocking-large | 1 | 3.2x | 18.5x | 108.1x |
| Flocking-small | 1 | 18.7x | 17.4x | 183.3x |
| Flocking-large | 1 | 3.1x | 19.8x | 209.7x |
| Schelling-small | 1 | 77.5x | 23.7x | 59.4x |
| Schelling-large | 1 | 6.9x | 32.8x | 68.4x |

Expand Down