# An Optimization Example Using the Differential Evolution Algorithm

Numerous optimization algorithms exist, and choosing among them is rarely straightforward. During my PhD research I found differential evolution (DE) to be the most stable of the evolutionary algorithms I tested, outperforming the others in many structural applications. Its simplicity and versatility are the reasons I have used it in many of my optimization articles, and especially in my publication "A comparative study of differential evolution variants in constrained structural optimization", which has attracted a lot of interest and many citations. In this article, I try to demystify every aspect of the algorithm in a clear and simple way, with a practical example, code and results.




Introduction to Differential Evolution



  Differential Evolution (DE) is a population-based, stochastic optimizer introduced by
  Rainer Storn and Kenneth Price (technical report 1995; journal article 1997). It minimizes a real-valued
  objective function over a continuous search space and needs no derivatives: it only ever evaluates
  the objective. That makes it a natural choice for black-box problems, where the function comes from a
  simulation or an experiment and may be non-differentiable, noisy, or riddled with local minima.




  The method is popular because it is simple (about twenty lines of code), has only three control parameters (the population size $NP$, the scale factor $F$ and the crossover rate $CR$), and is surprisingly robust. However, it is not efficient: it typically needs thousands of function evaluations, it gives no mathematical guarantee of reaching the global optimum in finite time, and constraints need explicit handling. For a smooth, convex problem a gradient-based method is far cheaper (we will compare against one at the end).





  The key idea. A new candidate is built from the difference of two population members.
  When the population is spread out, differences are large and DE takes big exploratory steps; when the population
  has contracted around a minimum, differences are small and DE automatically switches to fine local search. The
  population itself supplies the step size and direction, so there is no step-size schedule to tune.





  Problem statement. Given an objective $f:\mathbb{R}^D \to \mathbb{R}$, bounds
  $L_j \le x_j \le U_j$ and, optionally, constraints $g_k(\mathbf{x}) \le 0$, find
  $$\mathbf{x}^{*} = \arg\min_{\mathbf{x}} f(\mathbf{x}) \quad \text{subject to} \quad g_k(\mathbf{x}) \le 0,\; k = 1,\dots,K.$$









Algorithm Overview



  DE maintains a population of $NP$ candidate vectors $\mathbf{x}_1,\dots,\mathbf{x}_{NP}\in\mathbb{R}^D$.
  In every generation $g$, each vector in turn plays the role of the target $\mathbf{x}_i$ and is challenged by
  a trial vector $\mathbf{u}_i$ built in two stages, mutation and crossover.
  Selection then decides which of the two survives into generation $g+1$.





  
    
  
  
  
  1
  Initialize
  NP random vectors
  within the bounds
  
  
  
  2
  Mutate
  v = r₁ + F (r₂ − r₃)
  one mutant per target
  
  
  
  3
  Cross over
  u = mix(x, v)
  controlled by CR
  
  
  
  4
  Select
  keep u if f(u) ≤ f(x)
  greedy, one-to-one
  
  
  repeat for every target vector, then advance to the next generation g → g + 1
  stop after Gₘₐₓ generations, or when the population has converged

Fig. 1 – One pass of differential evolution. After the random initialization, every
generation applies mutation, crossover and selection to each of the $NP$ target vectors.






1

Initialization – sample $NP$ vectors uniformly inside the bounds and evaluate them.




2

Mutation – pick three distinct individuals other than the target and combine them into a mutant $\mathbf{v}_i$.




3

Crossover – mix target and mutant component by component into the trial vector $\mathbf{u}_i$.




4

Selection – the trial replaces the target if it is at least as good, otherwise the target survives.




5

Repeat steps 2–4 until $G_{\max}$ generations have run, or the population has converged.





Control Parameters



  ParameterMeaningUsual rangeEffect


  
    $NP$Population size$5D$ to $10D$ (at least 4)Larger: more diversity and robustness, more evaluations per generation


    $F$Scale factor of the difference vector$0.4$ to $1.0$Larger: longer exploratory steps; too small: the population contracts before it finds the optimum


    $CR$Crossover rate$0.1$ to $0.9$Larger: the trial changes many coordinates at once; smaller: it changes few


    $G_{\max}$Number of generationsproblem dependentSets the evaluation budget, $NP \cdot G_{\max}$


  

The ranges are common rules of thumb from the DE literature, not guarantees. The parameter study below shows
how sensitive the outcome can be, even on a two-dimensional problem.








