Bacterial Foraging Optimization (BFO) Explorer © 2026 Theodore P. Pavlic · MIT License

A layered exploration of Passino's (2002) Bacterial Foraging Optimization (BFO) — this tab isolates the cell-to-cell signaling and chemotaxis that drive each individual bacterium. Tab ② extends the same mechanics to 2-D. Tab ③ adds reproduction and elimination-dispersal to complete the full algorithm.

Cell-to-cell communication is implemented with attractants and repellants that diffuse into the surrounding space. Each bacterium emits an attractant Ja (positive Gaussian, above axis) and a repellant Jr (negative Gaussian, below axis). Their sum Jcc creates a ring of preferred separation: short-range repulsion fading to moderate-range attraction. This emergent spacing is BFO's key ecological advantage over algorithms like PSO — bacteria maintain population diversity automatically through mutual repulsion, without a separate crowding or niching mechanism.

Drag the fixed bacteria (●) or the mobile bacterium (◆ m). Enable the nutrient gradient to add an environmental reward Jenv; toggle all mobile to let every bacterium chemotax simultaneously. In all-mobile mode each bacterium navigates its own personal Jtotal (excluding its own self-signal), so the stable configuration is a Nash equilibrium: no individual can improve by moving given the others' positions. Enable all landscapes to see each agent's private Jtotal curve and observe why their peaks differ.

— idle —
Fixed bacteria Mobile (m) Ja (fixed) Ja (mobile) Jr (fixed) Jr (mobile) Jcc (mobile) Mobile trail
Mobile θ
Jccm)
Jenvm)
Jtotalm)
Algorithm Reference — BFO Cell-to-Cell Signaling & Chemotaxis (Passino 2002)
Cell-to-Cell Signal
given bacteria positions {θi}, i = 1…S ha, σa ← attractant height & width (std. dev.) dr, σr ← repellant depth & width (std. dev.) ▷ Per-bacterium contributions at test point θ: Jia(θ) ← ha · exp(−‖θ−θi‖² / σa²) ← positive peak, above axis Jir(θ) ← −dr · exp(−‖θ−θi‖² / σr²) ← negative well, below axis ▷ Total cell-to-cell reward at θ: Jcc(θ) ← Σi=1S [ Jia(θ) + Jir(θ) ] Jtotal(θ) ← Jcc(θ) + Jenv(θ) ← maximise σr² ≪ σa² → narrow repellant, wide attraction ⟹ moat of preferred separation d* exists σr² ≥ σa² → repellant as wide as attractant ⟹ moat collapses → pure repulsion everywhere
Note: Passino (2002) uses da (depth) and hr (height) under his cost-minimization convention where attractant subtracts from cost and repellant adds to it. Here the sign is flipped to maximization, so the attractant is a positive peak (height → ha) and the repellant is a negative well (depth → dr). Passino's wa = 1/σa², wr = 1/σr². Sliders use σ directly; the kernel squares it internally. Self-signaling: Passino's original formulation sums over all S bacteria including self. This widget excludes self by default, which can help stabilize trajectories, but inclusion can be toggled back on.
Chemotaxis Phase (1-D)
given step size C, swim length Ns θmob ← current position of the mobile bacterium Jtotal(θ) = Jcc(θ) + Jenv(θ) ← higher Jtotal = better position ▷ Tumble: Δ ← random direction (±1) ← unit tumble in 1-D θnew ← clamp(θmob + C · Δ, domain) ▷ Swim (greedy ascent on Jtotal): if Jtotalnew) > Jtotalmob) then θmob ← θnew ← accept uphill step for s = 1 to Ns do θnxt ← clamp(θmob + C · Δ) if Jtotalnxt) > Jtotalmob) then θmob ← θnxt ← keep swimming ↑ else break ← downhill: stop end for end if ← else: tumble again next step