9. Global Search: DE and PSO
Global search in nlopt4r runs on finite boxes, reads objective values and uses explicitly seeded random streams. The two population algorithms are synchronous differential evolution (DE/rand/1/bin) and inertia-weight global-best particle swarm optimization (PSO).
9.1 Differential evolution
The per-generation flow of global::differential_evolution:
- initialization: sample
population_sizepoints uniformly in the box, or validate a caller-supplied population; - for each target \(i\), draw three distinct donors \(a,b,c\) with \(i\) excluded from the donor set;
- mutation vector
- binomial crossover: each coordinate takes the mutant component with probability \(CR\), with at least one coordinate forced to the mutant component, including at \(CR=0\);
- bound repair: a mutant component below its lower bound becomes
and one above its upper bound becomes
- selection: replace the target when the trial objective is at most the current value.
All donors read the preceding generation, giving synchronous updates. Defaults and valid ranges:
| Field | Default | Valid range |
|---|---|---|
population_size | 40 | \(\ge 4\) |
max_generations | 1000 | Nonnegative integer |
weight (\(F\)) | 0.8 | \(0<F\le2\) |
crossover (\(CR\)) | 0.9 | \(0\le CR\le1\) |
seed | 0 | Any 64-bit unsigned integer |
budget.max_evaluations | 10000 | Positive integer |
budget.target_value | None | Finite value |
9.2 Particle swarm
The velocity and position updates of global::particle_swarm:
where \(p_i\) is the personal best, \(g\) the global-best snapshot taken at the start of the generation, and \(r_1,r_2\) independent uniform draws per coordinate.
Implementation details:
- initial velocities are zero;
- velocity components clip to \(\pm v_{\max,j}\) with \(v_{\max,j}=c_v,(u_j-l_j)\), where
velocity_limitsupplies \(c_v\); - positions project into the box; a projected coordinate resets its velocity to zero;
- personal bests update on a strict objective decrease; ties keep the earlier best;
- the global best updates by generation, and all particles in a generation read one snapshot.
Defaults and valid ranges:
| Field | Default | Valid range |
|---|---|---|
population_size | 40 | \(\ge 2\) |
max_generations | 1000 | Nonnegative integer |
inertia (\(w\)) | 0.7 | \(0\le w<1\) |
cognitive (\(c_1\)) | 1.5 | Finite nonnegative |
social (\(c_2\)) | 1.5 | Finite nonnegative |
velocity_limit | 0.2 | \(0<v\le1\) |
seed | 0 | Any 64-bit unsigned integer |
9.3 Randomness and reproduction
Both entry points use the ChaCha8 stream of rand_chacha 0.9, seeded by the seed field. Initialization samples normalized coordinates:
Reproduction conditions: identical seed, dependency versions and floating-point platform. The same seed reproduces the same sequence on the same build and platform.
9.4 Report and diversity
GlobalSolution fields:
| Field | Meaning |
|---|---|
x, value | Best evaluated point and its objective |
generations | Completed generations (initialization and an unfinished generation excluded) |
evaluations | Callback counts, including initialization |
termination_reason | TargetReached, MaxEvaluations, MaxIterations, Stagnated or Cancelled |
seed | Seed of this run |
diversity | Maximum over coordinates of the population spread divided by the box width |
target_reached() tests for TargetReached, which corresponds to the objective reaching the caller’s target_value.
9.5 Budget and cancellation
- the objective budget is a strict cap: exhaustion during initialization or a partial generation returns the best evaluated point;
_with_observervariants call the observer after each valid evaluation;Control::Stopcancels after the current evaluation; an observer error propagates with the best point retained;- cancellation, budget and generation caps are ordinary reports, with
termination_reasonrecording the specific cause.
Software interface
DeOptions,PsoOptions,differential_evolution,particle_swarm: see chapter 17.- Observers and
EvaluationContext: see chapter 21. - Benchmark protocol and measured results: see chapter 13.
- API reference (docs.rs):
global.
References
- R. Storn, K. Price, “Differential Evolution—A Simple and Efficient Heuristic for Global Optimization over Continuous Spaces,” J. Global Optim. 11 (1997), 341–359.
- J. Kennedy, R. Eberhart, “Particle swarm optimization,” Proc. IEEE ICNN 4 (1995), 1942–1948.
- Y. Shi, R. Eberhart, “A modified particle swarm optimizer,” Proc. IEEE ICEC (1998), 69–73.