Step 1 – Initialization



  The initial population is drawn uniformly at random from the search box, so that it covers the whole domain:




  $$x_{i,j,0} = L_j + \text{rand}_{[0,1]} \cdot (U_j - L_j), \qquad i = 1,\dots,NP,\; j = 1,\dots,D$$




  Here $L_j$ and $U_j$ are the lower and upper bounds of coordinate $j$, and $\text{rand}_{[0,1]}$ is a fresh uniform
  random number for every entry. A fixed random seed makes a run reproducible, which matters when you compare
  parameter settings.









Step 2 – Mutation (DE/rand/1)



  The classic strategy is called DE/rand/1: rand because the base vector is chosen at random,
  1 because one difference vector is used. Three distinct individuals
  $\mathbf{r}_1,\mathbf{r}_2,\mathbf{r}_3$, all different from the target $\mathbf{x}_i$, are drawn at random and
  combined into the mutant vector




  $$\mathbf{v}_{i} = \mathbf{r}_{1} + F \cdot (\mathbf{r}_{2} - \mathbf{r}_{3}).$$




  Geometrically, $\mathbf{r}_2-\mathbf{r}_3$ is the arrow that points from one random member of the population to another.
  We copy this arrow, shrink or stretch it by the factor $F$, and attach it to the base vector $\mathbf{r}_1$ (Fig. 2).
  Because the arrow is made from the population itself, it is long while the population is widely spread and short once
  the population has collapsed onto a minimum – this is the self-scaling behaviour that gives DE its name.





  
    
    
  
  
  
  0
  
  
  2
  
  
  4
  
  
  6
  
  
  8
  
  
  10
  
  
  0
  
  
  2
  
  
  4
  
  
  6
  
  x₁
  x₂
  
  
  
  
  
  
  r₁
  
  r₂
  
  r₃
  
  v
  
  xi (target)
  r₂ − r₃
  F·(r₂ − r₃)
  ua
  ub
  
  difference r₂ − r₃
  
  scaled difference, F = 0.8
  
  trial candidates (crossover)

Fig. 2 – Mutation and crossover in two dimensions. The mutant $\mathbf{v}$ (orange) is
the base vector $\mathbf{r}_1$ plus the scaled difference $F(\mathbf{r}_2-\mathbf{r}_3)$, here with $F=0.8$. The target
$\mathbf{x}_i$ and the mutant span the dashed green rectangle; binomial crossover (next step) returns one of its
corners: $\mathbf{v}$, $\mathbf{u}_a$ or $\mathbf{u}_b$. The points are drawn to scale.







  Any component of $\mathbf{v}_i$ that leaves the search box is clipped to the nearest bound. Other common remedies are
  to reflect the component back into the box or to redraw it at random.




Other Mutation Strategies



  StrategyMutant vectorCharacter


  
    DE/rand/1$\mathbf{r}_1 + F(\mathbf{r}_2-\mathbf{r}_3)$Exploratory, robust default


    DE/best/1$\mathbf{x}_{best} + F(\mathbf{r}_1-\mathbf{r}_2)$Fast convergence, higher risk of premature convergence


    DE/rand/2$\mathbf{r}_1 + F(\mathbf{r}_2-\mathbf{r}_3) + F(\mathbf{r}_4-\mathbf{r}_5)$More diversity, slower


    DE/current-to-best/1$\mathbf{x}_i + F(\mathbf{x}_{best}-\mathbf{x}_i) + F(\mathbf{r}_1-\mathbf{r}_2)$Balance between exploitation and exploration


  







Step 3 – Crossover (Binomial)



  The mutant is rarely used as it stands. Instead, the trial vector $\mathbf{u}_i$ inherits some components from
  the mutant and the rest from the target, which preserves part of the information that the target already carries:




  $$u_{i,j} =
  \begin{cases}
    v_{i,j} & \text{if } \text{rand}_{[0,1]} \le CR \;\text{ or }\; j = j_\text{rand} \\
    x_{i,j} & \text{otherwise}
  \end{cases}$$




  $j_\text{rand}$ is one randomly chosen coordinate that is always taken from the mutant. Without it, with
  probability $(1-CR)^D$ the trial would be an exact copy of the target and the evaluation would be wasted.





  
    
  
  target xᵢ
  mutant vᵢ
  trial uᵢ
  j = 1
  rand = 0.21
  
  x₁
  
  
  v₁
  
  
  v₁
  from mutant
  j = 2
  rand = 0.74
  
  
  x₂
  
  
  v₂
  
  x₂
  from target
  j = 3
  rand = 0.88
  
  x₃
  
  
  v₃
  
  
  v₃ ★
  from mutant
  j = 4
  rand = 0.43
  
  x₄
  
  
  v₄
  
  
  v₄
  from mutant
  j = 5
  rand = 0.91
  
  
  x₅
  
  
  v₅
  
  x₅
  from target
  j = 6
  rand = 0.67
  
  
  x₆
  
  
  v₆
  
  x₆
  from target
  CR = 0.5
  j_rand = 3 ★
  A component is taken from the mutant when rand ≤ CR, or when it is the forced index j_rand.

