uo.solution package
Submodules
uo.solution.distance_calculation_cache_control_statistics module
The distance_calculation_cache_control_statistics
module describes the class DistanceCalculationCacheControlStatistics
.
- class uo.solution.distance_calculation_cache_control_statistics.DistanceCalculationCacheControlStatistics(*args, **kwargs)
Bases:
Generic
[E_co
]Class that represents control statistics for solution code distance calculation cache.
- property cache: dict[E_co, E_co]
Property getter for cache
- Returns:
cache that is used during calculation for previously obtained solution code distances
- Return type:
dict[(E_co,E_co)]
- property cache_hit_count: int
Property getter for cache_hit_count
- Returns:
number of cache hits during calculation of the solution code distances
- Return type:
- property cache_request_count: int
Property getter for cache_request_count
- Returns:
overall number of calculation of the solution code distances
- Return type:
- increment_cache_hit_count() None
Increments number of cache hits during calculation of the solution code distances
- increment_cache_request_count() None
Increments overall number of calculation of the solution code distances
- 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:
- string_rep(delimiter: str, indentation: int = 0, indentation_symbol: str = '', group_start: str = '{', group_end: str = '}') str
String representation of solution distance calculation cache control statistic
- 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:
uo.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_hit_count: int
Property getter for cache_hit_count
- Returns:
number of cache hits during evaluation
- Return type:
- property cache_request_count: int
Property getter for cache_request_count
- Returns:
overall number of evaluations
- Return type:
- 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:
- 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:
uo.solution.quality_of_solution module
The quality_of_solution
module describes the class QualityOfSolution
.
- class uo.solution.quality_of_solution.QualityOfSolution(objective_value: float | None, objective_values: list[float] | tuple[float] | None, fitness_value: float | None, fitness_values: list[float] | tuple[float] | None, is_feasible: bool)
Bases:
object
- property fitness_value: float | None
Property getter for fitness value of the target solution
- Returns:
fitness value of the target solution instance
- Return type:
- property fitness_values: list[float] | tuple[float] | None
Property getter for fitness values of the target solution
- property is_feasible: bool
Property getter for feasibility of the target solution
- Returns:
feasibility of the target solution instance
- Return type:
uo.solution.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:
- 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:
- property fitness_value: float
Property getter for fitness value of the target solution
- Returns:
fitness value of the target solution instance
- Return type:
- property fitness_values: list[float] | tuple[float]
Property getter for fitness values of the target solution
- 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
- property is_feasible: bool
Property getter for feasibility of the target solution
- Returns:
feasibility of the target solution instance
- Return type:
- 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:
- property objective_values: list[float] | tuple[float]
Property getter for objective values of the target solution
- 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:
- property random_seed: int
Property getter for the random seed used during metaheuristic execution
- Returns:
random seed
- Return type:
- 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:
- 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:
- 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:
- 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:
- uo.solution.solution.random() x in the interval [0, 1).