uo.target_solution package

Submodules

uo.target_solution.evaluation_cache_control_statistics module

The evaluation_cache_control_statistics module describes the class EvaluationCacheControlStatistics.

class uo.solution.evaluation_cache_control_statistics.EvaluationCacheControlStatistics(*args, **kwargs)

Bases: object

Class that represents control statistics for evaluation caching.

property cache: dict[str]

Property getter for cache

Returns:

cache that is used during evaluation

Return type:

dict[str]

property cache_hit_count: int

Property getter for cache_hit_count

Returns:

number of cache hits during evaluation

Return type:

int

property cache_request_count: int

Property getter for cache_request_count

Returns:

overall number of evaluations

Return type:

int

increment_cache_hit_count() None

Increments number of cache hits during evaluation

increment_cache_request_count() None

Increments overall number of evaluations

property max_cache_size: int

Property getter for max_cache_size

Returns:

maximum size of the cache - if 0 cache is with unlimited size

Return type:

int

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

String representation of the EvaluationCacheControlStatistics 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.target_solution.target_solution module

The solution module describes the class Solution.

class uo.solution.solution.Solution(random_seed: int | None, fitness_value: float | int | None, fitness_values: list[float] | tuple[float] | None, objective_value: float | int | None, objective_values: list[float] | tuple[float] | None, is_feasible: bool, evaluation_cache_is_used: bool = False, evaluation_cache_max_size: int | None = None, distance_calculation_cache_is_used: bool = False, distance_calculation_cache_max_size: int | None = None)

Bases: Generic[R_co, A_co]

abstract argument(representation: R_co) A_co

Argument of the target solution

Parameters:

representation (R_co) – internal representation of the solution

Returns:

argument of the solution

Return type:

A_co

calculate_quality(problem: Problem) QualityOfSolution

Calculate fitness, objective and feasibility of the solution, with optional cache consultation

Parameters:

problem (Problem) – problem that is solved

Returns:

objective value, fitness value and feasibility of the solution instance

Return type:

QualityOfSolution

abstract calculate_quality_directly(representation: R_co, problem: Problem) QualityOfSolution

Fitness calculation of the target solution

Parameters:
  • representation (R_co) – native representation of the solution for which objective value, fitness and feasibility are calculated

  • problem (Problem) – problem that is solved

Returns:

objective value, fitness value and feasibility of the solution instance

Return type:

QualityOfSolution

abstract copy()

Copy the current target solution

Returns:

new uo.solution.Solution instance with the same properties

Return type:

Solution

copy_from(original) None

Copy all data from the original target solution

evaluate(problem: Problem) None

Evaluate current target solution

Parameters:

problem (Problem) – problem that is solved

property evaluation_cache_cs: EvaluationCacheControlStatistics | None

Property getter that returns cache for evaluation control and statistics

Returns:

cache for evaluation control and statistics

Return type:

EvaluationCacheControlStatistics

property fitness_value: float

Property getter for fitness value of the target solution

Returns:

fitness value of the target solution instance

Return type:

float

property fitness_values: list[float] | tuple[float]

Property getter for fitness values of the target solution

Returns:

fitness values of the target solution instance

Return type:

list[float]|tuple[float]

abstract init_from(representation: R_co, problem: Problem) None

Initialization of the solution, by setting its native representation

Parameters:
  • representation (R_co) – representation that will be ste to solution

  • problem (Problem) – problem which is solved by solution

abstract init_random(problem: Problem) None

Random initialization of the solution

Parameters:

problem (Problem) – problem which is solved by solution

is_better(other: Solution, problem: Problem) bool | None

Checks if this solution is better than the other, with respect to problem that is optimized

Parameters:
  • other (Solution) – other solution

  • problem (Problem) – problem to be solved

Returns:

True if first is better, False if first is worse, None if quality of both solutions are equal

Return type:

bool

property is_feasible: bool

Property getter for feasibility of the target solution

Returns:

feasibility of the target solution instance

Return type:

bool

abstract native_representation(representation_str: str) R_co

Obtain native representation from solution code of the Solution instance

Parameters:

representation_str (str) – solution’s representation as string (e.g. solution code)

Returns:

solution’s native representation

Return type:

R_co

property objective_value: float

Property getter for objective value of the target solution

Returns:

objective value of the target solution instance

Return type:

float

property objective_values: list[float] | tuple[float]

Property getter for objective values of the target solution

Returns:

objective values of the target solution instance

Return type:

list[float]|tuple[float]

obtain_feasible_representation(problem: Problem) R_co
property quality: QualityOfSolution

Property getter for the quality of the target solution

Returns:

quality of the target solution, in the single-objective optimization context

Return type:

QualityOfSolution

property random_seed: int

Property getter for the random seed used during metaheuristic execution

Returns:

random seed

Return type:

int

property representation: R_co

Property getter for representation of the target solution

Returns:

representation of the target solution instance

Return type:

R_co

representation_distance(representation_1: R_co, representation_2: R_co) float

Calculate distance between two native representations, with optional cache consultation

Parameters:
  • representation_1 (R_co) – native representation for the first solution

  • representation_2 (R_co) – native representation for the second solution

Returns:

distance

Return type:

float

property representation_distance_cache_cs: DistanceCalculationCacheControlStatistics | None

Property getter that returns cache for distance calculation control and statistics

Returns:

cache for distance calculation control and statistics

Return type:

DistanceCalculationCacheControlStatistics

abstract representation_distance_directly(representation_1: R_co, representation_2: R_co) float

Directly calculate distance between two solutions determined by its native representations

Parameters:
  • representation_1 (R_co) – native representation for the first solution

  • representation_2 (R_co) – native representation for the second solution

Returns:

distance

Return type:

float

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

string_representation() str

String representation of the target solution

Parameters:

representation (R_co) – internal representation of the solution

Returns:

string representation of the solution

Return type:

str

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

Module contents