CVOA - Coronavirus Optimization Algorithm

The CVOA (Coronavirus Optimization Algorithm) module implements a novel metaheuristic inspired by the spreading behavior of the coronavirus. It provides both local and distributed implementations of the algorithm.

Submodules

CVOA Local

class CVOA(global_state: LocalPandemicState, domain: Domain, fitness_function: Callable[[Solution], float], strain_properties: StrainProperties = ('Strain#1', 10, 5, 6, 15, 7, 0.5, 0.1, 0.001, 0.1, 0.05), update_isolated=False, log_dir='logs/CVOA')

Bases: Metaheuristic

This class implements the CVOA algorithm. It uses the Solution class as an abstraction of an individual for the meta-heuristic.

It solves an optimization problem defined by a Domain object and an implementation of a fitness function.

By instantiate CVOA object, i.e. a strain, the configuration parameters must be provided.

This class supports multiple strain execution by means of multy-threading. Each strain (CVOA object) will execute its CVOA algorithm (cvoa()) in a thread and, finally, the best Solution (i.e. the best fitness function is obtained).

To launch a multi-strain execution, this module provides the cvoa_launcher() method.

Parameters:
  • strain_id (str) – The strain name

  • pandemic_duration (int) – The pandemic duration, defaults to 10

  • spreading_rate (int) – The spreading rate, defaults to 6

  • min_super_spreading_rate (int) – The minimum super spreading rate, defaults to 6

  • max_super_spreading_rate (int) – The maximum super spreading rate, defaults to 15

  • social_distancing (int) – The distancing stablished between the individuals, defaults to 10

  • p_isolation (float) – The probability of an individual being isolated, defaults to 0.7

  • p_travel (float) – The probability that an individual will travel, defaults to 0.1

  • p_re_infection (float) – The probability of an individual being re-infected, defaults to 0.0014

  • p_superspreader (float) – The probability of an individual being a super-spreader, defaults to 0.1

  • p_die (float) – The probability that an individual will die, defaults to 0.05

  • verbose (bool) – The verbosity option, defaults to True

Code example

from metagen.framework import Domain, Solution
from metagen.metaheuristics import CVOA, cvoa_launcher
domain = Domain()
multithread = True

domain.defineInteger(0, 1)

fitness_function = ...

if multithread: # For multiple thread excecution

    CVOA.initialize_pandemic(domain, fitness_function)
    strain1 = CVOA("Strain1", pandemic_duration=100)
    strain2 = CVOA("Strain2",  pandemic_duration=100)
    ...

    strains = [strain1, strain2, ...]
    optimal_solution = cvoa_launcher(strains)
else: # For individual thread excecution

    CVOA.initialize_pandemic(domain, fitness_function)
    search = CVOA(pandemic_duration=100)
    optimal_solution = search.run()
initialize(num_solutions=10) Tuple[List[Solution], Solution]

Initialize the population/solutions for the metaheuristic. Must set self.current_solutions and self.best_solution.

Parameters:

num_solutions (int) – The number of solutions to initialize.

Returns:

A tuple containing the population and the best individual.

Return type:

Tuple[List[Solution], Solution]

iterate(solutions: List[Solution]) Tuple[List[Solution], Solution]

Execute one iteration of the metaheuristic.

Parameters:

solutions (List[Solution]) – The current population of solutions.

Returns:

A tuple containing the updated population and the best individual.

Return type:

Tuple[List[Solution], Solution]

update_pandemic_global_state() None

It updates the specific strain death and superspreader’s sets and the global death and recovered sets.

update_new_infected_population(new_infected_population: Set[Solution], new_infected_individual: Solution) None

It updates the next infected population with a new infected individual.

Parameters:
  • new_infected_population (set of Solution) – The population of the next iteration.

  • new_infected_individual (Solution) – The new infected individual that will be inserted into the netx iteration set.

stopping_criterion() bool

Check if the algorithm should stop. Override this method to implement custom stopping criteria.

Returns:

True if the algorithm should stop, False otherwise.

Return type:

bool

post_execution() None

Callback executed after algorithm execution completes. Override this method to add custom post-execution cleanup.

CVOA Distributed

class DistributedCVOA(global_state: ray.remote, domain: Domain, fitness_function: Callable[[Solution], float], strain_properties: StrainProperties = ('Strain#1', 10, 5, 6, 15, 7, 0.5, 0.1, 0.001, 0.1, 0.05), update_isolated=False, log_dir='logs/DCVOA', detailed_info=False)

Bases: Metaheuristic

This class implements the CVOA algorithm. It uses the Solution class as an abstraction of an individual for the meta-heuristic.

It solves an optimization problem defined by a Domain object and an implementation of a fitness function.

By instantiate CVOA object, i.e. a strain, the configuration parameters must be provided.

This class supports multiple strain execution by means of multy-threading. Each strain (CVOA object) will execute its CVOA algorithm (cvoa()) in a thread and, finally, the best Solution (i.e. the best fitness function is obtained).

To launch a multi-strain execution, this module provides the cvoa_launcher() method.

Parameters:
  • strain_id (str) – The strain name

  • pandemic_duration (int) – The pandemic duration, defaults to 10

  • spreading_rate (int) – The spreading rate, defaults to 6

  • min_super_spreading_rate (int) – The minimum super spreading rate, defaults to 6

  • max_super_spreading_rate (int) – The maximum super spreading rate, defaults to 15

  • social_distancing (int) – The distancing stablished between the individuals, defaults to 10

  • p_isolation (float) – The probability of an individual being isolated, defaults to 0.7

  • p_travel (float) – The probability that an individual will travel, defaults to 0.1

  • p_re_infection (float) – The probability of an individual being re-infected, defaults to 0.0014

  • p_superspreader (float) – The probability of an individual being a super-spreader, defaults to 0.1

  • p_die (float) – The probability that an individual will die, defaults to 0.05

  • verbose (bool) – The verbosity option, defaults to True

initialize(num_solutions=10) Tuple[List[Solution], Solution]

Initialize the population/solutions for the metaheuristic. Must set self.current_solutions and self.best_solution.

Parameters:

num_solutions (int) – The number of solutions to initialize.

Returns:

A tuple containing the population and the best individual.

Return type:

Tuple[List[Solution], Solution]

iterate(solutions: List[Solution]) Tuple[List[Solution], Solution]

Execute one iteration of the metaheuristic.

Parameters:

solutions (List[Solution]) – The current population of solutions.

Returns:

A tuple containing the updated population and the best individual.

Return type:

Tuple[List[Solution], Solution]

update_pandemic_global_state() None

It updates the specific strain death and superspreader’s sets and the global death and recovered sets.

update_new_infected_population(new_infected_population: Set[Solution], new_infected_individual: Solution) None

It updates the next infected population with a new infected individual.

Parameters:
  • new_infected_population (set of Solution) – The population of the next iteration.

  • new_infected_individual (Solution) – The new infected individual that will be inserted into the netx iteration set.

stopping_criterion() bool

Check if the algorithm should stop. Override this method to implement custom stopping criteria.

Returns:

True if the algorithm should stop, False otherwise.

Return type:

bool

post_execution() None

Callback executed after algorithm execution completes. Override this method to add custom post-execution cleanup.