Physarum (Slime-Mould Agents)
別名: slime mould、Physarum transport network、agent trail-following
初出 2010 · Jeff Jones — The widely-used computational model was formalized by Jeff Jones, "Characteristics of pattern formation and evolution in approximations of Physarum transport networks" (Artificial Life, MIT Press, 2010). · 年表 ↗
コミュニティ・通称 名称 — 記述的命名。粘菌 Physarum polycephalum の輸送ネットワークを近似することにちなむ (モデルは Jones 2010 が定式化)。人名エポニムではない。
ひとことで 多数の単純なエージェント(粒子)が、共有された拡散するトレイル(誘引物質)マップを感知・追従し、そこへ物質を堆積させるエージェントベースのモデル。局所的な「感知・堆積・移動」の規則だけから、粘菌 Physarum polycephalum の採餌行動に似た葉脈状の動的な輸送網が自己組織化する。
コード
上のデモの実際のスケッチ(サンドボックスで再現可能)。これで全部です。
physarum/index.html
// Physarum (slime-mould) transport networks, after Jeff Jones' agent model
// (2010). Each of many agents senses the chemo-attractant trail at three points
// ahead (left / centre / right), steers toward the strongest, steps forward and
// deposits more trail. The trail field diffuses (blur) and decays every tick.
// Purely local sensing + reinforcement → emergent vein-like networks. Canvas 2D.
const SEED = (Math.random() * 1e9) | 0;
let rs = SEED >>> 0 || 1;
function rnd(){ rs ^= rs<<13; rs ^= rs>>>17; rs ^= rs<<5; rs >>>= 0; return rs / 4294967296; }
const cv = document.getElementById('c');
const ctx = cv.getContext('2d');
const DIM = Math.floor(Math.min(window.innerWidth, window.innerHeight));
const RES = Math.min(DIM, 400); // higher res + small sensor ⇒ many channels (a fine mesh, not a few lines)
cv.width = cv.height = RES;
cv.style.width = cv.style.height = DIM + 'px';
// --- Jones parameters (the values that reliably reticulate) ---
const N = Math.floor(RES * RES * 0.30); // agent density
const SO = 5; // sensor offset distance (px) — small vs the grid ⇒ fine mesh
const SA = 22.5 * Math.PI / 180; // sensor angle
const RA = 22.5 * Math.PI / 180; // rotation (turn) angle
const STEP = 1.0; // move distance
const DEPOSIT = 3.0; // trail dropped per step
const DECAY = 0.96; // multiplicative decay after diffuse (higher ⇒ veins persist,
// so more of the network is visible at once)
const CAP = 255; // trail saturation (bounds runaway feedback)
const DIFFUSE = 0.35; // blur strength — light, so distinct veins survive
const NOISE = 5 * Math.PI / 180; // heading jitter/step — breaks the perfect alignment
// that otherwise locks agents into parallel bands
let trail = new Float32Array(RES * RES);
let buf = new Float32Array(RES * RES);
const ax = new Float32Array(N), ay = new Float32Array(N), ah = new Float32Array(N);
for (let i = 0; i < N; i++) {
ax[i] = rnd() * RES; ay[i] = rnd() * RES; ah[i] = rnd() * Math.PI * 2; // uniform seeding
}
const wrap = (v) => (v % RES + RES) % RES;
function senseAt(x, y, a) {
const sx = wrap(Math.round(x + Math.cos(a) * SO));
const sy = wrap(Math.round(y + Math.sin(a) * SO));
return trail[sy * RES + sx];
}
function agents() {
for (let i = 0; i < N; i++) {
const x = ax[i], y = ay[i], h = ah[i];
const F = senseAt(x, y, h);
const FL = senseAt(x, y, h - SA);
const FR = senseAt(x, y, h + SA);
let nh = h;
if (F > FL && F > FR) { /* strongest ahead → keep heading */ }
else if (F < FL && F < FR) nh = h + (rnd() < 0.5 ? -RA : RA); // valley ahead → random turn
else if (FR > FL) nh = h + RA; // steer right
else if (FL > FR) nh = h - RA; // steer left
nh += (rnd() - 0.5) * 2 * NOISE; // small jitter
const nx = wrap(x + Math.cos(nh) * STEP);
const ny = wrap(y + Math.sin(nh) * STEP);
ax[i] = nx; ay[i] = ny; ah[i] = nh;
const di = (ny | 0) * RES + (nx | 0);
trail[di] = Math.min(CAP, trail[di] + DEPOSIT); // deposit (saturating)
}
}
function diffuseDecay() {
for (let y = 0; y < RES; y++) {
const y0 = ((y - 1 + RES) % RES) * RES, y1 = y * RES, y2 = ((y + 1) % RES) * RES;
for (let x = 0; x < RES; x++) {
const xl = (x - 1 + RES) % RES, xr = (x + 1) % RES;
const s = trail[y0+xl]+trail[y0+x]+trail[y0+xr]
+ trail[y1+xl]+trail[y1+x]+trail[y1+xr]
+ trail[y2+xl]+trail[y2+x]+trail[y2+xr];
const c = trail[y1 + x];
// light blur: blend current cell toward the 3x3 mean, then decay
const v = (c + (s / 9 - c) * DIFFUSE) * DECAY;
buf[y1 + x] = v > CAP ? CAP : v;
}
}
const t = trail; trail = buf; buf = t;
}
const img = ctx.createImageData(RES, RES);
function render() {
const d = img.data;
for (let i = 0; i < RES * RES; i++) {
const v = Math.min(1, trail[i] / 40); // normalise (lower ⇒ faint secondary trails show)
const g = Math.pow(v, 0.7); // gamma for glow
d[i*4] = 255 * Math.min(1, g * 1.15); // warm yellow-white veins
d[i*4+1] = 255 * Math.min(1, g * 0.95);
d[i*4+2] = 255 * Math.min(1, g * g * 0.55 + g * 0.15);
d[i*4+3] = 255;
}
ctx.putImageData(img, 0, 0);
}
function tick() { agents(); diffuseDecay(); }
function loop() { tick(); tick(); render(); requestAnimationFrame(loop); }
loop();仕組み
2D のトレイルマップと、位置・向きを持つエージェント群を用意し、各ステップで「前方3点(左・中央・右)の感知 → トレイルの濃い方へ回転 → 前進して堆積」を行う。ステップ間にトレイルを拡散・減衰させる。堆積・拡散・減衰の相互作用でエージェントが経路を強化し合い、自己組織化する網が絶えず再配線される。
パラメータ
agentCount: number — Number of slime-mould agents.sensorAngle: number — Angle of the left/right sensors from the agent's heading.sensorDistance: number — How far ahead each agent senses the trail map.turnAngle: number — Rotation applied when steering toward the strongest trail.depositAmount: number — Trail strength each agent lays down per step.decayRate: number — Rate at which the trail map fades each frame.
系譜
このアルゴリズムを使う作品 (1)
最終更新 2026-07-16