infection.util package
Submodules
infection.util.individual module
This module defines the Individual abstract class, and its HeallthyIndividual and InfectedIndividual subclasses and all of their properties and methods.
- class infection.util.individual.HealthyIndividual(simulation: Simulation, infection_probability: float, **kwargs)[source]
Bases:
Individual
- This is the definition of the HealthyIndividual class. It inherits
from the Individual abstract class.
- Args:
simulation (Simulation): Instance of the Simulation class. infection_probability (Float): A value from 0 to 1 that
determines how likely is an individual to get infected.
- Attributes:
simulation: To store the instance of the simulation class. infection_probability: To store the infection_probability. recovered: Boolean property used to track when the individual has
recovered from an infection. False by default. True when it has recovered from an infection. An individual that has recovered from an infection can no longer get infected.
- time_infected: Integer property that tracks during how many cycles
the individual has been infected.
- max_time_infected: Integer property that defines how many cycles need
to pass until the individual recovers. This private property can’t be modified since it doesn’t have a setter method. Set to MAX_TIME_INFECTED.
- cooldown: Integer property that tracks how many cycles have passed
after the last infection evaluation to avoid evaluating against the same individual multiple times after crossing paths.
- max_cooldown: Integer property that defines how many cycles need
to pass until the infection evaluations restart. This private property can’t be modified since it doesn’t have a setter method. Set to MAX_COOLDOWN.
- status: String property that tracks the infection status of the
individual. “healthy” by default.
- property cooldown: int
- count_infected_neighbors(circular_button: CircularButton, quad_tree: QuadTree) int [source]
- Method that searches the quad_tree to find the number of infected
individuals within the provided radius and returns the count in the infected_neighbor_count variable.
- Args:
- circular_button (CircularButton): Instance of the button
containing the individual.
- quad_tree (QuadTree): A quadtree structure that contains the
positions of all the individuals in the simulation for fast neighbor search.
- Returns:
- infected_neighbor_count (int): The number of infected individuals
within the provided radius.
- evaluate_infection(circular_button: CircularButton, quad_tree: QuadTree) tuple[int, int] [source]
- Method that calls the count_infected_neighbors method and if
there’s one or more infected neighbors, a formula is used to randomly calculate if the individual should get infected based on the infection_probability and the number of infected neighbors.
- Args:
- circular_button (CircularButton): Instance of the button
containing the individual.
- quad_tree (QuadTree): A quadtree structure that contains the
positions of all the individuals in the simulation for fast neighbor search.
- Returns:
infected (int): 0 if not infected, 1 or more if infected. infected_neighbor_count: The number of infected individuals
within the provided radius.
- infection(circular_button: CircularButton, quad_tree: QuadTree) None [source]
- Method that controls if the individual will get infected by
being around one or more infected individuals in the provided quad_tree, or if the individual is now recovered because self.max_time_infected cycles have passed after infection.
- Args:
- circular_button (CircularButton): The instance of the button
containing the individual to change its properties.
- quad_tree (QuadTree): A quadtree structure that contains the
position of all the individuals in the canvas for fast neighbor search.
- property infection_probability: float
- property max_cooldown: int
- property max_time_infected: int
- recover(circular_button: CircularButton) None [source]
Method to set the individual’s properties when it recovers.
- Args:
- circular_button (CircularButton): Instance of the button
containing the individual.
- property recovered: int
Boolean property used to track when the individual has recovered from an infection.
- sick(circular_button: CircularButton) None [source]
Method to set the individual’s properties when it gets sick.
- Args:
- circular_button (CircularButton): Instance of the button
containing the individual.
- property simulation: Simulation
To store an instance of the simulation class.
- property status: str
String property used to track the infection status of the individual.
- property time_infected: int
Integer property to track how long the individual has been infected.
- class infection.util.individual.Individual[source]
Bases:
ABC
This is the definition of the Individual abstract class. It inherits from the ABC class to make it an abstract class.
- abstract infection() None [source]
Abstract method that will control the infection status of the individual and decide if it will get infected or if it will recover.
- abstract recover() None [source]
Abstract method that will set the properties when the individual recovers from infection
- abstract property recovered: bool
Boolean property used to track when the individual has recovered from an infection.
- abstract property simulation: Simulation
To store an instance of the simulation class.
- abstract property status: str
String property used to track the infection status of the individual.
- abstract property time_infected: int
Integer property to track how long the individual has been infected.
- class infection.util.individual.InfectedIndividual(simulation: Simulation, **kwargs)[source]
Bases:
Individual
This is the definition of the InfectedIndividual class. It inherits from the Individual abstract class.
- Args:
simulation (Simulation): Instance of the Simulation class.
- Attributes:
simulation: To store the instance of the simulation class. recovered: Boolean property used to track when the individual has
recovered from an infection. False by default. True when it has recovered from an infection. An individual that has recovered from an infection can no longer get infected.
- time_infected: Integer property that tracks during how many cycles
the individual has been infected.
- max_time_infected: Integer property that defines how many cycles need
to pass until the individual recovers. This private property can’t be modified since it doesn’t have a setter method. Set to MAX_TIME_INFECTED.
- status: String property that tracks the infection status of the
individual. “infected” by default.
- infection(circular_button: CircularButton, quad_tree: QuadTree) None [source]
- Method that controls if the individual is now recovered because
self.max_time_infected cycles have passed after infection.
- Args:
- circular_button (CircularButton): The instance of the button
containing the individual to change its properties.
- quad_tree (QuadTree): A quadtree structure that contains the
position of all the individuals in the canvas for fast neighbor search. Ignored in the InfectedIndividual class.
- property max_time_infected: int
- recover(circular_button: CircularButton) None [source]
Method to set the individual’s properties when it recovers.
- Args:
- circular_button (CircularButton): Instance of the button
containing the individual.
- property recovered: bool
Boolean property used to track when the individual has recovered from an infection.
- property simulation: Simulation
To store an instance of the simulation class.
- property status: str
String property used to track the infection status of the individual.
- property time_infected: int
Integer property to track how long the individual has been infected.