Metaheuristic Algorithms API
API reference for metaheuristic algorithms in opt.metaheuristic.
Module Overview
python
from opt.metaheuristic import (
HarmonySearch,
CrossEntropy,
SineCosine,
TabuSearch,
VariableNeighborhood,
)1
2
3
4
5
6
7
2
3
4
5
6
7
Common Interface
python
class MetaheuristicAlgorithm(AbstractOptimizer):
def __init__(
self,
func: Callable,
lower_bound: float,
upper_bound: float,
dim: int,
max_iter: int,
**kwargs
):
pass
def search(self) -> tuple[np.ndarray, float]:
pass1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
Available Algorithms
HarmonySearch- Music-inspired optimizationCrossEntropy- Adaptive importance samplingSineCosine- Mathematical function-basedTabuSearch- Memory-based searchVariableNeighborhood- Local search strategy
Example Usage
python
from opt.metaheuristic import HarmonySearch, SineCosine
from opt.benchmark.functions import ackley
# Harmony Search
hs = HarmonySearch(
func=ackley,
lower_bound=-32.768,
upper_bound=32.768,
dim=10,
max_iter=100,
harmony_memory_size=30,
hmcr=0.9, # Harmony memory consideration rate
par=0.3 # Pitch adjustment rate
)
solution, fitness = hs.search()
# Sine Cosine Algorithm
sca = SineCosine(
func=ackley,
lower_bound=-32.768,
upper_bound=32.768,
dim=10,
max_iter=100,
population_size=30
)
solution, fitness = sca.search()1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
See Also
- Metaheuristic Algorithms - Algorithm details