uo.algorithm.metaheuristic package

Subpackages

Submodules

uo.algorithm.metaheuristic.metaheuristic module

The metaheuristic module describes the class Metaheuristic.

class uo.algorithm.metaheuristic.metaheuristic.Metaheuristic(finish_control: FinishControl, problem: Problem, solution_template: Solution | None, name: str, output_control: OutputControl | None, random_seed: int | None, additional_statistics_control: AdditionalStatisticsControl | None)

Bases: Algorithm

This class represent metaheuristic

property additional_statistics_control: AdditionalStatisticsControl | None

Property getter for the structure that controls keeping of the statistic during metaheuristic execution

Returns:

structure that controls that controls keeping of the statistic during metaheuristic execution

Return type:

Optional[AdditionalStatisticsControl]

abstract copy()

Copy the current metaheuristic

Returns:

new Metaheuristic instance with the same properties

Return type:

Metaheuristic

determine_fields_val(fields_def: list[str], fields_val: list[str]) list[str]

Determines fields values upon fields definition and old values

Parameters:
  • fields_def (list[str]) – list of field definitions

  • fields_val (list[str]) – list of old field values

Returns:

list of new field values

Return type:

list[str]

elapsed_seconds() float

Calculate time elapsed during execution of the metaheuristic algorithm

Returns:

elapsed time (in seconds)

Return type:

float

property finish_control: FinishControl

Property getter for the structure that controls finish criteria for metaheuristic execution

Returns:

structure that controls finish criteria for metaheuristic execution

Return type:

FinishControl

main_loop() None

Main loop of the metaheuristic algorithm

abstract main_loop_iteration() None

One iteration within main loop of the metaheuristic algorithm

optimize() Solution

Executing optimization by the metaheuristic algorithm

property random_seed: int

Property getter for the random seed used during metaheuristic execution

Returns:

random seed

Return type:

int

should_finish() bool

Check if execution of the metaheuristic algorithm should finish

Returns:

Should execution finish

Return type:

bool

string_rep(delimiter: str, indentation: int = 0, indentation_symbol: str = '', group_start: str = '{', group_end: str = '}') str

String representation of the Metaheuristic instance

Parameters:
  • delimiter (str) – delimiter between fields

  • indentation (int, optional, default value 0) – level of indentation

  • indentation_symbol (str, optional, default value '') – indentation symbol

  • group_start (str, optional, default value '{') – group start string

  • group_end (str, optional, default value '}') – group end string

Returns:

string representation of instance that controls output

Return type:

str

update_additional_statistics_if_required(solution: Solution) None

Updates the additional statistics, if required.

uo.algorithm.metaheuristic.metaheuristic.random() x in the interval [0, 1).

The single_solution_metaheuristic module describes the class SingleSolutionMetaheuristic.

class uo.algorithm.metaheuristic.single_solution_metaheuristic.SingleSolutionMetaheuristic(finish_control: FinishControl, problem: Problem, solution_template: Solution | None, name: str, output_control: OutputControl | None, random_seed: int | None, additional_statistics_control: AdditionalStatisticsControl | None)

Bases: Metaheuristic

This class represent single solution metaheuristic

abstract copy()

Copy the current single solution metaheuristic

Returns:

new SingleSolutionMetaheuristic instance with the same properties

Return type:

SingleSolutionMetaheuristic

property current_solution: Solution | None

Property getter for the current solution used during single solution metaheuristic execution

Returns:

instance of the uo.solution.Solution class subtype – current solution of the problem

Return type:

Solution

string_rep(delimiter: str, indentation: int = 0, indentation_symbol: str = '', group_start: str = '{', group_end: str = '}') str

String representation of the SingleSolutionMetaheuristic instance

Parameters:
  • delimiter (str) – delimiter between fields

  • indentation (int, optional, default value 0) – level of indentation

  • indentation_symbol (str, optional, default value '') – indentation symbol

  • group_start (str, optional, default value '{') – group start string

  • group_end (str, optional, default value '}') – group end string

Returns:

string representation of instance that controls output

Return type:

str

uo.algorithm.metaheuristic.single_solution_metaheuristic.random() x in the interval [0, 1).

The population_based_metaheuristic module describes the class PopulationBasedMetaheuristic.

