uo.algorithm package

Subpackages

Submodules

uo.algorithm.algorithm module

The algorithm module describes the class Algorithm.

class uo.algorithm.algorithm.Algorithm(problem: Problem, solution_template: Solution | None, name: str, output_control: OutputControl | None)

Bases: Optimizer

This class describes Algorithm.

name

The name of the algorithm.

Type:

str

output_control

The structure that controls output.

Type:

OutputControl

problem

The problem to be solved.

Type:

Problem

solution_template

The solution template for the problem to be solved.

Type:

Optional[Solution]

Properties:

solution_template (Optional[Solution]): The solution template for the problem to be solved. evaluation (int): The current number of evaluations during algorithm execution. iteration (int): The iteration of metaheuristic execution. iteration_best_found (int): The iteration when the best solution is found.

__init__(name

str, output_control: OutputControl, problem: Problem, solution_template: Optional[Solution] = None) -> None: Create a new Algorithm instance.

__copy__() Algorithm

Internal copy of the current algorithm.

copy() Algorithm

Copy the current algorithm.

init() None

Initialization of the algorithm.

string_rep(delimiter

str, indentation: int = 0, indentation_symbol: str = ‘’, group_start: str = ‘{’, group_end: str = ‘}’) -> str: String representation of the ‘Algorithm’ instance.

__str__() str

String representation of the ‘Algorithm’ instance.

__repr__() str

Representation of the ‘Algorithm’ instance.

__format__(spec

str) -> str: Formatted ‘Algorithm’ instance.

property best_solution: Solution

Property getter for the best solution obtained during metaheuristic execution

Returns:

best solution so far

Return type:

Solution

abstract copy()

Copy the current algorithm

Returns:

new Algorithm instance with the same properties

Return type:

uo.algorithm.Algorithm

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]

property evaluation: int

Property getter for current number of evaluations during algorithm execution

Returns:

current number of evaluations

Return type:

int

property evaluation_best_found: int

Property getter for the evaluation when the best solution is found

Returns:

evaluation when the best solution is found

Return type:

int

property iteration: int

Property getter for the iteration of metaheuristic execution

Returns:

iteration

Return type:

int

property iteration_best_found: int

Property getter for the iteration when the best solution is found

Returns:

iteration when the best solution is found

Return type:

int

property solution_template: Solution | None

Property getter for the solution template for the problem to be solved

Returns:

solution template for the problem to be solved

Return type:

Solution

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

String representation of the ‘Algorithm’ 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.output_control module

The output_control module describes the class OutputControl.

class uo.algorithm.output_control.OutputControl(output_file: TextIOWrapper | None = None, fields: str = 'iteration, evaluation, "step_name", best_solution.string_representation(), best_solution.fitness_value, best_solution.objective_value, best_solution.is_feasible', moments: str = 'after_algorithm')

Bases: object

This class determine where the output generated during execution of the uo.algorithm.Algorithm instance will be written

copy()

Copy the current output control

Returns:

new OutputControl instance with the same properties

Return type:

OutputControl

property fields: str

Property getter for fields_definitions property

Returns:

comma-separated string with list of fields for output

Return type:

str

property fields_definitions: list[str]

Property getter for fields_definitions property

Returns:

list of fields definitions to be evaluated during output

Return type:

list[str]

property fields_headings: list[str]

Property getter for fields_headings property

Returns:

list of fields headings for output

Return type:

list[str]

property moments: str

Property getter for moments property

Returns:

comma-separated list of moments for output

Return type:

str

property output_file: TextIOWrapper

Property getter for output file

Returns:

output file to which algorithm will write

Return type:

TextIOWrapper

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

String representation of the target solution 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

property write_after_algorithm: bool

Property getter for property write_after_algorithm

Returns:

should write to the output after algorithm execution

Return type:

bool

property write_after_evaluation: bool

Property getter for property write_after_evaluation

Returns:

should write to the output after evaluation

Return type:

bool

property write_after_iteration: bool

Property getter for property write_after_iteration

Returns:

should write to the output after algorithm iteration

Return type:

bool

property write_after_step_in_iteration: bool

Property getter for property write_after_step_in_iteration

Returns:

should write to the output after step in iteration

Return type:

bool

property write_before_algorithm: bool

Property getter for property write_before_algorithm

Returns:

should write to the output prior to algorithm execution

Return type:

bool

property write_before_evaluation: bool

Property getter for property write_before_evaluation

Returns:

should write to the output prior to evaluation

Return type:

bool

property write_before_iteration: bool

Property getter for property write_before_iteration

Returns:

should write to the output prior to algorithm iteration

Return type:

bool

property write_before_step_in_iteration: bool

Property getter for property write_before_step_in_iteration

Returns:

should write to the output prior to step in iteration

Return type:

bool

Module contents