From 9fae37347b243b308c6d0f94de7883fddb3676fe Mon Sep 17 00:00:00 2001 From: AlexBocken Date: Mon, 26 Jun 2023 16:03:45 +0200 Subject: [PATCH] hotfix --- agent.py | 10 +++++++--- main.py | 21 ++++++++------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/agent.py b/agent.py index c76ebf2..2be08df 100644 --- a/agent.py +++ b/agent.py @@ -103,7 +103,7 @@ class RandomWalkerAnt(Agent): """ combined = res_weights * walk_weights normalized = combined / np.sum(combined) - return normalized + return list(normalized) def _pick_from_remaining_five(remaining_five): """ @@ -190,7 +190,9 @@ class RandomWalkerAnt(Agent): res_weights = self._get_resistance_weights() weights = _combine_weights(res_weights, sens_weights) - self._next_pos = np.random.choice(all_neighbors_cells, p=weights) + random_index = np.random.choice(range(6), p=weights) + self._next_pos = all_neighbors_cells[random_index] + self._prev_pos = self.pos return @@ -205,7 +207,9 @@ class RandomWalkerAnt(Agent): walk_weights[front_index] = self.model.alpha weights = _combine_weights(res_weights, walk_weights) - self._nex_pos = np.random.choice(all_neighbors_cells, p=weights) + + random_index = np.random.choice(range(6), p=weights) + self._next_pos = all_neighbors_cells[random_index] self._prev_pos = self.pos def step(self): diff --git a/main.py b/main.py index 870155c..86a1875 100755 --- a/main.py +++ b/main.py @@ -180,21 +180,16 @@ if __name__ == "__main__": print(kwargs) model = ActiveWalkerModel(**kwargs) - # from hexplot import plot_hexagon - # a = np.zeros_like(model.grid.fields['food']) - # a[np.nonzero(model.grid.fields['food'])] = 1 - # plot_hexagon(a, title="Nest locations") - # plot_hexagon(model.grid.fields['res'], title="Resistance Map") + from hexplot import plot_hexagon + a = np.zeros_like(model.grid.fields['food']) + a[np.nonzero(model.grid.fields['food'])] = 1 + plot_hexagon(a, title="Nest locations") + plot_hexagon(model.grid.fields['res'], title="Resistance Map") - # from tqdm import tqdm as progress_bar - #for _ in progress_bar(range(model.max_steps)): - # model.step() - # agent_densities = model.datacollector.get_model_vars_dataframe()["agent_dens"] - # mean_dens = np.mean(agent_densities) - # norm_dens = mean_dens/np.max(mean_dens) - # plot_hexagon(norm_dens, title="Ant density overall") - # plt.show() + from tqdm import tqdm as progress_bar + for _ in progress_bar(range(model.max_steps)): + model.step()