class uo.algorithm.metaheuristic.population_based_metaheuristic.PopulationBasedMetaheuristic(finish_control: FinishControl, problem: Problem, solution_template: Solution | None, name: str, output_control: OutputControl | None, random_seed: int | None, additional_statistics_control: AdditionalStatisticsControl | None)

Bases: Metaheuristic

This class represent population metaheuristic

abstract copy() PopulationBasedMetaheuristic

Copy the current population based metaheuristic

Returns:

new PopulationBasedMetaheuristic instance with the same properties

Return type:

PopulationBasedMetaheuristic

property current_population: list[Solution] | None

Property getter for the population of solutions within population based metaheuristic execution

Returns:

list of the uo.solution.Solution class subtype – current solutions of the problem

Return type:

list[Solution]

string_rep(delimiter: str, indentation: int = 0, indentation_symbol: str = '', group_start: str = '{', group_end: str = '}') str

String representation of the SingleSolutionMetaheuristic instance

Parameters:
  • delimiter (str) – delimiter between fields

  • indentation (int, optional, default value 0) – level of indentation

  • indentation_symbol (str, optional, default value '') – indentation symbol

  • group_start (str, optional, default value '{') – group start string

  • group_end (str, optional, default value '}') – group end string

Returns:

string representation of instance that controls output

Return type:

str

uo.algorithm.metaheuristic.population_based_metaheuristic.random() x in the interval [0, 1).
class uo.algorithm.metaheuristic.metaheuristic_void.MetaheuristicVoid(finish_control: FinishControl, problem: Problem, solution_template: Solution | None = None, name: str = 'metaheuristic-void', output_control: OutputControl | None = None, random_seed: int | None = None, additional_statistics_control: AdditionalStatisticsControl | None = None)

Bases: Metaheuristic

copy()

Copy the current metaheuristic

Returns:

new Metaheuristic instance with the same properties

Return type:

Metaheuristic

init()
main_loop_iteration() None

One iteration within main loop of the metaheuristic algorithm

uo.algorithm.metaheuristic.metaheuristic_void.random() x in the interval [0, 1).
class uo.algorithm.metaheuristic.single_solution_metaheuristic_void.SingleSolutionMetaheuristicVoid(finish_control: ~uo.algorithm.metaheuristic.finish_control.FinishControl, problem: ~uo.problem.problem.Problem =, solution_template: ~uo.solution.solution.Solution | None =  { fitness_value=-inf objective_value=-inf is_feasible=False representation()=None evaluation_cache_cs=Nonerepresentation_distance_cache_cs=None}, name: str = 'ss_metaheuristic_void', output_control: ~uo.algorithm.output_control.OutputControl | None = None, random_seed: int | None = None, additional_statistics_control: ~uo.algorithm.metaheuristic.additional_statistics_control.AdditionalStatisticsControl | None = None)

Bases: SingleSolutionMetaheuristic

copy()

Copy the current single solution metaheuristic

Returns:

new SingleSolutionMetaheuristic instance with the same properties

Return type:

SingleSolutionMetaheuristic

init()
main_loop_iteration() None

One iteration within main loop of the metaheuristic algorithm

uo.algorithm.metaheuristic.single_solution_metaheuristic_void.random() x in the interval [0, 1).
class uo.algorithm.metaheuristic.population_based_metaheuristic_void.PopulationBasedMetaheuristicVoid(finish_control: ~uo.algorithm.metaheuristic.finish_control.FinishControl, problem: ~uo.problem.problem.Problem =, solution_template: ~uo.solution.solution.Solution | None =  { fitness_value=-inf objective_value=-inf is_feasible=False representation()=None evaluation_cache_cs=Nonerepresentation_distance_cache_cs=None}, name: str = 'pop_metaheuristic_void', output_control: ~uo.algorithm.output_control.OutputControl | None = None, random_seed: int | None = None, additional_statistics_control: ~uo.algorithm.metaheuristic.additional_statistics_control.AdditionalStatisticsControl | None = None)

Bases: PopulationBasedMetaheuristic

copy()

Copy the current population based metaheuristic

Returns:

new PopulationBasedMetaheuristic instance with the same properties

Return type:

PopulationBasedMetaheuristic

init()
main_loop_iteration() None

One iteration within main loop of the metaheuristic algorithm

uo.algorithm.metaheuristic.population_based_metaheuristic_void.random() x in the interval [0, 1).

Module contents