Fig. 3 – Binomial crossover for $D=6$ and $CR=0.5$. Each coordinate draws its own random
number (top row). Coordinates 1 and 4 satisfy $\text{rand}\le CR$; coordinate 3 is the forced index $j_\text{rand}$ (★);
the other three come from the target.







  On average $1+(D-1)\,CR$ coordinates come from the mutant. A high $CR$ therefore moves the trial
  vector in many directions at once, which suits problems whose variables interact (for example, a constraint along a
  diagonal). A low $CR$ changes only a few coordinates at a time, which suits problems that can be solved
  one variable at a time. In two dimensions the picture of Fig. 2 makes this concrete: the trial is $\mathbf{v}$ with
  probability $CR$, and $\mathbf{u}_a$ or $\mathbf{u}_b$ with probability $(1-CR)/2$ each.









Step 4 – Greedy Selection



  The trial vector replaces its target only if it is at least as good:




  $$\mathbf{x}_{i,g+1} =
  \begin{cases}
    \mathbf{u}_{i} & \text{if } f(\mathbf{u}_{i}) \le f(\mathbf{x}_{i,g}) \\
    \mathbf{x}_{i,g}   & \text{otherwise}
  \end{cases}$$




  The comparison is strictly one-to-one: a trial competes only with its own target, never with the rest of the
  population. This is elitist (the best objective value in the population can never get worse) and it preserves
  diversity, because a mediocre individual survives as long as nobody has beaten its own trial. Using
  $\le$ rather than $

 0$. The optimal value is $f^* = (-0.5)^2 + (-0.5)^2 = 0.5$. Geometrically, the optimum is the
  point of the line closest to $(2,3)$, where the contour $f=0.5$ just touches the constraint line (Fig. 4). Since
  $\lambda = 1$, any penalty weight $\rho > 1$ is exact; we use $\rho = 100$.





  
    
  
  
  
  
  
  
  
  
  
  
  
  
  0
  
  
  2
  
  
  4
  
  
  6
  
  
  8
  
  
  0
  
  
  2
  
  
  4
  
  
  6
  
  
  8
  
  x
  y
  f = 2
  f = 5
  f = 10
  f = 20
  feasible region
  infeasible region: x + y > 4
  x + y = 4
  
  
  unconstrained minimum (2, 3), f = 0
  
  
  
  constrained optimum
  (1.5, 2.5),  f = 0.5

Fig. 4 – The problem. Blue circles are contours of $f$, the red line is the constraint
$x+y=4$ and the shaded red half-plane is infeasible. The unconstrained minimum $(2,3)$ is infeasible; the constrained optimum
$(1.5,\,2.5)$ is where the contour $f=0.5$ touches the line.






Python Implementation



  The listing below is complete and was run to produce every number and figure in this article (NumPy 2.5, Python 3.14).
  The penalty is the absolute-value penalty from above; selection and update are synchronous.



import numpy as np

# ---- problem -------------------------------------------------------
def objective(p):
    x, y = p
    return (x - 2) ** 2 + (y - 3) ** 2

def violation(p):
    """Amount by which g(x, y) = x + y - 4 <= 0 is violated."""
    x, y = p
    return max(0.0, x + y - 4)

RHO = 100.0

def penalized(p):
    return objective(p) + RHO * violation(p)

