Evaporation.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536
  1. from intelligine.cst import MOLECULES, MOLECULES_DIRECTION
  2. from intelligine.synergy.stigmergy.MoleculesManager import MoleculesManager
  3. class Evaporation:
  4. def __init__(self, context, intensity_decrement, molecules_exclude_types, molecule_minimum_age):
  5. self._context = context
  6. self._intensity_decrement = intensity_decrement
  7. self._molecules_manager = MoleculesManager(context)
  8. self._molecules_exclude_types = molecules_exclude_types
  9. self._molecule_minimum_age = molecule_minimum_age
  10. def evaporate(self):
  11. for position, flavour in self._get_flavours():
  12. self._decrease_flavour(flavour)
  13. self._molecules_manager.set_flavour(position, flavour)
  14. def _get_flavours(self):
  15. molecules_points = self._context.metas.list.get(MOLECULES, MOLECULES)
  16. for molecule_point in molecules_points:
  17. yield molecule_point, self._molecules_manager.get_flavour(molecule_point)
  18. def _decrease_flavour(self, flavour):
  19. for direction_molecule in flavour.get_molecules(MOLECULES_DIRECTION):
  20. if not self._is_recent_molecule(direction_molecule) \
  21. and not self._is_excluded_molecule_type(direction_molecule):
  22. direction_molecule.increment_intensity(-self._intensity_decrement)
  23. flavour.set_molecule(direction_molecule)
  24. def _is_recent_molecule(self, molecule):
  25. return (self._context.get_cycle() - molecule.get_cycle_age()) < self._molecule_minimum_age
  26. def _is_excluded_molecule_type(self, molecule):
  27. return molecule.get_type() in self._molecules_exclude_types