pymetaheuristic: A Python Library for Metaheuristic Optimization and Collaborative Search
Project description
pymetaheuristic
A Python library for metaheuristic optimization and collaborative search, bringing together 374 optimization algorithms across swarm, evolutionary, trajectory, physics-inspired, nature-inspired, human-inspired, and mathematical families. pymetaheuristic makes metaheuristics observable, comparable, cooperative, and benchmarkable through single optimizers, island systems, adaptive orchestration, diagnostics, and scientific benchmark studies.
A. Version Note
This README targets pymetaheuristic-v5+. It can be installed with:
pip install pymetaheuristic
For legacy, the old library can still be installed with:
pip install pymetaheuristic==1.9.5
B. pymetaheuristic Lab
New to Python or prefer a graphical interface? The pymetaheuristic Lab provides a convenient Web App to run optimizations without writing extensive code.
import pymetaheuristic
# Start the web service using:
pymetaheuristic.web_app()
# Terminate the web service using:
pymetaheuristic.web.web_stop()
This Google Colab Demo is intended for quick demos only. For the best experience, run the Web UI locally or open it directly in a full browser.
C. Summary
- Introduction
- Installation and Package Overview
- 2.1 Installation
- 2.2 Package Overview
- 2.3 Optimization, Telemetry, Export, and Plotting Example --- [Colab Demo] ---
- 2.4 Termination Criteria --- [Colab Demo] ---
- 2.5 Constraint Handling Example --- [Colab Demo] ---
- 2.6 Cooperative Multi-island Example --- [Colab Demo] ---
- 2.7 Orchestrated Cooperation Example --- [Colab Demo] ---
- 2.8 Island System Unified Interface --- [Colab Demo] ---
- 2.9 Adaptive Orchestration Policies
- 2.10 Chaotic Maps and Transfer Functions --- [Colab Demo] ---
- 2.11 Hyperparameter Tuner --- [Colab Demo] ---
- 2.12 Save, Load, and Checkpoint --- [Colab Demo] ---
- 2.13 Benchmark Runner --- [Colab Demo] ---
- 2.14 Benchmark Study --- [Colab Demo] ---
- Algorithm Details
- Test Functions --- [Colab Demo] ---
- Other Libraries
1. Introduction
pymetaheuristic is a Python optimization library built around metaheuristics, benchmark functions, stepwise execution, telemetry, cooperation, rule-based orchestration, constraint-aware evaluation, composable termination criteria, typed variable spaces, chaotic initialization, transfer functions, hyperparameter tuning, and benchmark sweeps. The package provides:
- a broad collection of metaheuristic algorithms
- benchmark functions for testing and visualization
- a stepwise engine API for controlled execution
- telemetry, export helpers, evaluation-indexed convergence data, and save/load for experiments
- cooperative multi-island optimization through
cooperative_optimize - clean object-based island systems through
IslandSystem,Island,TopologyConfig, andMigrationConfig - adaptive orchestration through fixed, rule-based, bandit, and portfolio-adaptive controllers
- island diagnostics, including migration matrices, contribution tables, island roles, action effectiveness, and topology summaries
- built-in constrained optimization support plus named repair strategies (
clip,wang,reflect,rand,limit_inverse) - composable
Terminationobject with four independent stopping conditions - automatic per-step diversity and exploration/exploitation tracking in history
- plotly-based diversity, convergence, runtime, and explore/exploit charts, including evaluation-indexed convergence plots
- typed variable space (
FloatVar,IntegerVar,CategoricalVar,PermutationVar,BinaryVar) - ten chaotic maps plus
lhs,obl, andsobolpopulation initialization presets - eight transfer functions and
BinaryAdapterfor binary/discrete optimization HyperparameterTunerfor grid/random hyperparameter searchBenchmarkRunnerfor lightweight multi-algorithm × multi-problem sweepsBenchmarkStudyfor scientific benchmarking of algorithms, island systems, and orchestration controllers, with rank tables, statistical tests, convergence plots, ECDFs, performance profiles, and result persistencesave_result,load_result,save_checkpoint,load_checkpointfor persistence- callback system with lifecycle hooks and callback-driven early stopping
- object-based
ProblemAPI with parametrized bounds,latex_code(), and curated test-problem wrappers - reusable
levy_flight()utility and human-readablealgorithm.info()metadata
2. Installation and Package Overview
2.1 Installation
Standard installation:
pip install pymetaheuristic
2.2 Package Overview
| Area | Main objects / functions | What it covers |
|---|---|---|
| Core Optimization | optimize, list_algorithms, get_algorithm_info, create_optimizer |
Single-algorithm optimization, algorithm discovery, and inspection of default parameters |
| Termination | Termination, EarlyStopping, callbacks |
Composable stopping criteria: max_steps, max_evaluations, max_time, max_early_stop, target_fitness, and callback-driven stops |
| Constraints and Feasibility | optimize(..., constraints=..., constraint_handler=...) |
Constrained optimization with inequality/equality constraints, feasibility-aware evaluation |
| Benchmarks and Plots (Plotly) | FUNCTIONS, get_test_function, plot_function, plot_convergence, compare_convergence, plot_benchmark_summary, plot_island_dynamics, plot_collaboration_network, plot_population_snapshot |
Built-in benchmark functions and plotly-based landscape, convergence, and cooperation visualizations |
| History Charts (Plotly) | plot_global_best_chart, plot_diversity_chart, plot_explore_exploit_chart, plot_runtime_chart, plot_run_dashboard, plot_diversity_comparison |
Per-step diversity, exploration/exploitation, runtime, and convergence charts using plotly |
| Telemetry and Export | summarize_result, export_history_csv, export_population_snapshots_json, convergence_data |
Experiment summarization, evaluation-indexed convergence extraction, and export of history and snapshots |
| IO (Persistence) | save_result, load_result, save_checkpoint, load_checkpoint, result_to_json, result_from_json |
Save and restore results; checkpoint-and-resume for long runs |
| Typed Variable Space | FloatVar, IntegerVar, BinaryVar, CategoricalVar, PermutationVar, build_problem_spec, decode_position, encode_position |
Define mixed-type search spaces; automatic encode/decode to/from continuous representation |
| Problem Objects | Problem, FunctionalProblem, SphereProblem, RastriginProblem, AckleyProblem, RosenbrockProblem, ZakharovProblem, get_test_problem |
N-dimensional object-based problem definitions with parametrized bounds and latex_code() |
| Chaotic Maps | ChaoticMap, chaotic_sequence, chaotic_population, AVAILABLE_CHAOTIC_MAPS |
Ten chaotic maps for diversity-preserving population initialisation and perturbation |
| Initialisation Presets | uniform_population, lhs_population, obl_population, sobol_population, get_init_function, AVAILABLE_INIT_STRATEGIES |
Composable initialisation strategies for any algorithm through init_function= or init_name= |
| Transfer Functions | apply_transfer, binarize, BinaryAdapter, vstf_01–vstf_04, sstf_01–sstf_04, AVAILABLE_TRANSFER_FUNCTIONS |
Eight transfer functions mapping continuous positions to binary probabilities for binary optimization |
| Repair and Random Utilities | limit, limit_inverse, wang, rand, reflect, get_repair_function, levy_flight |
Named bound-repair policies and a reusable Lévy-flight sampler |
| Hyperparameter Tuner | HyperparameterTuner |
Grid or random search over algorithm hyperparameters across multiple trials |
| Benchmark Runner | BenchmarkRunner |
Lightweight multi-algorithm × multi-problem sweeps with summary aggregation and plotly-based benchmark charts |
| Benchmark Study | BenchmarkStudy, BenchmarkResult, BenchmarkProblem, ProblemSuite, ExperimentRecord, load_benchmark |
Scientific benchmarking of algorithms, island systems, and orchestration controllers with long-format records, ranks, statistical tests, convergence plots, ECDFs, performance profiles, rank heatmaps, and JSON persistence |
| Cooperation | cooperative_optimize, replay_cooperative_result, IslandSystem, Island, TopologyConfig, MigrationConfig, ExecutionConfig |
Direct and object-based multi-island cooperative optimization with configurable topology, migration interval, migration size, and migration policy |
| Orchestration | orchestrated_optimize, OrchestrationSpec, CollaborativeConfig, RulesConfig, BanditConfig, PortfolioConfig, OrchestrationConfig |
Checkpoint-driven cooperation with fixed, rule-based, bandit, and portfolio-adaptive orchestration |
| Island Diagnostics | migration_matrix, topology_summary, island_contribution, island_roles, action_effectiveness, diagnostics_summary |
Post-run interpretation of island systems, including communication patterns, donor/receiver behavior, island roles, and controller action effectiveness |
| Reference | print_root_exports, print_reference, search_reference |
Programmatic argument reference for all callables |
To quickly inspect parameters:
import pymetaheuristic
# List
pymetaheuristic.print_root_exports()
# Detail
pymetaheuristic.print_reference("optimize")
2.3 Optimization, Telemetry, Export, and Plotting Example
optimize is the main high-level entry point for running a single metaheuristic on a user-defined objective function. The user specifies the algorithm, search bounds, and computational budget, while optional keyword arguments configure the selected optimizer and control diagnostics, such as history storage and population snapshots. The function returns a structured result object containing the best solution found, its objective value, and optional run traces that can later be summarized, exported, or plotted. In the example below, optimize applies Particle Swarm Optimization (PSO) to the Easom function over a bounded two-dimensional domain, stores the optimization trajectory, and then summarizes the run with summarize_result.
When store_history and store_population_snapshots are enabled, the returned result object contains enough information to support post-run analysis, reproducibility, and visualization. The history can be exported as a tabular CSV file, population states can be saved as JSON snapshots for later inspection, and convergence can be visualized directly with the built-in plotting utilities. In the example below, PSO is applied to the Sphere function, the optimization trace is exported to disk, and the convergence behavior is plotted for immediate inspection.
import numpy as np
import pymetaheuristic
# To use a built-in test function instead, uncomment the next line:
# easom = pymetaheuristic.get_test_function("easom")
# Or define your own objective function.
# The input must be a list (or array-like) of variable values,
# and its length corresponds to the problem dimension.
def easom(x = [0, 0]):
x1, x2 = x
return -np.cos(x1) * np.cos(x2) * np.exp(-(x1 - np.pi) ** 2 - (x2 - np.pi) ** 2)
result = pymetaheuristic.optimize(
algorithm = "pso",
target_function = easom,
min_values = (-5, -5),
max_values = ( 5, 5),
max_steps = 30,
seed = 42,
store_history = True,
store_population_snapshots = True,
)
print(result.best_fitness)
print(len(result.history))
print(pymetaheuristic.summarize_result(result))
pymetaheuristic.export_history_csv(result, "population_history.csv")
pymetaheuristic.export_population_snapshots_json(result, "population_snapshots.json")
fig = pymetaheuristic.plot_convergence(result)
2.4 Termination Criteria
Termination is a composable stopping-criteria object that replaces (or extends) the individual max_steps, max_evaluations, target_fitness, and timeout_seconds keyword arguments. The first condition that triggers ends the run.
Four independent condition types are supported:
- MG (
max_steps): maximum number of macro-steps / iterations. - FE (
max_evaluations): maximum number of objective-function evaluations. - TB (
max_time): wall-clock time bound in seconds. - ES (
max_early_stop): early stopping — halt if the global best has not improved by more thanepsilonfor this many consecutive steps.
import numpy as np
import pymetaheuristic
def easom(x = [0, 0]):
x1, x2 = x
return -np.cos(x1) * np.cos(x2) * np.exp(-(x1 - np.pi) ** 2 - (x2 - np.pi) ** 2)
# Build a composable termination with multiple conditions
# The run stops as soon as ANY condition is triggered.
term = pymetaheuristic.Termination(
max_steps = 1000,
max_evaluations = 50000,
max_time = 30.0, # 30-second wall-clock limit
max_early_stop = 25, # stop if no improvement for 25 steps
epsilon = 1e-8,
)
result = pymetaheuristic.optimize(
algorithm = "pso",
target_function = easom,
min_values = (-5, -5),
max_values = ( 5, 5),
termination = term,
seed = 42,
)
print(f"Best fitness: {result.best_fitness:.6f}")
print(f"Steps run: {result.steps}")
print(f"Evaluations: {result.evaluations}")
print(f"Termination reason: {result.termination_reason}")
2.5 Constraint Handling Example
This example illustrates how optimize can be applied to constrained optimization problems. The user provides one or more constraint functions alongside the objective, and the solver evaluates candidate solutions by combining objective quality with constraint satisfaction according to the selected handling strategy. In this case, the "deb" constraint handler applies feasibility-based comparison rules, so feasible solutions are preferred over infeasible ones, and among infeasible candidates, those with smaller violations are favored. The returned result, therefore, includes not only the best position and penalized search outcome but also metadata describing the raw objective value, the magnitude of constraint violation, and whether the final solution is feasible.
import pymetaheuristic
# ─────────────────────────────────────────────────────────────────────────────
# Variables: 1) wire diameter d, 2) mean coil diameter D, 3) number of coils N
# Solution: f* ≈ 0.012665
# ─────────────────────────────────────────────────────────────────────────────
def tension_spring(x = [0, 0, 0]):
d, D, N = x[0], x[1], x[2]
return (N + 2) * D * d**2
constraints = [
lambda x: 1 - (x[1]**3 * x[2]) / (71785 * x[0]**4),
lambda x: (4*x[1]**2 - x[0]*x[1]) / (12566*(x[1]*x[0]**3 - x[0]**4)) + 1/(5108*x[0]**2) - 1,
lambda x: 1 - 140.45*x[0] / (x[1]**2 * x[2]),
lambda x: (x[0] + x[1]) / 1.5 - 1,
]
result = pymetaheuristic.optimize(
algorithm = "pso",
target_function = tension_spring,
min_values = (0.05, 0.25, 2.0),
max_values = (2.00, 1.30, 15.0),
constraints = constraints,
constraint_handler = "deb",
max_steps = 2500,
seed = 42,
)
print(result.best_position)
print(result.best_fitness)
print(result.metadata["best_raw_fitness"])
print(result.metadata["best_violation"])
print(result.metadata["best_is_feasible"])
Other constraints examples:
constraint = [lambda x: x[0] + x[1] - 1.0] # x0 + x1 <= 1
constraints = [
lambda x: x[0]**2 + x[1]**2 - 4.0, # x0^2 + x1^2 <= 4
lambda x: -x[0], # x0 >= 0
lambda x: -x[1], # x1 >= 0
lambda x: x[2] - 5.0, # x2 <= 5
lambda x: 2.0 - x[2], # x2 >= 2
lambda x: abs(x[0] - x[1]) - 0.5, # |x0 - x1| <= 0.5
lambda x: max(x[0], x[1]) - 3.0, # max(x0, x1) <= 3
lambda x: x[0]*x[1] - 2.0, # x0*x1 <= 2
lambda x: np.sin(x[0]) + x[1] - 1.5, # sin(x0) + x1 <= 1.5
lambda x: {"type": "eq", "value": x[0] - x[1]} # x0 = x1
]
def c1(x):
return x[0] + x[1] - 1.0 # x0 + x1 <= 1
def c2(x):
return -x[0] # x0 >= 0
def c3(x):
return {"type": "eq", "value": x[0] - x[1]} # x0 = x1
constraints = [c1, c2, c3]
2.6 Cooperative Multi-island Example
cooperative_optimize extends the framework from single-optimizer execution to a collaborative multi-island setting, where several heterogeneous metaheuristics explore the same search space in parallel and periodically exchange information. This interface is useful when the user wants to combine complementary search behaviors—for example, swarm-based, evolutionary, and trajectory-based methods—within a single optimization run. The migration mechanism controls when candidate solutions are shared, how many are transferred, and how communication is structured through a topology such as a ring. In the example below, PSO, GA, SA, and ABCO are executed as cooperating islands on the Easom function, with periodic migration events that allow promising solutions discovered by one method to influence the others.
import numpy as np
import pymetaheuristic
def easom(x = [0, 0]):
x1, x2 = x
return -np.cos(x1) * np.cos(x2) * np.exp(-(x1 - np.pi) ** 2 - (x2 - np.pi) ** 2)
result = pymetaheuristic.cooperative_optimize(
islands = [
{"algorithm": "pso", "config": {"swarm_size": 25}},
{"algorithm": "ga", "config": {}},
{"algorithm": "sa", "config": {"temperature_iterations": 20}},
{"algorithm": "abco", "config": {}},
],
target_function = easom,
min_values = (-5, -5),
max_values = ( 5, 5),
max_steps = 20,
migration_interval = 5,
migration_size = 2,
topology = "ring",
seed = 42,
)
print(result.best_fitness)
print(len(result.events))
2.7 Orchestrated Cooperation Example
orchestrated_optimize adds an adaptive decision layer atop cooperative multi-island optimization. Instead of relying only on fixed migration schedules, the run is periodically inspected at predefined checkpoints, and an orchestration policy decides whether corrective actions such as rebalancing, perturbation, restarting, or waiting should be applied. This interface is useful when the user wants cooperation to become state-aware and responsive to signals such as stagnation, loss of diversity, or uneven progress across islands. In the example below, PSO, GA, and SA cooperate on the Easom function under a rule-based orchestration policy, and the resulting object records not only the best solution found but also the sequence of checkpoints and the decisions taken during the run.
import numpy as np
import pymetaheuristic
def easom(x = [0, 0]):
x1, x2 = x
return -np.cos(x1) * np.cos(x2) * np.exp(-(x1 - np.pi) ** 2 - (x2 - np.pi) ** 2)
config = pymetaheuristic.CollaborativeConfig(
orchestration = pymetaheuristic.OrchestrationSpec(
mode = "rules",
checkpoint_interval = 5,
max_actions_per_checkpoint = 2,
warmup_checkpoints = 1,
),
rules = pymetaheuristic.RulesConfig(
stagnation_threshold = 4,
low_diversity_threshold = 0.05,
high_diversity_threshold = 0.25,
perturbation_sigma = 0.05,
),
)
result = pymetaheuristic.orchestrated_optimize(
islands = [
{"label": "pso", "algorithm": "pso", "config": {"swarm_size": 20}},
{"label": "ga", "algorithm": "ga", "config": {"population_size": 20}},
{"label": "sa", "algorithm": "sa", "config": {"temperature": 10.0}},
],
target_function = easom,
min_values = (-5, -5),
max_values = ( 5, 5),
max_steps = 20,
seed = 42,
config = config,
)
print(result.best_fitness)
print(len(result.checkpoints))
print(len(result.decisions))
2.8 Island System Unified Interface
IslandSystem is the object-based interface for defining collaborative optimization systems. It wraps the direct APIs cooperative_optimize and orchestrated_optimize into a cleaner architecture where islands, topology, migration, orchestration, and execution settings are declared as reusable configuration objects. This interface is recommended when the same island portfolio must be reused across cooperative, rule-based, bandit, portfolio-adaptive, or benchmarked runs.
import numpy as np
import pymetaheuristic
def easom(x = [0, 0]):
x1, x2 = x
return -np.cos(x1) * np.cos(x2) * np.exp(-(x1 - np.pi) ** 2 - (x2 - np.pi) ** 2)
system = pymetaheuristic.IslandSystem(
islands = [
pymetaheuristic.Island(
label = "pso_explorer",
algorithm = "pso",
role = "explorer",
config = {"swarm_size": 25},
),
pymetaheuristic.Island(
label = "ga_diversity",
algorithm = "ga",
role = "diversity_keeper",
config = {"population_size": 30},
),
pymetaheuristic.Island(
label = "sa_refiner",
algorithm = "sa",
role = "local_refiner",
config = {"temperature": 10.0},
),
pymetaheuristic.Island(
label = "abco_explorer",
algorithm = "abco",
role = "swarm_explorer",
config = {},
),
],
topology = pymetaheuristic.TopologyConfig(name = "ring",),
migration = pymetaheuristic.MigrationConfig(
interval = 5,
size = 2,
mode = "elite",
policy = "push",
),
orchestration = pymetaheuristic.OrchestrationConfig(
checkpoint_interval = 5,
warmup_checkpoints = 1,
max_actions_per_checkpoint = 2,
),
rules = pymetaheuristic.RulesConfig(
stagnation_threshold = 4,
low_diversity_threshold = 0.05,
high_diversity_threshold = 0.25,
perturbation_sigma = 0.05,
),
objective = "min",
max_steps = 250,
seed = 42,
)
result = system.optimize(
target_function = easom,
min_values = (-5, -5),
max_values = ( 5, 5),
mode = "cooperative",
)
print(result.best_fitness)
print(result.best_position)
print(len(result.events))
Island diagnostics transform cooperative and orchestrated runs into interpretable collaborative-search reports. After a run, the result object can summarize migration flows, topology structure, island contributions, island roles, and the effectiveness of orchestration actions. These diagnostics are useful for understanding whether cooperation helped, which island acted as the best refiner, which island donated useful candidates, and whether adaptive interventions were beneficial.
import pandas as pd
# Migration matrix: how many candidates moved between islands.
migration_df = pd.DataFrame(result.migration_matrix(value = "migrants")).fillna(0)
print(migration_df)
# Contribution table: final fitness, improvement, donor/receiver behavior.
contribution_df = pd.DataFrame(result.island_contribution()).T
print(contribution_df)
# Interpretable island roles.
roles_df = pd.DataFrame(result.island_roles()).T
print(roles_df)
# Topology and communication summary.
topology = result.topology_summary()
print(topology)
# Action effectiveness for cooperative migration or orchestrated decisions.
actions = result.action_effectiveness()
print(actions)
Diagnostic plots are also available:
result.plot_migration_network(value = "migrants", show = True, renderer = "colab")
result.plot_island_fitness(show = True, renderer = "colab")
2.9 Adaptive Orchestration Policies
The orchestration layer supports multiple coordination policies. The "cooperative" mode uses fixed migration, "rules" applies checkpoint-based rules, "bandit" uses a multi-armed bandit controller to select actions based on previous rewards, and "portfolio_adaptive" changes behavior according to the optimization phase and island-state indicators.
import numpy as np
import pymetaheuristic
def easom(x = [0, 0]):
x1, x2 = x
return -np.cos(x1) * np.cos(x2) * np.exp
system = pymetaheuristic.IslandSystem(
islands=[
{"label": "pso", "algorithm": "pso", "config": {"swarm_size": 25}},
{"label": "ga", "algorithm": "ga", "config": {"population_size": 30}},
{"label": "sa", "algorithm": "sa", "config": {"temperature": 10.0}},
],
max_steps = 250,
seed = 42,
)
modes = ["cooperative", "rules", "bandit", "portfolio_adaptive"]
results = {}
for mode in modes:
results[mode] = system.optimize(
target_function = easom,
min_values = (-5, -5),
max_values = ( 5, 5),
mode = mode,
)
for mode, res in results.items():
print(mode,
"best_fitness = ", res.best_fitness,
"events = ", len(getattr(res, "events", []) or []),
"checkpoints = ", len(getattr(res, "checkpoints", []) or []),
"decisions = ", len(getattr(res, "decisions", []) or []),
)
Bandit orchestration can be configured explicitly:
config = pymetaheuristic.CollaborativeConfig(
orchestration = pymetaheuristic.OrchestrationSpec(
mode = "bandit",
checkpoint_interval = 5,
max_actions_per_checkpoint = 2,
warmup_checkpoints = 1,
),
rules = pymetaheuristic.RulesConfig(
stagnation_threshold = 3,
low_diversity_threshold = 0.10,
perturbation_sigma = 0.05,
),
bandit = pymetaheuristic.BanditConfig(
policy = "ucb",
exploration = 0.5,
action_cost_penalty = 0.05,
),
)
result = pymetaheuristic.orchestrated_optimize(
islands = [
{"label": "pso", "algorithm": "pso", "config": {"swarm_size": 25}},
{"label": "ga", "algorithm": "ga", "config": {"population_size": 30}},
{"label": "sa", "algorithm": "sa", "config": {"temperature": 10.0}},
],
target_function = easom,
min_values = (-5, -5),
max_values = ( 5, 5),
max_steps = 25,
seed = 42,
config = config,
)
print(result.best_fitness)
print(result.action_effectiveness())
2.10 Chaotic Maps and Transfer Functions
Chaotic maps are initializations based on deterministic chaotic sequences that improve early population diversity and help avoid premature convergence. Ten maps are available: logistic, tent, bernoulli, chebyshev, circle, cubic, icmic, piecewise, sine, gauss. The default for population initialization is random. Transfer functions map continuous positions to bit-flip probabilities, enabling any continuous metaheuristic to solve binary or Boolean problems. Four V-shaped (v1–v4) and four S-shaped (s1–s4) functions are available. BinaryAdapter wraps any algorithm and automatically applies the transfer function.
import itertools
import numpy as np
import pymetaheuristic
# Knapsack Instance
weights = np.array([23, 31, 29, 44, 53, 38, 63, 85, 89, 82], dtype = int)
values = np.array([92, 57, 49, 68, 60, 43, 67, 84, 87, 72], dtype = int)
capacity = 165
n_items = len(weights)
# Known Optimum
# x = [1, 1, 1, 1, 0, 1, 0, 0, 0, 0]
# profit = 309
# weight = 165
# Target Function:
def knapsack(bits):
bits = np.asarray(bits, dtype = int)
total_w = np.sum(weights * bits)
total_v = np.sum(values * bits)
if total_w > capacity:
return 1000.0 + (total_w - capacity)
return -float(total_v)
# Optimize
engine = pymetaheuristic.create_optimizer(
algorithm = "ga",
target_function = knapsack,
min_values = [0.0] * n_items,
max_values = [1.0] * n_items,
population_size = 15,
max_steps = 300,
seed = 42,
init_name = "chaotic:tent",
)
# Results
adapter = pymetaheuristic.BinaryAdapter(engine, transfer_fn = "v2")
result = adapter.run()
found_profit = -result.best_fitness
print("\nMetaheuristic result")
print("Best profit:", found_profit)
print("Binary solution reported:", result.metadata.get("binary_best_position"))
2.11 Hyperparameter Tuner
HyperparameterTuner performs grid or random search over an algorithm's hyperparameters. It runs each configuration for n_trials independent trials, aggregates results, and returns a DataFrame (if pandas is available) or a list of dicts. The best_params and best_fitness attributes summarise the optimal configuration found.
import numpy as np
import pymetaheuristic
def easom(x = [0, 0]):
x1, x2 = x
return -np.cos(x1) * np.cos(x2) * np.exp(-(x1 - np.pi) ** 2 - (x2 - np.pi) ** 2)
tuner = pymetaheuristic.HyperparameterTuner(
algorithm = "pso",
param_grid = {
"swarm_size": [20, 50, 100],
"w": [0.4, 0.7, 0.9],
"c1": [1.5, 2.0],
"c2": [1.5, 2.0],
"init_name": ["uniform", "chaotic:tent"],
},
target_function = easom,
min_values = [-5, -5],
max_values = [ 5, 5],
termination = pymetaheuristic.Termination(max_steps = 200),
n_trials = 5,
objective = "min",
seed = 42,
search = "grid",
)
df = tuner.run()
summary = tuner.summary()
print(f"Best params: {tuner.best_params}")
print(f"Best fitness: {tuner.best_fitness:.6f}")
print(summary.head())
2.12 Save, Load, and Checkpoint
The IO module provides a set of functions for persisting results and resuming interrupted runs.
save_result/load_result: pickle a completedOptimizationResultto disk.result_to_json/result_from_json: export a human-readable JSON summary.save_checkpoint/load_checkpoint: pickle a running(engine, state)pair; resume by callingengine.step(state)in a loop.
import numpy as np
import pymetaheuristic
# Easom:
def easom(x = [0, 0]):
x1, x2 = x
return -np.cos(x1) * np.cos(x2) * np.exp(-(x1 - np.pi)**2 - (x2 - np.pi)**2)
# Optimize - Run
result = pymetaheuristic.optimize(
algorithm = 'pso',
target_function = easom,
min_values = (-5, -5),
max_values = ( 5, 5),
max_steps = 25, # iterations
seed = 42,
store_history = True,
store_population_snapshots = True,
)
# Save & Load a Completed Result
pymetaheuristic.save_result(result, "easom_ga.pkl")
r2 = pymetaheuristic.load_result("easom_ga.pkl")
print(f"Reloaded best fitness: {r2.best_fitness:.6f}")
print(f"Reloaded best position: {r2.best_position}")
# Export and Read a JSON Summary
pymetaheuristic.result_to_json(result, "easom_ga.json")
summary = pymetaheuristic.result_from_json("easom_ga.json")
print(f"JSON best_fitness: {summary['best_fitness']}")
print(f"JSON best_position: {summary['best_position']}")
# Checkpoint and Resume
engine = pymetaheuristic.create_optimizer(
algorithm = algorithm_id,
target_function = easom,
min_values = (-5, -5),
max_values = ( 5, 5),
max_steps = 25, # iterations
seed = 42,
store_history = True,
store_population_snapshots = True,
)
state = engine.initialize()
# Run
for _ in range(0, 100):
state = engine.step(state)
pymetaheuristic.save_checkpoint(engine, state, "easom_checkpoint.pkl")
print(f"Checkpoint saved at step {state.step}, best = {state.best_fitness:.6f}")
# Resume from Checkpoint
engine2, state2 = pymetaheuristic.load_checkpoint("easom_checkpoint.pkl")
while not engine2.should_stop(state2):
state2 = engine2.step(state2)
result_resumed = engine2.finalize(state2)
print(f"Resumed best fitness: {result_resumed.best_fitness:.6f}")
print(f"Resumed best position: {result_resumed.best_position}")
2.13 Benchmark Runner
BenchmarkRunner is the lightweight benchmark interface for multi-algorithm × multi-problem comparative sweeps. It executes every algorithm on every problem for a configurable number of independent trials, records the best fitness and wall-clock time for each run, and captures failed trials without interrupting the sweep. The raw results are returned as a tidy DataFrame that can be aggregated into summary statistics, rank tables, and publication-quality compact tables. For a more complete scientific benchmarking workflow involving algorithms, island systems, orchestration controllers, statistical tests, convergence plots, ECDFs, performance profiles, and persistence, use BenchmarkStudy.
import pandas as pd
import pymetaheuristic
# Algorithms
algorithms = ["acgwo", "gwo", "i_gwo", "fox", "tlbo"]
# Problems
rastrigin = pymetaheuristic.get_test_function("rastrigin")
rosenbrock = pymetaheuristic.get_test_function("rosenbrocks_valley")
problems = [
{
"name": "Rastrigin-5D",
"target_function": rastrigin,
"min_values": [-5.12] * 5,
"max_values": [ 5.12] * 5,
"objective": "min",
},
{
"name": "Rosenbrock-5D",
"target_function": rosenbrock,
"min_values": [-30.0] * 5,
"max_values": [ 30.0] * 5,
"objective": "min",
},
]
# Runner
termination = pymetaheuristic.Termination(max_steps = 250)
runner = pymetaheuristic.BenchmarkRunner(
algorithms = algorithms,
problems = problems,
termination = termination,
n_trials = 5,
seed = 42,
n_jobs = 1,
)
raw_df = runner.run(show_progress = True)
# Raw Results
failed_df = raw_df[raw_df["error"].notna()].copy()
valid_df = raw_df[raw_df["error"].isna()].copy()
summary_df = runner.summary().copy()
# Rank Table
rank_table = summary_df.pivot(index = "algorithm", columns = "problem", values = "rank")
rank_table["average_rank"] = rank_table.mean(axis = 1)
rank_table = rank_table.sort_values("average_rank")
2.14 Benchmark Study
BenchmarkStudy is the scientific benchmarking interface. Unlike BenchmarkRunner, which focuses on lightweight algorithm sweeps, BenchmarkStudy can compare ordinary algorithms, island systems, and orchestration controllers under the same experimental protocol. It stores long-format experiment records, supports repeated trials, computes rank tables and statistical tests, and provides benchmark plots such as convergence curves, ECDFs, performance profiles, and rank heatmaps.
import pymetaheuristic
# Benchmark problems.
problems = pymetaheuristic.ProblemSuite.from_names(["sphere", "rastrigin", "ackley", "rosenbrock"], dimensions = 2)
system = pymetaheuristic.IslandSystem(
islands = [
pymetaheuristic.Island(
label = "pso_explorer",
algorithm = "pso",
role = "explorer",
config = {"swarm_size": 25},
),
pymetaheuristic.Island(
label = "ga_diversity",
algorithm = "ga",
role = "diversity_keeper",
config = {"population_size": 30},
),
pymetaheuristic.Island(
label = "sa_refiner",
algorithm = "sa",
role = "local_refiner",
config = {"temperature": 10.0},
),
pymetaheuristic.Island(
label = "abco_explorer",
algorithm = "abco",
role = "swarm_explorer",
config = {},
),
],
topology = pymetaheuristic.TopologyConfig(name = "ring",),
migration = pymetaheuristic.MigrationConfig(
interval = 5,
size = 2,
mode = "elite",
policy = "push",
),
orchestration = pymetaheuristic.OrchestrationConfig(
checkpoint_interval = 5,
warmup_checkpoints = 1,
max_actions_per_checkpoint = 2,
),
rules = pymetaheuristic.RulesConfig(
stagnation_threshold = 4,
low_diversity_threshold = 0.05,
high_diversity_threshold = 0.25,
perturbation_sigma = 0.05,
),
objective = "min",
max_steps = 250,
seed = 42,
)
benchmark_system_rules = {"type": "island_system", "name": "islands_rules", "system": system, "mode": "rules",}
benchmark_system_bandit = {"type": "island_system", "name": "islands_bandit", "system": system, "mode": "bandit",}
benchmark_system_portfolio = {"type": "island_system", "name": "islands_portfolio_adaptive", "system": system, "mode": "portfolio_adaptive",}
study = pymetaheuristic.BenchmarkStudy(
candidates = [
{
"name": "pso",
"type": "algorithm",
"algorithm": "pso",
"config": {"swarm_size": 30},
},
{
"name": "ga",
"type": "algorithm",
"algorithm": "ga",
"config": {"population_size": 40},
},
{
"name": "de",
"type": "algorithm",
"algorithm": "de",
"config": {"population_size": 40},
},
benchmark_system_rules,
benchmark_system_bandit,
benchmark_system_portfolio,
],
problems = problems,
n_trials = 5,
max_evaluations = 5000,
seed = 42,
)
benchmark_result = study.run()
# Long-format experiment table.
df = benchmark_result.to_dataframe()
print(df.head())
# Summary and ranking.
print(benchmark_result.summary())
print(benchmark_result.rank_table())
print(benchmark_result.scientific_summary())
# Statistical tests.
print(benchmark_result.friedman_test())
print(benchmark_result.wilcoxon_pairwise())
# Save and reload.
benchmark_result.save("benchmark_demo.json")
loaded = pymetaheuristic.load_benchmark("benchmark_demo.json")
print(loaded.summary())
Benchmark plots:
benchmark_result.plot_convergence(show = True, renderer = "colab")
benchmark_result.plot_ecdf(show = True, renderer = "colab")
benchmark_result.plot_performance_profile(show = True, renderer = "colab")
benchmark_result.plot_rank_heatmap(show = True, renderer = "colab")
Use BenchmarkRunner when you want a quick multi-algorithm × multi-problem sweep and a compact DataFrame summary. Use BenchmarkStudy when you need a scientific experimental protocol with repeated trials, fixed budgets, algorithm and island-system candidates, rank tables, statistical tests, convergence plots, ECDFs, performance profiles, rank heatmaps, and save/load support.
3. Algorithm Details
You can inspect the default parameters of any metaheuristic in the library using get_algorithm_info().
import pymetaheuristic
from pprint import pprint
# Get Info
algorithm_id = "pso" # change this to any ID from the table, e.g. "de", "ga", "gwo", "woa"
algo_iinfo = pymetaheuristic.get_algorithm_info(algorithm_id)
# Results
print("Algorithm ID:", algo_info["algorithm_id"])
print("Algorithm Name:", algo_info["algorithm_name"])
print("")
print("Default Parameters:")
pprint(algo_info["defaults"])
Algorithm ID: pso
Algorithm Name: Particle Swarm Optimization
Default Parameters:
{'c1': 2.0, 'c2': 2.0, 'decay': 0, 'swarm_size': 30, 'w': 0.9}
The table below summarizes the optimization engines currently available in the library. The Algorithm column reports the conventional algorithm name, ID gives the identifier used in the codebase, Family provides a coarse methodological grouping, Population indicates whether the algorithm maintains an explicit candidate population, Candidate Injection indicates whether the algorithm is currently marked as able to absorb external candidates during cooperative or orchestrated workflows, Restart shows whether native restart support is declared, and Snapshot Fit provides a practical recommendation for using store_population_snapshots in the current implementation. Click the algorithm name to open its primary reference or original source. All algorithms support checkpointing through the library framework, and all constraint handling is available through the framework-level constraint machinery.
| Algorithm | ID | Family | Population | Candidate Injection | Restart | Snapshot Fit |
|---|---|---|---|---|---|---|
| Adam (Adaptive Moment Estimation) | adam |
math | No | No | No | No |
| Adaptive Chaotic Grey Wolf Optimizer | acgwo |
swarm | Yes | Yes | No | Yes |
🔍 View complete Metaheuristic reference table
4. Test Functions
The graph module can be used with the built-in benchmark functions or with any user-defined scalar objective function that follows the same interface f(x) -> float. The unified plotting function automatically adapts the visualization to the number of variables:
**1D**: Line Plot (1 Variable, `plot_function_1d`)
**2D**: Contour Map and Heatmap (2 Variables,`plot_function_2d`)
**3D**: Interactive Surface Plot (2 Variables,`plot_function_3d`)
**ND**: Parallel-coordinates Plot & PCA Projection (3+ Variables,`plot_function_nd`)
import pymetaheuristic
rastrigin = pymetaheuristic.get_test_function("rastrigin")
# Plot
pymetaheuristic.plot_function_3d(
rastrigin,
min_values = (-5.12, -5.12),
max_values = ( 5.12, 5.12),
solutions = ([ 0, 0]),
title = "Rastrigin",
filepath = "out.html", # also supports .png / .svg / .pdf
)
The table below summarizes the benchmark functions currently available in the library. The Function column reports the conventional function name, ID gives the callable identifier used in the codebase (when importing from pymetaheuristic.src.test_functions), Domain and Global Minimum describes, when applicable, the corresponding decision vector, and the known global optimum in terms of objective value.
Benchmark Function Optima
All functions below use the minimization convention. Notation
| Symbol | Meaning |
|---|---|
| D | Number of decision variables. |
| x* | Global minimizer. |
| f* | Global minimum value. |
| 0D | D-dimensional vector of zeros. |
| 1D | D-dimensional vector of ones. |
2-Dimensional Functions
| Function | ID | Domain | Global Minimum |
|---|---|---|---|
| Ackley | ackley |
[-32.768, 32.768]2 | f(x1, x2) = 0; (x1, x2) = (0, 0) |
| Beale | beale |
[-4.5, 4.5]2 | f(x1, x2) = 0; (x1, x2) = (3, 0.5) |
| Bohachevsky F1 | bohachevsky_1 |
[-100, 100]2 | f(x1, x2) = 0; (x1, x2) = (0, 0) |
| Bohachevsky F2 | bohachevsky_2 |
[-100, 100]2 | f(x1, x2) = 0; (x1, x2) = (0, 0) |
| Bohachevsky F3 | bohachevsky_3 |
[-100, 100]2 | f(x1, x2) = 0; (x1, x2) = (0, 0) |
| Booth | booth |
[-10, 10]2 | f(x1, x2) = 0; (x1, x2) = (1, 3) |
| Branin RCOS | branin_rcos |
x1 ∈ [-5, 10], x2 ∈ [0, 15] | f* = 0.3978873577 at (-π, 12.275), (π, 2.275), (3π, 2.475) |
| Bukin F6 | bukin_6 |
x1 ∈ [-15, -5], x2 ∈ [-3, 3] | f(x1, x2) = 0; (x1, x2) = (-10, 1) |
| Cross-in-Tray | cross_in_tray |
[-10, 10]2 | f* ≈ -2.0626118708 at (x1, x2) = (±1.349406609, ±1.349406609) |
| Drop-Wave | drop_wave |
[-5.12, 5.12]2 | f(x1, x2) = -1; (x1, x2) = (0, 0) |
| Easom | easom |
[-100, 100]2 | f(x1, x2) = -1; (x1, x2) = (π, π) |
| Eggholder | eggholder |
[-512, 512]2 | f* ≈ -959.6407; (x1, x2) ≈ (512, 404.2319) |
| Goldstein-Price | goldstein_price |
[-2, 2]2 | f(x1, x2) = 3; (x1, x2) = (0, -1) |
| Himmelblau | himmelblau |
[-5, 5]2 | f* = 0 at (3, 2), (-2.805118, 3.131312), (-3.779310, -3.283186), (3.584428, -1.848126) |
| Hölder Table | holder_table |
[-10, 10]2 | f* ≈ -19.208502568 at (x1, x2) = (±8.055023472, ±9.664590029) |
| Levi F13 | levi_13 |
[-10, 10]2 | f(x1, x2) = 0; (x1, x2) = (1, 1) |
| Matyas | matyas |
[-10, 10]2 | f(x1, x2) = 0; (x1, x2) = (0, 0) |
| McCormick | mccormick |
x1 ∈ [-1.5, 4], x2 ∈ [-3, 4] | f* ≈ -1.913222955; (x1, x2) ≈ (-0.54719756, -1.54719756) |
| Schaffer F2 | schaffer_2 |
[-100, 100]2 | f(x1, x2) = 0; (x1, x2) = (0, 0) |
| Schaffer F4 | schaffer_4 |
[-100, 100]2 | f* ≈ 0.292578632 at (0, ±1.25313), (±1.25313, 0) |
| Schaffer F6 | schaffer_6 |
[-100, 100]2 | f(x1, x2) = 0; (x1, x2) = (0, 0) |
| Six-Hump Camel Back | six_hump_camel_back |
x1 ∈ [-3, 3], x2 ∈ [-2, 2] | f* ≈ -1.031628453 at (0.089842, -0.712656), (-0.089842, 0.712656) |
| Three-Hump Camel Back | three_hump_camel_back |
[-5, 5]2 | f(x1, x2) = 0; (x1, x2) = (0, 0) |
D-Dimensional Functions
| Function | ID | Domain | Global Minimum |
|---|---|---|---|
| Alpine 1 | alpine_1 |
[-10, 10]D | f(x) = 0; xi = 0, i = 1, ..., D |
| Alpine 2 | alpine_2 |
[0, 10]D | f* ≈ -(2.808131180)D; xi ≈ 7.917052698 [N1] |
| Axis Parallel Hyper-Ellipsoid | axis_parallel_hyper_ellipsoid |
[-5.12, 5.12]D | f(x) = 0; xi = 0, i = 1, ..., D |
| Bent Cigar | bent_cigar |
[-100, 100]D | f(x) = 0; x = 0D |
| Chung-Reynolds | chung_reynolds |
[-100, 100]D | f(x) = 0; x = 0D |
| Cosine Mixture | cosine_mixture |
[-1, 1]D | f(x) = -0.1D; x = 0D [N1] |
| Csendes | csendes |
[-1, 1]D | f(x) = 0; x = 0D |
| De Jong F1 / Sphere | de_jong_1 |
[-5.12, 5.12]D | f(x) = 0; x = 0D |
| Discus | discus |
[-100, 100]D | f(x) = 0; x = 0D |
| Dixon-Price | dixon_price |
[-10, 10]D | f(x) = 0; xi = 2-((2i - 2) / 2i), i = 1, ..., D |
| Elliptic | elliptic |
[-100, 100]D | f(x) = 0; x = 0D |
| Expanded Griewank plus Rosenbrock | expanded_griewank_plus_rosenbrock |
[-5, 5]D | f(x) = 0; x = 1D |
| Griewank | griewangk_8 |
[-600, 600]D | f(x) = 0; x = 0D |
| Happy Cat | happy_cat |
[-100, 100]D | f(x) = 0; x = -1D |
| HGBat | hgbat |
[-100, 100]D | f(x) = 0; x = -1D |
| Katsuura | katsuura |
[-100, 100]D | f(x) = 0; x = 0D [N2] |
| Levy | levy |
[-10, 10]D | f(x) = 0; x = 1D |
| Michalewicz | michalewicz |
[0, π]D | Dimension- and m-dependent [N3] |
| Modified Schwefel | modified_schwefel |
[-100, 100]D | f(x) = 0; x = 0D [N4] |
| Perm 0,d,beta | perm |
[-D, D]D | f(x) = 0; xi = 1 / i, i = 1, ..., D |
| Pinter | pinter |
[-10, 10]D | f(x) = 0; x = 0D |
| Powell | powell |
[-4, 5]D | f(x) = 0; x = 0D [N5] |
| Qing | qing |
[-500, 500]D | f(x) = 0; xi = ±√i, i = 1, ..., D |
| Quintic | quintic |
[-10, 10]D | f(x) = 0; each xi ∈ {-1, 2} |
| Rastrigin | rastrigin |
[-5.12, 5.12]D | f(x) = 0; x = 0D |
| Ridge | ridge |
[-100, 100]D | f(x) = 0; x = 0D [N6] |
| Rosenbrock Valley | rosenbrocks_valley |
[-5, 10]D | f(x) = 0; x = 1D |
| Salomon | salomon |
[-100, 100]D | f(x) = 0; x = 0D |
| Schumer-Steiglitz | schumer_steiglitz |
[-100, 100]D | f(x) = 0; x = 0D |
| Schwefel | schwefel |
[-500, 500]D | f(x) = 0; xi ≈ 420.968746228, i = 1, ..., D |
| Schwefel 2.21 | schwefel_221 |
[-100, 100]D | f(x) = 0; x = 0D |
| Schwefel 2.22 | schwefel_222 |
[-100, 100]D | f(x) = 0; x = 0D |
| Sphere 2 / Sum of Different Powers | sphere_2 |
[-1, 1]D | f(x) = 0; x = 0D |
| Sphere 3 / Rotated Hyper-Ellipsoid | sphere_3 |
[-65.536, 65.536]D | f(x) = 0; x = 0D |
| Step | step |
[-100, 100]D | f(x) = 0; abs(xi) < 1 [N7] |
| Step 2 | step_2 |
[-100, 100]D | f(x) = 0; -0.5 ≤ xi < 0.5 [N7] |
| Step 3 | step_3 |
[-100, 100]D | f(x) = 0; abs(xi) < 1 [N7] |
| Stepint | stepint |
[-5.12, 5.12]D | f = 25 - 6D*; xi ∈ [-5.12, -5) [N8] |
| Styblinski-Tang | styblinski_tang |
[-5, 5]D | f ≈ -39.166165704D*; xi ≈ -2.903534028 |
| Trid | trid |
[-D2, D2]D | f* = -D(D + 4)(D - 1) / 6; xi = i(D + 1 - i) |
| Weierstrass | weierstrass |
[-0.5, 0.5]D | f(x) = 0; x = 0D |
| Whitley | whitley |
[-10.24, 10.24]D | f(x) = 0; x = 1D |
| Zakharov | zakharov |
[-5, 10]D | f(x) = 0; x = 0D |
CEC 2022 Functions
| Function | ID | Domain | Global Minimum |
|---|---|---|---|
| CEC 2022 F1 | cec_2022_f01 |
2, 10, 20 | f* = 300 |
| CEC 2022 F2 | cec_2022_f02 |
2, 10, 20 | f* = 400 |
| CEC 2022 F3 | cec_2022_f03 |
2, 10, 20 | f* = 600 |
| CEC 2022 F4 | cec_2022_f04 |
2, 10, 20 | f* = 800 |
| CEC 2022 F5 | cec_2022_f05 |
2, 10, 20 | f* = 900 |
| CEC 2022 F6 | cec_2022_f06 |
10, 20 | f* = 1800 |
| CEC 2022 F7 | cec_2022_f07 |
10, 20 | f* = 2000 |
| CEC 2022 F8 | cec_2022_f08 |
10, 20 | f* = 2200 |
| CEC 2022 F9 | cec_2022_f09 |
2, 10, 20 | f* = 2300 |
| CEC 2022 F10 | cec_2022_f10 |
2, 10, 20 | f* = 2400 |
| CEC 2022 F11 | cec_2022_f11 |
2, 10, 20 | f* = 2600 |
| CEC 2022 F12 | cec_2022_f12 |
2, 10, 20 | f* = 2700 |
Engineering Design Benchmarks
Engineering benchmarks expose an objective function, along with bounds and constraints. Use get_engineering_benchmark("<id>") to retrieve objective, constraints, min_values, max_values, and best-known metadata. Constraint functions follow the package convention g(x) ≤ 0.
| Function | ID | Domain | Global Minimum | Constraints |
|---|---|---|---|---|
| Tension/compression spring design | tension_spring |
d ∈ [0.05, 2], D ∈ [0.25, 1.30], N ∈ [2, 15] | f* ≈ 0.012665; (d, D, N) ≈ (0.05169, 0.35675, 11.2871) [N9] | 4 inequalities |
| Welded beam design | welded_beam |
h ∈ [0.1, 2], l ∈ [0.1, 10], t ∈ [0.1, 10], b ∈ [0.1, 2] | f* ≈ 1.724852; (h, l, t, b) ≈ (0.20573, 3.47049, 9.03662, 0.20573) | 7 inequalities |
| Pressure vessel design, continuous relaxation | pressure_vessel |
Ts, Th ∈ [0, 99], R ∈ [10, 200], L ∈ [10, 240] | f* ≈ 5804.376217; (Ts, Th, R, L) ≈ (0.727591, 0.359649, 37.699012, 240) [N10] | 4 inequalities |
| Pressure vessel design, discrete thickness | pressure_vessel_discrete |
Ts, Th rounded upward to multiples of 1/16; R ∈ [10, 200], L ∈ [10, 240] | f* ≈ 6059.714335; (Ts, Th, R, L) ≈ (0.8125, 0.4375, 42.098446, 176.636596) [N10] | 4 inequalities |
| Speed reducer design | speed_reducer |
7 bounded design variables | f* ≈ 2994.471066; x ≈ (3.5, 0.7, 17, 7.3, 7.71532, 3.35021, 5.28665) | 11 inequalities |
| Three-bar truss design | three_bar_truss |
A1, A2 ∈ [0, 1] | f* ≈ 263.895843; (A1, A2) ≈ (0.788675, 0.408248) | 3 inequalities |
| Cantilever beam design | cantilever_beam |
xi ∈ [0.01, 100], i = 1, ..., 5 | f* ≈ 1.339956; x ≈ (6.016016, 5.309173, 4.494330, 3.501475, 2.152665) | 1 inequality |
| Gear train design | gear_train |
integer xi ∈ [12, 60], i = 1, ..., 4 | f* ≈ 2.700857 × 10-12; x = (16, 19, 43, 49) [N11] | box + integrality |
Notes
| Note | Meaning |
|---|---|
| N1 | Alpine 2 and Cosine Mixture have sign-convention traps in the literature. This package uses minimization-compatible signs. |
| N2 | Katsuura is implemented as the product expression minus 1, so the exposed minimum is 0 at the origin. |
| N3 | Michalewicz has no single dimension-free closed-form optimum. For m = 10, common reference values are approximately: D = 2, f = -1.8013; D = 5, f = -4.6877; D = 10, f* = -9.6602. |
| N4 | Modified Schwefel is exposed in shifted CEC-style coordinates, so the visible optimizer is 0D. |
| N5 | Powell requires D to be a multiple of 4. |
| N6 | This is the cumulative ridge implementation, not the BBOB sharp-ridge function. |
| N7 | Step functions have optimizer intervals, not isolated optimizer points. |
| N8 | Stepint is bound-dependent. With bounds [-5.12, 5.12]D, f = 25 - 6D*; without bounds, it is unbounded below. |
| N9 | Engineering-design rows are constrained benchmarks. The Python module exposes get_engineering_benchmark(id) so users can pass the returned objective, bounds, and constraints directly to pymetaheuristic.optimize. |
| N10 | Pressure vessel has two common variants. pressure_vessel is the continuous relaxation; pressure_vessel_discrete rounds shell/head thickness upward to multiples of 1/16 before objective and constraint evaluation. |
| N11 | Gear train is a discrete integer benchmark. The implementation rounds variables to the nearest integer tooth counts by default. |
5. Other Libraries
- For Multiobjective Optimization or Many Objectives Optimization, try pyMultiobjective
- For Traveling Salesman Problems (TSP), try pyCombinatorial
Acknowledgement
This section is dedicated to everyone who helped improve or correct the code. Thank you very much!
- Raiser (01.MARCH.2022) - https://github.com/mpraiser - University of Chinese Academy of Sciences (China)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pymetaheuristic-7.0.0.tar.gz.
File metadata
- Download URL: pymetaheuristic-7.0.0.tar.gz
- Upload date:
- Size: 838.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4fc2d7dad962ed62dc78f649b17f3ea7fd4aef73f45f6084963165216d65a80
|
|
| MD5 |
a0928da7e8ce749f3b22c5a2690a92ca
|
|
| BLAKE2b-256 |
0973086d84cea9ad2bf6e167c8045281829efa7fe8bb935c2a1629f593d940f5
|
File details
Details for the file pymetaheuristic-7.0.0-py3-none-any.whl.
File metadata
- Download URL: pymetaheuristic-7.0.0-py3-none-any.whl
- Upload date:
- Size: 1.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b47fb89b5a1452cd80568cc6656970e886d6dc14a741c96c53eadaa0c810a048
|
|
| MD5 |
8e9efaf4c6c71171cc584888131554d2
|
|
| BLAKE2b-256 |
cd2e1e4e866c49d768f22e436b31e9abf95f7338706556eb7fd039ef80b2a720
|