From 5178fa19b14ccfa1a4937d4eb0a9d3d0317b35c1 Mon Sep 17 00:00:00 2001 From: Tortar <68152031+Tortar@users.noreply.github.com> Date: Wed, 20 Sep 2023 22:25:03 +0200 Subject: [PATCH 1/7] Fix flocking behaviour --- Flocking/Agents/Flocking.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flocking/Agents/Flocking.jl b/Flocking/Agents/Flocking.jl index f7ae0ee3..72c5b8ea 100755 --- a/Flocking/Agents/Flocking.jl +++ b/Flocking/Agents/Flocking.jl @@ -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 From 5213f5d3d1175565e6a963b6af3cf15d760232bb Mon Sep 17 00:00:00 2001 From: Tortar <68152031+Tortar@users.noreply.github.com> Date: Wed, 20 Sep 2023 22:26:53 +0200 Subject: [PATCH 2/7] Update Flocking.jl --- Flocking/Agents/Flocking.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flocking/Agents/Flocking.jl b/Flocking/Agents/Flocking.jl index 72c5b8ea..dc4a35f9 100755 --- a/Flocking/Agents/Flocking.jl +++ b/Flocking/Agents/Flocking.jl @@ -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) ./ 2 bird.vel = bird.vel ./ norm(bird.vel) move_agent!(bird, model, bird.speed) end From 776e5fcc1a07f2edca83598ed41b86294efe124e Mon Sep 17 00:00:00 2001 From: Tortar <68152031+Tortar@users.noreply.github.com> Date: Wed, 20 Sep 2023 22:28:15 +0200 Subject: [PATCH 3/7] Update boid.py --- Flocking/Mesa/boid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flocking/Mesa/boid.py b/Flocking/Mesa/boid.py index 5deb6a40..42276815 100755 --- a/Flocking/Mesa/boid.py +++ b/Flocking/Mesa/boid.py @@ -73,7 +73,7 @@ def step(self): match_vector += neighbor.velocity N = max(N, 1) cohere = cohere / N * self.cohere_factor - separation_vector = separation_vector * self.separate_factor + separation_vector = separation_vector / N * 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 From cfb1887bc6b15446bcdec9079f5be2656dab004e Mon Sep 17 00:00:00 2001 From: Tortar <68152031+Tortar@users.noreply.github.com> Date: Wed, 20 Sep 2023 22:29:55 +0200 Subject: [PATCH 4/7] Update boid.py --- Flocking/Mesa/boid.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Flocking/Mesa/boid.py b/Flocking/Mesa/boid.py index 42276815..1872f998 100755 --- a/Flocking/Mesa/boid.py +++ b/Flocking/Mesa/boid.py @@ -75,8 +75,7 @@ def step(self): cohere = cohere / N * self.cohere_factor separation_vector = separation_vector / N * 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 + self.velocity += (cohere + separation_vector + match_vector) self.velocity /= np.linalg.norm(self.velocity) new_pos = self.pos + self.velocity * self.speed self.model.space.move_agent(self, new_pos) From b6f33036635d51a5b2ac2e0bf760cfdc4fb08379 Mon Sep 17 00:00:00 2001 From: Tortar <68152031+Tortar@users.noreply.github.com> Date: Wed, 20 Sep 2023 22:30:33 +0200 Subject: [PATCH 5/7] Update Flocking.jl --- Flocking/Agents/Flocking.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flocking/Agents/Flocking.jl b/Flocking/Agents/Flocking.jl index dc4a35f9..41a67b00 100755 --- a/Flocking/Agents/Flocking.jl +++ b/Flocking/Agents/Flocking.jl @@ -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) ./ 2 + bird.vel = bird.vel .+ (cohere .+ separate .+ match) ./ N bird.vel = bird.vel ./ norm(bird.vel) move_agent!(bird, model, bird.speed) end From 352f224a4c0d6a77fe0cd8673916b5e759a67512 Mon Sep 17 00:00:00 2001 From: Tortar <68152031+Tortar@users.noreply.github.com> Date: Wed, 20 Sep 2023 22:32:01 +0200 Subject: [PATCH 6/7] Update boid.py --- Flocking/Mesa/boid.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Flocking/Mesa/boid.py b/Flocking/Mesa/boid.py index 1872f998..87e7f98f 100755 --- a/Flocking/Mesa/boid.py +++ b/Flocking/Mesa/boid.py @@ -72,10 +72,10 @@ def step(self): separation_vector -= heading match_vector += neighbor.velocity N = max(N, 1) - cohere = cohere / N * self.cohere_factor - separation_vector = separation_vector / N * self.separate_factor - match_vector = match_vector / N * self.match_factor - self.velocity += (cohere + separation_vector + match_vector) + cohere = cohere * self.cohere_factor + separation_vector = separation_vector * self.separate_factor + 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) From 76af736ac4e9d3a18c590a04d200064baa4dcad9 Mon Sep 17 00:00:00 2001 From: Tortar <68152031+Tortar@users.noreply.github.com> Date: Thu, 21 Sep 2023 08:57:01 +0200 Subject: [PATCH 7/7] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 76dab812..d2298aca 100755 --- a/README.md +++ b/README.md @@ -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 |