# ---- differential evolution (DE/rand/1/bin) ------------------------
def differential_evolution(func, bounds, NP=20, F=0.8, CR=0.7,
                           G_max=200, seed=42):
    rng = np.random.default_rng(seed)
    lo, hi = np.array(bounds, dtype=float).T
    D = len(lo)

    pop = lo + rng.random((NP, D)) * (hi - lo)      # initialization
    fit = np.array([func(p) for p in pop])

    history = [(pop.copy(), fit.copy())]
    for g in range(G_max):
        new_pop, new_fit = pop.copy(), fit.copy()
        for i in range(NP):
            # mutation: three distinct individuals, none equal to target
            others = [j for j in range(NP) if j != i]
            r1, r2, r3 = rng.choice(others, 3, replace=False)
            v = np.clip(pop[r1] + F * (pop[r2] - pop[r3]), lo, hi)

            # binomial crossover; one component is forced from the mutant
            mask = rng.random(D) <= CR
            mask[rng.integers(D)] = True
            u = np.where(mask, v, pop[i])

            # greedy selection
            fu = func(u)
            if fu <= fit[i]:
                new_pop[i], new_fit[i] = u, fu
        pop, fit = new_pop, new_fit
        history.append((pop.copy(), fit.copy()))

    best = np.argmin(fit)
    return pop[best], fit[best], history


bounds = [(0, 10), (0, 10)]
best, f_best, history = differential_evolution(
    penalized, bounds, NP=20, F=0.8, CR=0.7, G_max=200, seed=42)

print(f"best x = {best[0]:.6f}, y = {best[1]:.6f}")
print(f"f(x, y) = {objective(best):.8f},  x + y = {best.sum():.6f}")


Running the driver gives


best x = 1.500000, y = 2.500000
f(x, y) = 0.50000000,  x + y = 4.000000



  The solution agrees with the analytic result to six decimals. The run used $NP\cdot G_{\max} + NP = 4020$ objective evaluations.









Watching the Population Converge



  Fig. 5 shows the 20 individuals at four moments of the run with seed 42. At generation 0 they are scattered over the whole box and
  none of them is feasible, so the best individual (orange) is simply the one that violates the constraint least. Within three
  generations twelve individuals have landed in the feasible triangle. By generation 10, 19 of the 20 are feasible and the best one
  is already close to the optimum, but the population is still spread out. By generation 30 it has contracted into a tight cluster
  on the line $x+y=4$ – the shrinking differences $\mathbf{r}_2-\mathbf{r}_3$ at work.




  
    
    
    
    
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  0
  
  5
  
  10
  
  0
  
  5
  
  10
  
  x
  y
  g = 0
  0/20 feasible
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  0
  
  5
  
  10
  
  0
  
  5
  
  10
  
  x
  y
  g = 3
  12/20 feasible
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  0
  
  2
  
  4
  
  6
  
  0
  
  2
  
  4
  
  6
  
  x
  y
  g = 10
  19/20 feasible
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  1
  
  2
  
  3
  
  2
  
  3
  
  4
  
  x
  y
  g = 30
  20/20 feasible
  
  
  feasible
  
  infeasible
  
  best individual
  
  optimum (1.5, 2.5)

Fig. 5 – Population snapshots (seed 42, $NP=20$). Green points are feasible, red points infeasible.
The panels use different axis ranges so that the late stages remain visible. The black dot marks the true optimum $(1.5, 2.5)$.






Convergence History



  The table lists the best individual of the same run (error $=\tilde f - f^*$ with $f^*=0.5$).




  
    GenerationBest $\tilde{f}$$x$$y$$x+y$Error $\tilde f - f^*$


  
  
    0124.2024304.66720.43805.10521.2 × 102


    12.8983940.61392.01152.62542.4 × 100


    51.0806990.96052.98943.94995.8 × 10−1


    100.5385281.53432.43293.96713.9 × 10−2


    300.5020821.52062.47823.99882.1 × 10−3


    500.5001261.50232.49763.99991.3 × 10−4


    1000.5000001.50002.50004.00007.3 × 10−8


    1500.5000001.50002.50004.00001.0 × 10−10


    2000.5000001.50002.50004.00002.2 × 10−13


  


  Note that from generation 1 on the best individual is feasible ($x+y\le 4$). It then slides along the boundary towards the
  optimum from the inside (Fig. 7).




