This commit is contained in:
Alexander Bocken 2023-06-26 16:03:45 +02:00
parent fb1c8f5797
commit 9fae37347b
Signed by: Alexander
GPG Key ID: 1D237BE83F9B05E8
2 changed files with 15 additions and 16 deletions

View File

@ -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):

21
main.py
View File

@ -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()