Skip to the content.

Ant colony: a pheromone trail per tier, sampled against a delay heuristic

What it shows

Which tier earns the load is not fixed, it is negotiated by the traffic itself. AntColonyOrchestrator keeps one pheromone trail per tier (Mist, Edge, Cloud), seeded at INITIAL_PHEROMONE = 0.5. In find_computing_node a tier is sampled with a weight that multiplies the trail by a delay heuristic, weight = pheromone ** ALPHA / (1 + delay) ** BETA with ALPHA = 1.0 and BETA = 2.0, so a fast tier is preferred from the first task while the trail still adapts. In results_returned the trail of the tier that ran the task is updated as (1 - EVAPORATION) * P + EVAPORATION * quality with EVAPORATION = 0.1, where quality is max_latency / (max_latency + total_delay) for a success and 0 for a failure, and the result is clamped between MIN_PHEROMONE = 0.05 and MAX_PHEROMONE = 5.0. Those bounds are the point: a failed tier never drops to zero, so it stays a candidate, and a lucky tier never saturates, so one early win cannot lock the choice. Inside the chosen tier the node with the smallest estimated delay, counting the tasks already pending on it, executes the task.

flowchart TD
    task["Task"] --> best["_best_node per tier"]
    best --> weight["weight = pheromone^1.0 / (1+delay)^2.0"]
    weight --> sample["_sample over the three tiers"]
    sample --> run["Run on Mist, Edge or Cloud"]
    run --> result{"task SUCCESS?"}
    result -->|yes| q["quality = lat / (lat + delay)"]
    result -->|no| z["quality = 0.0"]
    q --> trail["P = 0.9*P + 0.1*quality"]
    z --> trail
    trail --> clamp["clamp to 0.05 .. 5.0"]
    clamp --> best
    classDef trail_style fill:#cfe8ff,stroke:#333;
    class trail,clamp trail_style;

The scenario

settings/ runs one scenario, once, on a fixed seed:

Run it

From the repository root, after pip install -e .:

python examples/ant_colony/ant_colony.py

No-install variant:

PYTHONPATH=src python examples/ant_colony/ant_colony.py

What to look for

ANT_COLONY               devices= 300 tasks= 16870 ok= 12352 avg_delay=0.1666   cloud= 2113 edge=12926 mist= 1831 energy=77.6697

Tune ALPHA up to trust the trail more and the heuristic less, or raise EVAPORATION to make the colony forget old outcomes faster.

Files

Where to go next