Update app.py
Browse files
app.py
CHANGED
@@ -35,12 +35,14 @@ class HiveMind:
|
|
35 |
self.pheromone_importance = {'food': 0.5, 'danger': 0.3, 'exploration': 0.2}
|
36 |
|
37 |
def update_collective_memory(self, ant_memories):
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
44 |
|
45 |
def update_global_strategy(self, ant_performances):
|
46 |
best_ants = sorted(ant_performances, key=lambda x: x[1], reverse=True)[:5]
|
|
|
35 |
self.pheromone_importance = {'food': 0.5, 'danger': 0.3, 'exploration': 0.2}
|
36 |
|
37 |
def update_collective_memory(self, ant_memories):
|
38 |
+
for memory in ant_memories:
|
39 |
+
for position, info in memory:
|
40 |
+
if position not in self.collective_memory:
|
41 |
+
self.collective_memory[position] = info
|
42 |
+
else:
|
43 |
+
old_info = self.collective_memory[position]
|
44 |
+
new_info = tuple((old + new) / 2 for old, new in zip(old_info, info))
|
45 |
+
self.collective_memory[position] = new_info
|
46 |
|
47 |
def update_global_strategy(self, ant_performances):
|
48 |
best_ants = sorted(ant_performances, key=lambda x: x[1], reverse=True)[:5]
|