Sephfox commited on
Commit
f7ea6fc
1 Parent(s): d434cb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
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
- 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
- self.collective_memory[position] = (self.collective_memory[position] + info) / 2
 
 
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]