class PheromoneΒΆ

This script defines a Pheromone class that represents and manages pheromone intensity over time. The class provides methods for updating the intensity and retrieving its properties.

Attributes:
  • __intensity (float): Intensity of the pheromone (1 when released).

  • __center_x (int): X coord. of the matrix where it will be released. (NOT USED)

  • __center_y (int): Y coord. of the matrix where it will be released. (NOT USED)

  • __radius_top (int): Top radius indicating where intensity(r, k) = intensity(0, k). (NOT USED)

  • __radius_down (int): Down radius indicating where intensity decreases gradually between top radius and down radius, and drops to 0 after down radius. (NOT USED)

  • __deltaEvaporate (float): Delta(r) = evapRate * intensity(r,0).

  • __evapRate (float): Rate for the evaporation: in 20 sec the pheromone vanishes (because intensity(0, 0) = 1 -> intensity(0, 20) = 0).

  • __olfactory_habituation (int): 10sec. (NOT USED)

  • __released_by (int): Index of the drone which released the pheromone.

Methods:
  • tick(self) -> bool

  • get_intensity(self) -> float

  • released_by(self) -> int

  • released_by.setter(self, value:int)

Example:

>>> from models.pheromone import Pheromone
>>>
>>> pheromone = Pheromone()
>>>
>>> pheromone.tick()
True
>>>
>>> pheromone.get_intensity()
0.95
>>>
>>> pheromone.released_by
0
from models.pheromone import Pheromone

class Pheromone:
    """
    Assuming:
    - start intensity = 1
    - tick interval = 1s
    """

    def __init__(self):
        self.__intensity = 1                # intensity of the pheromone (1 when released)
        # self.__center_x = None              # X coord. of the matrix where it will be released
        # self.__center_y = None              # Y coord. of the matrix where it will be released
        # self.__radius_top = 1               # top radius indicating where intensity(r, k) = intensity(0, k)
        # self.__radius_down = 1              # down radius indicating where intensity decreases gradually between top radius and down radius, and drops to 0 after down radius
        self.__deltaEvaporate = None        # delta(r) = evapRate * intensity(r,0)
        self.__evapRate = 0.05               # rate for the evaporation: in 20 sec the pheromone vanishes (because intensity(0, 0) = 1 -> intensity(0, 20) = 0)
        # self.__olfactory_habituation = 10    # 10sec
        self.__released_by = None

    def tick(self) -> bool:
        """
        Updates intensity value as time goes by.
        Called by `Stigmergy` parent class.

        Returns:
        - True if Pheromone is still active
        - False if Pheromone has reached 0 `intensity` value
        """
        self.__deltaEvaporate = self.__evapRate * 1
        self.__intensity -= self.__deltaEvaporate
        return self.__intensity > 0

    @property
    def get_intensity(self) -> float:
        """
        Get current intensity value at its center
        """
        return self.__intensity

    @property
    def released_by(self) -> int:
        """
        Get index of the drone which released the pheromone
        """
            return self.__released_by

    @released_by.setter
    def released_by(self, value:int):
        """
        Set index of the drone which released the pheromone
        """
        self.__released_by = value