1
|
|
|
from NiaPy.algorithms import Algorithm |
2
|
|
|
from NiaPy.algorithms import basic as basic_algorithms |
3
|
|
|
from NiaPy.algorithms import modified as modified_algorithms |
4
|
|
|
from NiaPy.algorithms import other as other_algorithms |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
class AlgorithmUtility: |
8
|
|
|
r"""Base class with string mappings to algorithms. |
9
|
|
|
|
10
|
|
|
Attributes: |
11
|
|
|
classes (Dict[str, Algorithm]): Mapping from stings to algorithms. |
12
|
|
|
|
13
|
|
|
""" |
14
|
|
|
|
15
|
|
|
def __init__(self): |
16
|
|
|
r"""Initialize the algorithms.""" |
17
|
|
|
|
18
|
|
|
self.algorithm_classes = { |
19
|
|
|
"BatAlgorithm": basic_algorithms.BatAlgorithm, |
20
|
|
|
"FireflyAlgorithm": basic_algorithms.FireflyAlgorithm, |
21
|
|
|
"DifferentialEvolution": basic_algorithms.DifferentialEvolution, |
22
|
|
|
"CrowdingDifferentialEvolution": basic_algorithms.CrowdingDifferentialEvolution, |
23
|
|
|
"AgingNpDifferentialEvolution": basic_algorithms.AgingNpDifferentialEvolution, |
24
|
|
|
"DynNpDifferentialEvolution": basic_algorithms.DynNpDifferentialEvolution, |
25
|
|
|
"MultiStrategyDifferentialEvolution": basic_algorithms.MultiStrategyDifferentialEvolution, |
26
|
|
|
"DynNpMultiStrategyDifferentialEvolution": basic_algorithms.DynNpMultiStrategyDifferentialEvolution, |
27
|
|
|
"multiMutations": basic_algorithms.multiMutations, |
28
|
|
|
"AgingNpMultiMutationDifferentialEvolution": basic_algorithms.AgingNpMultiMutationDifferentialEvolution, |
29
|
|
|
"FlowerPollinationAlgorithm": basic_algorithms.FlowerPollinationAlgorithm, |
30
|
|
|
"GreyWolfOptimizer": basic_algorithms.GreyWolfOptimizer, |
31
|
|
|
"GeneticAlgorithm": basic_algorithms.GeneticAlgorithm, |
32
|
|
|
"ArtificialBeeColonyAlgorithm": basic_algorithms.ArtificialBeeColonyAlgorithm, |
33
|
|
|
"ParticleSwarmAlgorithm": basic_algorithms.ParticleSwarmAlgorithm, |
34
|
|
|
"BareBonesFireworksAlgorithm": basic_algorithms.BareBonesFireworksAlgorithm, |
35
|
|
|
"CamelAlgorithm": basic_algorithms.CamelAlgorithm, |
36
|
|
|
"MonkeyKingEvolutionV1": basic_algorithms.MonkeyKingEvolutionV1, |
37
|
|
|
"MonkeyKingEvolutionV2": basic_algorithms.MonkeyKingEvolutionV2, |
38
|
|
|
"MonkeyKingEvolutionV3": basic_algorithms.MonkeyKingEvolutionV3, |
39
|
|
|
"EvolutionStrategy1p1": basic_algorithms.EvolutionStrategy1p1, |
40
|
|
|
"EvolutionStrategyMp1": basic_algorithms.EvolutionStrategyMp1, |
41
|
|
|
"EvolutionStrategyMpL": basic_algorithms.EvolutionStrategyMpL, |
42
|
|
|
"EvolutionStrategyML": basic_algorithms.EvolutionStrategyML, |
43
|
|
|
"CovarianceMatrixAdaptionEvolutionStrategy": basic_algorithms.CovarianceMatrixAdaptionEvolutionStrategy, |
44
|
|
|
"SineCosineAlgorithm": basic_algorithms.SineCosineAlgorithm, |
45
|
|
|
"GlowwormSwarmOptimization": basic_algorithms.GlowwormSwarmOptimization, |
46
|
|
|
"GlowwormSwarmOptimizationV1": basic_algorithms.GlowwormSwarmOptimizationV1, |
47
|
|
|
"GlowwormSwarmOptimizationV2": basic_algorithms.GlowwormSwarmOptimizationV2, |
48
|
|
|
"GlowwormSwarmOptimizationV3": basic_algorithms.GlowwormSwarmOptimizationV3, |
49
|
|
|
"HarmonySearch": basic_algorithms.HarmonySearch, |
50
|
|
|
"HarmonySearchV1": basic_algorithms.HarmonySearchV1, |
51
|
|
|
"KrillHerdV1": basic_algorithms.KrillHerdV1, |
52
|
|
|
"KrillHerdV2": basic_algorithms.KrillHerdV2, |
53
|
|
|
"KrillHerdV3": basic_algorithms.KrillHerdV3, |
54
|
|
|
"KrillHerdV4": basic_algorithms.KrillHerdV4, |
55
|
|
|
"KrillHerdV11": basic_algorithms.KrillHerdV11, |
56
|
|
|
"FireworksAlgorithm": basic_algorithms.FireworksAlgorithm, |
57
|
|
|
"EnhancedFireworksAlgorithm": basic_algorithms.EnhancedFireworksAlgorithm, |
58
|
|
|
"DynamicFireworksAlgorithm": basic_algorithms.DynamicFireworksAlgorithm, |
59
|
|
|
"DynamicFireworksAlgorithmGauss": basic_algorithms.DynamicFireworksAlgorithmGauss, |
60
|
|
|
"GravitationalSearchAlgorithm": basic_algorithms.GravitationalSearchAlgorithm, |
61
|
|
|
"MothFlameOptimizer": basic_algorithms.MothFlameOptimizer, |
62
|
|
|
"FishSchoolSearch": basic_algorithms.FishSchoolSearch, |
63
|
|
|
"CuckooSearch": basic_algorithms.CuckooSearch, |
64
|
|
|
"CoralReefsOptimization": basic_algorithms.CoralReefsOptimization, |
65
|
|
|
"ForestOptimizationAlgorithm": basic_algorithms.ForestOptimizationAlgorithm, |
66
|
|
|
"MonarchButterflyOptimization": basic_algorithms.MonarchButterflyOptimization, |
67
|
|
|
"HybridBatAlgorithm": modified_algorithms.HybridBatAlgorithm, |
68
|
|
|
"DifferentialEvolutionMTS": modified_algorithms.DifferentialEvolutionMTS, |
69
|
|
|
"DifferentialEvolutionMTSv1": modified_algorithms.DifferentialEvolutionMTSv1, |
70
|
|
|
"DynNpDifferentialEvolutionMTS": modified_algorithms.DynNpDifferentialEvolutionMTS, |
71
|
|
|
"DynNpDifferentialEvolutionMTSv1": modified_algorithms.DynNpDifferentialEvolutionMTSv1, |
72
|
|
|
"MultiStrategyDifferentialEvolutionMTS": modified_algorithms.MultiStrategyDifferentialEvolutionMTS, |
73
|
|
|
"MultiStrategyDifferentialEvolutionMTSv1": modified_algorithms.MultiStrategyDifferentialEvolutionMTSv1, |
74
|
|
|
"SelfAdaptiveDifferentialEvolution": modified_algorithms.SelfAdaptiveDifferentialEvolution, |
75
|
|
|
"DynNpSelfAdaptiveDifferentialEvolutionAlgorithm": modified_algorithms.DynNpSelfAdaptiveDifferentialEvolutionAlgorithm, |
76
|
|
|
"MultiStrategySelfAdaptiveDifferentialEvolution": modified_algorithms.MultiStrategySelfAdaptiveDifferentialEvolution, |
77
|
|
|
"AgingSelfAdaptiveDifferentialEvolution": modified_algorithms.AgingSelfAdaptiveDifferentialEvolution, |
78
|
|
|
"NelderMeadMethod": other_algorithms.NelderMeadMethod, |
79
|
|
|
"HillClimbAlgorithm": other_algorithms.HillClimbAlgorithm, |
80
|
|
|
"SimulatedAnnealing": other_algorithms.SimulatedAnnealing, |
81
|
|
|
"MultipleTrajectorySearch": other_algorithms.MultipleTrajectorySearch, |
82
|
|
|
"MultipleTrajectorySearchV1": other_algorithms.MultipleTrajectorySearchV1 |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
def get_algorithm(self, algorithm): |
86
|
|
|
r"""Get the algorithm. |
87
|
|
|
|
88
|
|
|
Arguments: |
89
|
|
|
algorithm (Union[str, Algorithm]): String or class that represents the algorithm. |
90
|
|
|
|
91
|
|
|
Returns: |
92
|
|
|
Algorithm: Instance of an Algorithm. |
93
|
|
|
""" |
94
|
|
|
|
95
|
|
|
if issubclass(type(algorithm), Algorithm): |
96
|
|
|
return algorithm |
97
|
|
|
elif algorithm in self.algorithm_classes: |
98
|
|
|
return self.algorithm_classes[algorithm]() |
99
|
|
|
else: |
100
|
|
|
raise TypeError("Passed algorithm is not defined!") |
101
|
|
|
|