infection package
Subpackages
- infection.decorators package
- infection.util package
- Submodules
- infection.util.circular_button module
- infection.util.individual module
HealthyIndividual
HealthyIndividual.cooldown
HealthyIndividual.count_infected_neighbors()
HealthyIndividual.evaluate_infection()
HealthyIndividual.infection()
HealthyIndividual.infection_probability
HealthyIndividual.max_cooldown
HealthyIndividual.max_time_infected
HealthyIndividual.recover()
HealthyIndividual.recovered
HealthyIndividual.sick()
HealthyIndividual.simulation
HealthyIndividual.status
HealthyIndividual.time_infected
Individual
InfectedIndividual
- infection.util.menu_bottom module
- infection.util.menu_right module
- Module contents
Submodules
infection.simulation module
This module defines the Simulation class and all of its properties and methods. This is the main class that controls the simulation.
- class infection.simulation.Simulation(**kwargs)[source]
Bases:
App
- This is the definition of the Simulation class. It inherits from the
App Kivy class.
- Attributes:
- thread_pool: A ThreadPoolExecutor instance to spawn new threads
as required for the simulation, with a maximum of 4 workers.
threads: Integer that keeps the count of the spawned threads. quadtree: A QuadTree structure that contains the positions of all the
individuals in the simulation for fast neighbor search.
population: List of all the Individuals in the simulation. healthy: Integer that keeps the count of the healthy individuals
in the simulation.
- infected: Integer that keeps the count of the infected individuals
in the simulation.
- infection_probability: Float that stores the current infection
probability value. Initialized to 0.2.
- individual_size: The size of an individual in the canvas. It also
determines how close a healthy individual needs to be to an infected one to get infected. Ignored in the InfectedIndividual class. Initialized to Window.size[1] * .035.
- healthy_color: The color of a healthy individual in the canvas.
Initialized to the rgba value of blue.
- infected_color: The color of an infected individual in the canvas.
Initialized to the rgba value of red.
- recovered_color: The color of an infected individual in the canvas.
Initialized to the rgba value of green.
- add_healthy(number: int, *largs) int [source]
- Method that adds new healthy individuals to the simulation. The
number of individuals added is determined by the provided “number” argument.
- Args:
number (int): The number of healthy individuals to add to the simulation.
- Returns:
self.healthy (int): The final count of healthy individuals.
- add_infected(number: int, *largs) int [source]
- Method that adds new infected individuals to the simulation. The
number of individuals added is determined by the provided “number” argument.
- Args:
number (int): The number of infected individuals to add to the simulation.
- Returns:
self.infected (int): The final count of infected individuals.
- build() BoxLayout [source]
- Kivy method that initializes and integrates all the components of
the Simulation App instance and its graphical components.
- Returns:
- self.root (BoxLayout): An instance of the root Kivy widget that
contains all the graphical components of the simulation.
- property healthy: int
- property healthy_color: list
- property individual_size: int
- property infected: int
- property infected_color: list
- property infection_probability: float
- property population: list
- property quadtree: QuadTree
- property recovered_color: list
- reset_population(*largs) list [source]
- Method that resets all the simulation’s properties to their
initial states and values.
- Returns:
- self.population (list): An empty list after the population
was deleted.
- safe_sum_healthy(number: int) int [source]
- Method that safely increases or decreases the healthy individual
count, using “with lock” to avoid race condition. It also updates the value of the healthy individual count Label in the menu_bottom.
- Args:
number (int): The number of healthy individuals to increase or decrease.
- Returns:
self.healthy (int): The final count of healthy individuals.
- safe_sum_infected(number: int) int [source]
- Method that safely increases or decreases the infected individual
count, using “with lock” to avoid race condition. It also updates the value of the infected individual count Label in the menu_bottom
- Args:
number (int): The number of infected individuals to increase or decrease.
- Returns:
self.infected (int): The final count of infected individuals.
- property thread_pool: ThreadPoolExecutor
- property threads: int
- update(dt: float) None [source]
- Kivy method used to update the simulation on each cycle.
It uses the thread pool in self.thread_pool to spawn threads to control the infection state and movement of each individual in the simulation. To control the infection state, the “infection” method of each Individual is invoked in a thread, providing it the button containing the individual, and a quadtree with the positions of all the individuals. To control the movement, the “move” method of each Individual is invoked in a thread, providing an instance of the main simulation so the individual can calculate its position in the canvas and determine when it has to change direction.
- Args:
dt (Float): Internal Kivy property used to update the app on each cycle.