Algorithms
Single-objective
BCA
BilevelHeuristics.BCA — TypeBCA(;N, n, K, η_max, resize_population)Bilevel Centers Algorithm — a physics-inspired metaheuristic for single-objective bilevel optimisation. It uses a nested scheme where both the upper and lower levels employ a center-of-mass variation operator.
How it works
At each iteration, for every individual in the upper-level population:
- A random subset
Uof sizeKis selected. - The center of mass
cofUis computed, weighted by the combined fitnessQ = F + f(i.e., both level objectives). - A new candidate
p = x_i + η · (c - u_worst)is generated, whereu_worstis the worst element inUandηis a random step size. - The lower-level problem is solved for
p(using the same center-of-mass strategy), producing one or more optimal lower-level responses. - The new pair
(p, y_opt)replaces a worse member of the population.
The population size may be dynamically reduced during the run (resize_population), shifting from exploration to exploitation.
Parameters
N— upper-level population size (auto‑computed fromK × D_ulif 0).n— lower-level population size (auto‑computed if 0).K— number of solutions used to compute the center of mass (default7). LargerK→ faster convergence (exploitation); smallerK→ more exploration.η_max— maximum step size for the variation operator (default2.0).resize_population— iftrue, the population shrinks linearly over the run (defaulttrue).
Reference
Mejía-de-Dios, J. A., & Mezura-Montes, E. (2018, November). A physics-inspired algorithm for bilevel optimization. In 2018 IEEE International Autumn Meeting on Power, Electronics and Computing (ROPEC) (pp. 1–6). IEEE.
QBCA
BilevelHeuristics.QBCA — TypeQBCA(;N, K, η_ul_max, η_ll_max, α, β, autodiff)Quasi-Newton Bilevel Centers Algorithm — combines the center-of-mass variation (upper level) with a BFGS quasi-Newton solver (lower level) and Tikhonov regularisation for improved lower-level accuracy.
How it works
The upper-level search follows the same center-of-mass strategy as BCA. The key difference is in the lower-level solver:
- For a given upper-level
x, the lower level is first explored with a lightweight ECA centre-of-mass search to get an approximatey. - That
yis then refined by a BFGS quasi-Newton method, minimising a Tikhonov- regularised objectivef(x, y) + α·‖y‖² + β·‖y - y₀‖², which stabilises the lower-level solution and prevents overfitting to a singlex. - Both the upper and lower levels compute their own centers of mass, and the lower-level step also uses a separate step size
η_ll_max.
This hybrid approach reduces the number of lower-level function evaluations compared to BCA, especially on problems where the lower level is smooth and unimodal.
Parameters
N— upper-level population size (auto‑computed if 0).K— number of solutions to generate centers (default3).η_ul_max— upper-level step size (default2.0).η_ll_max— lower-level step size (default1/η_ul_max).α,β— Tikhonov regularisation weights (default0.05each).autodiff— differentiation mode for BFGS::finite(finite differences) or:forward(forward-mode AD) (default:finite).
Reference
Mejía-de-Dios, J. A., & Mezura-Montes, E. (2019, June). A metaheuristic for bilevel optimization using Tikhonov regularization and the quasi-Newton method. In 2019 IEEE Congress on Evolutionary Computation (CEC) (pp. 3134–3141). IEEE.
QBCA2
BilevelHeuristics.QBCA2 — TypeQBCA2(;N, K, η_max, δ1, δ2, ε1, ε2, λ, t_reevaluate)Improved Quasi-Newton BCA — an enhanced version of QBCA that explicitly detects and avoids pseudo-feasible solutions.
How it works
A pseudo-feasible solution (x, y) is one where:
yis optimal for the lower level givenx, andF(x, y)is close to the upper-level optimum, but- the lower-level optimum is not unique (multiple different
ygive the samefvalue).
Such solutions can mislead the upper-level search because the leader observes a good F value but the follower's response is not stable. QBCA2 detects pseudo-feasible pairs using thresholds (δ1, δ2, ε1, ε2) and avoids replacing solutions with unstable ones.
The upper-level search uses the center-of-mass operator, while the lower level is solved with BFGS (optionally preceded by Nelder-Mead). A surrogate model (SECA) can optionally be enabled to further reduce lower-level evaluations.
Parameters
N— upper-level population size (auto‑computed if 0).K— number of solutions to generate centers (default3).η_max— maximum step size (default2.0).δ1,δ2— position difference thresholds for pseudo-feasibility detection (default1e-2).ε1,ε2— objective difference thresholds for pseudo-feasibility detection (default1e-2).t_reevaluate— frequency (in iterations) for re-evaluating the lower level of the elite solution (default10).λ— regularisation for the optional surrogate model (default1e-12).autodiff— differentiation mode for BFGS (:finiteor:forward).use_surrogate_model— iftrue, a kernel-interpolation surrogate (SECA) assists the lower-level search (defaultfalse).
Reference
Mejía-de-Dios, J. A., Mezura-Montes, E., & Toledo-Hernández, P. (2022). Pseudo-feasible solutions in evolutionary bilevel optimization: Test problems and performance assessment. Applied Mathematics and Computation, 412, 126577.
SABO
BilevelHeuristics.SABO — TypeSABO(;N, K, η_max, δ1, δ2, ε1, ε2, λ, t_reevaluate)Surrogate-Assisted Bilevel Optimization — reduces the cost of lower-level optimisation by employing a kernel-interpolation surrogate model (BiApprox) to approximate the lower-level optimal response.
How it works
SABO extends the QBCA2 framework with a surrogate strategy:
- An elite surrogate solution is maintained, tracking the most promising pair
(x, y). - At each iteration, the surrogate model predicts the lower-level response for candidate upper-level points, reducing expensive lower-level evaluations.
- Every
t_reevaluateiterations, the entire population is re-evaluated with the true lower-level solver (BFGS) to correct surrogate drift. - The same pseudo-feasibility detection from
QBCA2is used to avoid unstable solutions.
The surrogate model is a kernel interpolation (radial basis function with Gaussian kernel) trained on previously evaluated (x, y) pairs. This makes SABO particularly effective when the lower level is expensive to evaluate.
Parameters
N— upper-level population size (auto‑computed if 0).K— number of solutions to generate centers (default3).η_max— maximum step size (default2.0).δ1,δ2,ε1,ε2— thresholds for pseudo-feasibility detection (default1e-2).λ— regularisation for the kernel interpolation surrogate (default1e-5).t_reevaluate— re-evaluation period (default5iterations).autodiff— differentiation mode (:finiteor:forward).
Reference
Mejía-de-Dios, J. A., & Mezura-Montes, E. (2020, June). A surrogate-assisted metaheuristic for bilevel optimization. In Proceedings of the 2020 Genetic and Evolutionary Computation Conference (GECCO) (pp. 629–635).
Multi-objective
BLEMO
BilevelHeuristics.BLEMO — TypeBLEMO(; ul = NSGA2(), ll = NSGA2())Bilevel Evolutionary Multi-Objective Optimization — a nested evolutionary algorithm for multi-objective bilevel problems.
BLEMO maintains multiple subpopulations, each corresponding to a distinct upper-level decision x. For each x, the lower-level NSGA-II finds a set of optimal responses. New upper-level candidates are generated via SBX crossover and polynomial mutation on the current elite set, and the lower level re-optimises from the inherited subpopulations. Non-dominated sorting and crowding distance are used for environmental selection at both levels.
The Pareto archive of non-dominated bilevel solutions is stored in method.parameters.archive.
Parameters (keyword constructor)
ul— upper-level NSGA2 configuration.ll— lower-level NSGA2 configuration.
SMS_MOBO
BilevelHeuristics.SMS_MOBO — TypeSMS_MOBO(;
ul = Metaheuristics.SMS_EMOA(;N = 100), # upper level optimizer
ll = Metaheuristics.NSGA2(;N = 50), # lower level optimizer
ul_offsprings = 10,
options_ul = Options(iterations = 100, f_calls_limit = Inf),
options_ll = Options(iterations = 50, f_calls_limit = Inf),
)S-metric-selection Multi-Objective Bilevel Optimization — described in Mejía-de-Dios & Mezura-Montes (2022).
SMS_MOBO extends the S-metric selection idea (SMS-EMOA) to the bilevel setting. Both the upper and lower levels solve multi-objective problems:
- The upper level uses
SMS_EMOA(hypervolume-based indicator) to drive the search toward a well-distributed Pareto front. - The lower level uses a multi-objective evolutionary algorithm (
NSGA2,SPEA2, orSMS_EMOA) to find the optimal response set for each upper-level decision. - A family concept groups an upper-level
xwith its associated lower-level optimalysolutions, and a super-rank criterion combines dominance information from both levels for environmental selection.
The non-dominated upper-level solutions are stored in method.parameters.archive and are also accessible via res.population after optimisation.
Parameters
ul— upper-level optimizer (SMS_EMOAis the only valid choice).ll— lower-level optimizer (NSGA2,SPEA2, orSMS_EMOA).ul_offsprings— number of new upper-level candidate solutions generated per generation (default10).
Example
using BilevelHeuristics
function F(x, y) # two upper-level objectives
[y[1] - x[1], y[2]], [-1.0 - sum(y)], [0.0]
end
function f(x, y) # two lower-level objectives
y, [-x[1]^2 + sum(y .^ 2)], [0.0]
end
bounds_ul = [0.0 1.0]'
bounds_ll = [-1 -1; 1 1.0]
res = optimize(F, f, bounds_ul, bounds_ll, SMS_MOBO())
# Access the Pareto archive:
archive = SMS_MOBO().parameters.archiveFlexible frameworks
Nested
BilevelHeuristics.Nested — TypeNested(; ul, ll)A flexible nested framework for bilevel optimisation that accepts any Metaheuristics.jl algorithm as the upper- and lower-level solver.
Unlike the specialised algorithms (BCA, QBCA, etc.) which use tightly-coupled strategies, Nested decouples the two levels entirely:
- The upper-level optimizer proposes candidate
xvalues. - For each
x, the lower-level optimizer runs to completion, finding optimaly. - The joint solution
(x, y)is evaluated and the upper-level population is updated.
This makes Nested suitable for prototyping — you can experiment with different combinations of algorithms (e.g. GA + DE, PSO + BFGS) without implementing any bilevel-specific logic.
Parameters
ul— a configuredMetaheuristics.AbstractAlgorithmfor the upper level.ll— a configuredMetaheuristics.AbstractAlgorithmfor the lower level.
Example
using BilevelHeuristics, Metaheuristics
ul = GA(N = 50) # Genetic Algorithm at upper level
ll = DE(N = 50) # Differential Evolution at lower level
res = optimize(F, f, bounds_ul, bounds_ll, Nested(; ul, ll))DBMA
BilevelHeuristics.DBMA — TypeDBMA(; Nu, Nl, F, CR)Differential Evolution Bilevel Multi-objective Algorithm — an ε-constrained DE framework for bilevel problems where the upper level is multi-objective and the lower level is single-objective (or multi-objective).
DBMA extends the ε-constrained Differential Evolution (εDE) to both levels. The ε-level control gradually relaxes constraint violations, allowing the algorithm to explore infeasible regions early and converge to feasible Pareto-optimal solutions later.
Internally, DBMA inherits from the Nested framework and specialises the truncation and decision-making steps to handle multi-objective upper-level populations using ε-dominance.
Parameters
Nu— upper-level population size (default50).Nl— lower-level population size (default50).F— DE mutation scaling factor (default0.7).CR— DE crossover rate (default0.5).
Example
using BilevelHeuristics
F(x, y) = [y[1] - x[1], y[2]], [-1.0 - sum(y)], [0.0] # two objectives
f(x, y) = sum((x - y).^2) + y[1]^2, [0.0], [0.0] # single objective
bounds_ul = [0.0 1.0]'
bounds_ll = [-ones(5) ones(5)]
res = optimize(F, f, bounds_ul, bounds_ll, DBMA())