|
@@ -4,32 +4,59 @@ from intelligine.synergy.stigmergy.MoleculesManager import MoleculesManager
|
4
|
4
|
|
5
|
5
|
class Evaporation:
|
6
|
6
|
|
7
|
|
- def __init__(self, context, intensity_decrement, molecules_exclude_types, molecule_minimum_age):
|
|
7
|
+ def __init__(self, context,
|
|
8
|
+ intensity_decrement=1,
|
|
9
|
+ molecule_minimum_age=0,
|
|
10
|
+ molecules_exclude_types=None,
|
|
11
|
+ molecules_include_types=None):
|
8
|
12
|
self._context = context
|
9
|
13
|
self._intensity_decrement = intensity_decrement
|
10
|
14
|
self._molecules_manager = MoleculesManager(context)
|
11
|
|
- self._molecules_exclude_types = molecules_exclude_types
|
12
|
15
|
self._molecule_minimum_age = molecule_minimum_age
|
|
16
|
+ self._molecules_exclude_types = molecules_exclude_types
|
|
17
|
+ self._molecules_include_types = molecules_include_types
|
13
|
18
|
|
14
|
19
|
def evaporate(self):
|
15
|
20
|
for position, flavour in self._get_flavours():
|
16
|
21
|
self._decrease_flavour(flavour)
|
17
|
22
|
self._molecules_manager.set_flavour(position, flavour)
|
18
|
23
|
|
|
24
|
+ def remove(self):
|
|
25
|
+ for position, flavour in self._get_flavours():
|
|
26
|
+ self._remove_molecule(flavour)
|
|
27
|
+ self._molecules_manager.set_flavour(position, flavour)
|
|
28
|
+
|
19
|
29
|
def _get_flavours(self):
|
20
|
|
- molecules_points = self._context.metas.list.get(MOLECULES, MOLECULES)
|
|
30
|
+ molecules_points = self._context.metas.list.get(MOLECULES, MOLECULES, allow_empty=True)
|
21
|
31
|
for molecule_point in molecules_points:
|
22
|
32
|
yield molecule_point, self._molecules_manager.get_flavour(molecule_point)
|
23
|
33
|
|
24
|
34
|
def _decrease_flavour(self, flavour):
|
|
35
|
+ for direction_molecule in self._get_molecules_from_flavour(flavour):
|
|
36
|
+ direction_molecule.increment_intensity(-self._intensity_decrement)
|
|
37
|
+ flavour.set_molecule(direction_molecule)
|
|
38
|
+
|
|
39
|
+ def _get_molecules_from_flavour(self, flavour):
|
|
40
|
+ molecules = []
|
25
|
41
|
for direction_molecule in flavour.get_molecules(MOLECULES_DIRECTION):
|
26
|
42
|
if not self._is_recent_molecule(direction_molecule) \
|
27
|
43
|
and not self._is_excluded_molecule_type(direction_molecule):
|
28
|
|
- direction_molecule.increment_intensity(-self._intensity_decrement)
|
29
|
|
- flavour.set_molecule(direction_molecule)
|
|
44
|
+ molecules.append(direction_molecule)
|
|
45
|
+ return molecules
|
|
46
|
+
|
|
47
|
+ def _remove_molecule(self, flavour):
|
|
48
|
+ for direction_molecule in self._get_molecules_from_flavour(flavour):
|
|
49
|
+ flavour.remove_molecule(direction_molecule)
|
30
|
50
|
|
31
|
51
|
def _is_recent_molecule(self, molecule):
|
32
|
52
|
return (self._context.get_cycle() - molecule.get_cycle_age()) < self._molecule_minimum_age
|
33
|
53
|
|
34
|
54
|
def _is_excluded_molecule_type(self, molecule):
|
35
|
|
- return molecule.get_type() in self._molecules_exclude_types
|
|
55
|
+ if not self._molecules_exclude_types and not self._molecules_include_types:
|
|
56
|
+ return False
|
|
57
|
+
|
|
58
|
+ if self._molecules_exclude_types and not self._molecules_include_types:
|
|
59
|
+ return molecule.get_type() in self._molecules_exclude_types
|
|
60
|
+
|
|
61
|
+ if not self._molecules_exclude_types and self._molecules_include_types:
|
|
62
|
+ return molecule.get_type() not in self._molecules_include_types
|