Convergence Plot



  On a logarithmic axis the error falls almost linearly, that is, geometrically fast: it shrinks by roughly a factor of ten every
  15 to 18 generations once the population has found the right region (from generation 30 to 200 the error falls from
  $2\cdot10^{-3}$ to $2\cdot10^{-13}$, ten orders of magnitude). The stairs in the curve of the best individual are
  characteristic of DE: improvement happens in bursts, whenever a trial vector beats the current best. The population mean (orange)
  lags behind because the average individual is still improving long after the best one has nearly converged. The thirty grey curves
  come from independent runs with seeds 0–29; all of them reached an error below $2\cdot10^{-12}$, so the behaviour is not a
  lucky seed.




  
    
  
  
  
  0
  
  
  25
  
  
  50
  
  
  75
  
  
  100
  
  
  125
  
  
  150
  
  
  175
  
  
  200
  
  
  10−14
  
  
  10−12
  
  
  10−10
  
  
  10−8
  
  
  10−6
  
  
  10−4
  
  
  10−2
  
  
  100
  
  
  102
  
  Generation g
  Best fitness error  f̃ − f*
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  best individual (seed 42)
  
  population mean (seed 42)
  
  30 independent runs (seeds 0–29)
  Values below 10⁻¹⁴ are drawn at the floor of the axis.

Fig. 6 – Convergence of the best penalized fitness. Error relative to the known optimum
$f^*=0.5$ on a logarithmic axis, for the run of Fig. 5 and 30 independent runs.






Trajectory of the Best Individual



  The left panel shows the coordinates of the best individual: after a few generations of large jumps, they settle at
  $x^*=1.5$ and $y^*=2.5$. The right panel plots the constraint value $x+y$. The best individual starts infeasible
  ($x+y\approx 5.1$), becomes feasible after the first generation and then creeps up to the limit $4$ from below, which is the signature of an
  active constraint: the optimum sits on the boundary.




  
    
    
  
  
  
  0
  
  
  20
  
  
  40
  
  
  60
  
  
  80
  
  
  100
  
  
  0
  
  
  1
  
  
  2
  
  
  3
  
  
  4
  
  
  5
  
  Generation g
  Coordinate
  
  
  
  
  
  
  x* = 1.5
  y* = 2.5
  
  x of best
  
  y of best
  
  
  0
  
  
  20
  
  
  40
  
  
  60
  
  
  80
  
  
  100
  
  
  2.5
  
  
  3
  
  
  3.5
  
  
  4
  
  
  4.5
  
  
  5
  
  Generation g
  Constraint value  x + y
  
  
  
  
  
  limit: x + y = 4
  infeasible
  
  g = 0: best is infeasible

Fig. 7 – Best individual, first 100 generations. Dashed lines mark the exact solution.











How Much Do the Parameters Matter?



  To see the influence of $F$, $CR$ and $NP$, the same problem was solved 30 times (seeds 0–29) for each of five settings. Fig. 8
  shows the median error over the 30 runs; the table counts how many runs reached an error below $10^{-6}$ within 200 generations and
  how many generations the successful runs needed (median).




  
    
  
  
  
  0
  
  
  25
  
  
  50
  
  
  75
  
  
  100
  
  
  125
  
  
  150
  
  
  175
  
  
  200
  
  
  10−14
  
  
  10−12
  
  
  10−10
  
  
  10−8
  
  
  10−6
  
  
  10−4
  
  
  10−2
  
  
  100
  
  
  102
  
  Generation g
  Median error  f̃ − f*  (30 runs)
  
  
  
  
  
  
  
  
  F = 0.8, CR = 0.7 (baseline)
  
  F = 0.5, CR = 0.9
  
  F = 0.8, CR = 0.1
  
  F = 0.2, CR = 0.7
  
  NP = 8 (F = 0.8, CR = 0.7)

Fig. 8 – Median error for five parameter settings (30 runs each). Values below $10^{-14}$ are drawn on the floor of the axis.







  SettingRuns with error < $10^{-6}$Median generations needed


  
    F = 0.8, CR = 0.7 (baseline)30 / 3094


    F = 0.5, CR = 0.928 / 3058


    F = 0.8, CR = 0.10 / 30–


    F = 0.2, CR = 0.72 / 3082


    NP = 8 (F = 0.8, CR = 0.7)25 / 3097


  

The median is taken over the successful runs only, so for $F=0.2$ it rests on just two runs.




  Baseline ($F=0.8$, $CR=0.7$) solved all 30 runs, but needed a median of 94 generations against 58 for the fastest setting.


  Smaller $F$, larger $CR$ ($0.5$, $0.9$) was the fastest, but two of 30 runs did not reach $10^{-6}$ within 200 generations: speed was bought with robustness.


  Low $CR$ ($0.1$) failed in every run. In two dimensions only about 10 % of the trial vectors then change both coordinates, so the search moves almost exclusively parallel to the axes, and it cannot follow a boundary that runs diagonally.


  Very small $F$ ($0.2$) stalls around an error of $10^{-3}$: the differences shrink faster than the population approaches the optimum, so the population contracts prematurely.


  A small population ($NP=8$) works most of the time but failed in 5 of 30 runs, because too few individuals reduce diversity.




  Caution. These numbers describe this particular two-variable problem and 30 runs per setting. They illustrate
  how the parameters act, not universal optimal values. For a real problem, tune $NP$, $F$ and $CR$ on a few pilot runs, and prefer
  settings that succeed in every run over settings that are merely fast on average.









