Skip to content

YPEA: Yarpiz Evolutionary Algorithms

YPEA: Yarpiz Evolutionary Algorithms

Define your optimization problem once. Solve it with any of 34 metaheuristics.

Yarpiz Evolutionary Algorithms (YPEA) puts genetic algorithms, particle swarms, CMA-ES, L-SHADE, NSGA-II, ant colonies, tabu search and more behind one problem definition and one result. Switching methods is one line, so you can find what works for your problem and compare methods fairly. It replaces the original YPEA toolbox, redesigned, with known defects fixed and each algorithm checked against its paper.

YPEA is available for Python and, from version 2.0, for MATLAB, with the same algorithms, settings and problems. Every example on this site has a Python tab and a MATLAB tab.

Start here

  • Getting started

    Install YPEA and solve your first problem in a few minutes.

  • User guide

    Variables, objectives, constraints, several objectives, results and plots.

  • Algorithms

    All 34 methods, how to choose one, and a run with real output on each page.

  • Applications

    Real problems solved step by step: scheduling, routing, power, control, finance and more.

  • Experiments and statistics

    Compare algorithms on many problems with statistical tests and paper-ready tables.

  • Benchmarks and test problems

    Classic functions, CEC 2017 and CEC 2022, TSP, knapsack, QAP, routing and more.

  • API reference

    Every class and function, with its parameters.

Why YPEA

  • Every algorithm solves every problem. All variable types (real, integer, binary, permutation, selection, partition, fixed sum) are encoded in [0, 1], so all 34 algorithms solve every problem.
  • Constraints built in. The objective may return (f, g) with g <= 0. Deb's feasibility rules are the default, and a penalty method is the alternative.
  • Results you can trust. The same seed gives the same result. The evaluation budget is never exceeded, and every improvement of the best solution is recorded with its evaluation count.
  • Fast when you need it. Vectorized objectives get the whole population at once, and an executor evaluates solutions in parallel.
  • Multiple objectives. NSGA-II, NSGA-III, MOEA/D, MOPSO and SPEA2 keep every non-dominated solution a run finds in Result.front.
  • Local search and hybrids. Hill climbing, tabu search, VNS, ILS and GRASP, ant colonies for discrete problems, algorithms run in sequence, and memetic runs.
  • Research ready. Run many algorithms on many problems, resume interrupted studies, and get statistical tests, LaTeX and Markdown tables, figures and an HTML report.

Install

pip install ypea

YPEA needs Python 3.12 or newer. The optional extras for plots and statistics are in Getting started.

Download ypea-2.0.0.mltbx from the latest release and open it in MATLAB, which installs it as an add-on. Or clone smkalami/ypea and add its folder (the one that holds +ypea) to the path:

addpath("path/to/ypea")

YPEA for MATLAB needs R2021a or newer and no other toolbox. With the Parallel Computing Toolbox, experiments, tuning and solve(..., parallel=true) run in parallel.

A 30-second example

Find 20 real numbers in [-10, 10] that minimize the sphere function, the sum of their squares. Its best value is 0, at x = 0.

import ypea

problem = ypea.Problem(
    vars=ypea.Real("x", shape=20, lb=-10, ub=10),
    objective=lambda sol: ypea.benchmarks.sphere(sol.x),
    name="sphere",
)

result = ypea.GA(max_nfe=20_000).solve(problem, seed=1)

print(result.best.obj_value)
print(result.best.solution.x[:3])
8.495166950680593e-12
[-5.93875260e-08  2.52175806e-06 -4.64273747e-07]

Differs from Python: MATLAB draws its own random numbers, so the values differ from Python's.

problem = ypea.Problem( ...
    vars=ypea.Real("x", shape=20, lb=-10, ub=10), ...
    objective=@(sol) ypea.benchmarks.sphere(sol.x), ...
    name="sphere");

result = ypea.GA(max_nfe=20000).solve(problem, seed=1);

disp(result.best.obj_value)
disp(result.best.solution.x(1:3))
   5.5400e-08

   1.0e-04 *

   -0.0821   -0.1093   -0.9627

max_nfe=20_000 stops the run after 20 000 evaluations of the objective. The seed fixes the random numbers, so the same seed gives the same result. The best value found is almost 0, and the first three numbers of the best solution are almost 0 too.

Any other algorithm solves the same problem. Here L-SHADE runs instead of GA, and summary() prints a short report of the run:

import ypea

problem = ypea.Problem(
    vars=ypea.Real("x", shape=20, lb=-10, ub=10),
    objective=lambda sol: ypea.benchmarks.sphere(sol.x),
    name="sphere",
)

result = ypea.LSHADE(max_nfe=20_000).solve(problem, seed=1)
print(result.summary())
L-SHADE on sphere
  best objective value: 4.58976e-08
  feasible: True (violation 0)
  evaluations: 20000, iterations: 250, time: 0.278 s, stopped by: max_nfe

Differs from Python: MATLAB draws its own random numbers, so the values differ from Python's.

problem = ypea.Problem( ...
    vars=ypea.Real("x", shape=20, lb=-10, ub=10), ...
    objective=@(sol) ypea.benchmarks.sphere(sol.x), ...
    name="sphere");

result = ypea.LSHADE(max_nfe=20000).solve(problem, seed=1);
disp(result.summary())
L-SHADE on sphere
  best objective value: 6.02505e-08
  feasible: true (violation 0)
  evaluations: 20000, iterations: 250, time: 1.41 s, stopped by: max_nfe

The sphere has no constraints, so every solution is feasible with violation 0. The run used its whole budget of evaluations and stopped because of max_nfe.

How it fits together

%%{init: {"flowchart": {"curve": "monotoneY"}}}%%
flowchart TB
    P("Problem: variables, objective, sense, constraints") --> A("Algorithm: GA, PSO, DE, CMA-ES, NSGA-II, ...")
    A -- "codes in [0, 1]" --> E("Evaluator: decodes, evaluates, counts, keeps the best")
    E -- "values and violations" --> A
    C("Comparator: min or max, constraint rules, Pareto dominance") -.- A
    E --> R("Result: best, front, history")
    R --> X("Plots, experiments, statistics, tuning")

You describe the problem. The algorithm never sees your variable types. It searches over codes, plain numbers in [0, 1] that stand for a solution. The evaluator decodes the codes into your variables, calls your objective, counts the evaluations and keeps the best solution.

Next: Getting started, then the user guide or an algorithm.

Author

YPEA was created and is maintained by Mostapha Kalami Heris (ORCID, Yarpiz), for Python, MATLAB and the browser (YPEA Studio).

Citing

If you use YPEA in research, see Citing.

License

MIT. The bundled benchmark and test problem data keep the terms of their sources (see Benchmarks and Test problems).