Cross-Check with SciPy



  In practice you would rarely write DE yourself. SciPy ships a well-tested version that also supports other mutation strategies,
  vectorized evaluation and general constraints:



import numpy as np
from scipy.optimize import differential_evolution, LinearConstraint

f = lambda p: (p[0] - 2) ** 2 + (p[1] - 3) ** 2
res = differential_evolution(
    f, [(0, 10), (0, 10)],
    constraints=LinearConstraint([[1, 1]], -np.inf, 4),   # x + y <= 4
    seed=42, tol=1e-10, polish=False)
print(res.x, res.fun, res.nfev)


Output:


[1.50000018 2.49999982] 0.5000000000002502 1464



  It reproduces $(1.5,\,2.5)$ with $f=0.5$, again to six decimals. For comparison, the gradient-based SLSQP method
  (scipy.optimize.minimize) finds the same solution from a starting point of its choice in a handful of iterations. This is the
  expected division of labour: for a smooth, convex problem like this one a gradient-based solver is far cheaper, while DE earns its keep
  when the objective is non-smooth, noisy or has many local minima, and gradients are unavailable or unreliable.







See also. The same problem, with the same penalty and the same budget of evaluations, is solved with another metaheuristic in An Optimization Example Using the Particle Swarm Optimization Algorithm, which also compares the two methods head to head.








  Result (seed 42, $NP=20$, $F=0.8$, $CR=0.7$, 200 generations):
  Best solution: $x = 1.500000$, $y = 2.500000$  –  objective $f = 0.50000000$
  Constraint: $x + y = 4.000000 \le 4$ ✔  |  bounds $0\le x,y\le 10$ ✔
  Analytic optimum: $(1.5,\,2.5)$, $f^*=0.5$  –  final error $2.2\cdot 10^{-13}$









Practical Guidance



  Scale the variables. DE draws every coordinate from its bounds, so wildly different ranges (for instance $[0,1]$ and $[0,10^6]$) slow it down. Rescale to comparable ranges.


  Choose the budget in evaluations. The cost is $NP\cdot G_{\max}$ evaluations; set $NP$ from the dimension and $G_{\max}$ from the budget.


  Run several seeds. DE is stochastic. Agreement between independent runs is the best evidence that you found the global optimum.


  Raise $NP$ for multimodal problems and use a larger $F$ if the population converges too early.


  Polish at the end. A short run of a local, gradient-based optimizer started from the DE solution (SciPy's polish=True) gives machine-precision accuracy cheaply.


  Stop on convergence. Besides $G_{\max}$, monitor the spread of the population or the improvement of the best value.









Summary of Key Formulas



  
    StepFormulaDescription


  
  
    Initialization$x_{i,j} = L_j + \text{rand}\cdot(U_j-L_j)$Uniform random sampling within the bounds


    Mutation$\mathbf{v}_i = \mathbf{r}_1 + F(\mathbf{r}_2 - \mathbf{r}_3)$Scaled difference added to a random base vector


    Crossover$u_{i,j} = v_{i,j}$ if $\text{rand}\le CR$ or $j=j_\text{rand}$, else $x_{i,j}$Binomial, component by component


    Selection$\mathbf{x}_{i,g+1} = \mathbf{u}_{i}$ if $f(\mathbf{u}_i) \le f(\mathbf{x}_{i,g})$Greedy, one-to-one replacement


    Penalty$\tilde{f}=f+\rho\sum_k\max(0,g_k)$Exact if $\rho$ exceeds the Lagrange multiplier


  






References



  R. Storn and K. Price, “Differential Evolution – A Simple and Efficient Heuristic for Global Optimization over Continuous Spaces,” Journal of Global Optimization 11 (1997), 341–359.


  K. V. Price, R. M. Storn and J. A. Lampinen, Differential Evolution: A Practical Approach to Global Optimization, Springer, 2005.


  K. Deb, “An efficient constraint handling method for genetic algorithms,” Computer Methods in Applied Mechanics and Engineering 186 (2000), 311–338.
