Previous post: Heat Spread on a Grid Next post: Grown QWOP Walker

Medical Drone Fleet

A browser-based medical drone simulation with priority dispatch, multi-stop routing, battery-aware charging, failover, and demand-based staging.

Overview

Five drones, one depot, six hospitals, and three chargers operate under a central dispatcher. The simulated map measures 100 × 62 units, and new delivery requests arrive with three priority levels: routine, urgent, and STAT.

The dispatcher assigns requests to available drones, plans routes, sends low-battery drones to charge before they run out of power, and positions idle drones near areas of expected demand.

Try the live simulation on the project page:

  • Surge creates a burst of three to five delivery requests.
  • Fail drone disables a drone mid-shift. The action is blocked if it would leave no drones operational.
  • Click a hospital to create a delivery request with a randomly selected priority.
  • Speed cycles through 1×, 2×, and 4× playback.

The activity feed shows how the dispatcher makes decisions, including assignment scores, route costs, and drone staging. It displays the newest six of up to 30 lines, merging some repeated parking messages. This is a condensed view, not a complete event log.

All performance indicators are calculated from the simulation. They include completed orders that were late, so the dispatcher cannot improve its reported on-time rate simply by completing easy orders and ignoring difficult ones.

The same planning approach could be adapted to parcel delivery, warehouse robots, or repair crews. The locations, priorities, and scoring weights would change, but the core dispatch problem would remain similar.

Dispatch and Routing

At each simulation step, the dispatcher sorts queued requests by priority, with STAT requests first. It then scores each available drone against each open request using three factors:

  • Distance to the pickup or delivery location.
  • Remaining battery capacity.
  • Current queue load.

The factors have weights of 0.45, 0.30, and 0.25, respectively. The Hungarian algorithm finds the assignment that minimizes the combined cost across the available drone-request pairs. The activity feed shows the top three bids so the chosen assignment can be inspected.

After the initial assignments, the dispatcher builds multi-stop routes with up to three deliveries per tour. It first creates a set of assignments, then greedily adds compatible stops and applies 2-opt route improvement to reduce unnecessary travel. This helps remove crossings and inefficient detours left by the initial route construction.

Priority determines which requests are considered first, while the assignment costs help determine which drone should serve them.

Battery Management

The dispatcher checks whether a drone has enough battery to complete its planned tour and reach a charger. It estimates the energy needed for the remaining route, the return journey to the nearest available charger, and an additional safety margin.

If the drone cannot safely finish the tour, it is redirected to charge and its assigned requests return to the queue for reassignment on the next simulation step. This behavior is especially visible when a burst of new requests arrives while some drones have little battery remaining.

Charging uses separate thresholds to avoid switching repeatedly between delivery and charging:

  • The dispatcher uses an 8% energy margin and a 15% feasibility margin.
  • Charging begins when battery falls below 75% and continues toward a target of 95%.
  • Charging increases battery by 8% per second.

The dispatcher prefers chargers that are unclaimed and available, then considers other chargers if necessary. A drone already travelling to a charger is also redirected if its delivery queue becomes empty or its battery falls below 25%.

The display estimates the time required to reach the charging target. These rules are part of the simulation, not validated battery-management settings for a real aircraft.

Failure and Recovery

Use Fail drone to see how the dispatcher responds when a drone becomes unavailable. Its assigned requests return to the queue on the next simulation step, allowing the remaining fleet to take over.

The failed drone returns to service after 150 simulation ticks with a full battery. Requests that exceed their deadlines expire instead of remaining in the queue indefinitely. The simulated deadlines are 150 ticks for routine requests, 100 for urgent requests, and 60 for STAT requests. Expired requests generate an alert.

Expired requests are included when calculating the on-time rate. This prevents the metric from looking better simply because late requests disappear from the system.

These are simplified recovery rules. They demonstrate reassignment and deadline handling, but do not model real aircraft inspections, maintenance, or safety procedures after a failure.

Demand Forecasting and Drone Staging

Each new request adds demand to a cell in a 10 × 6 grid over the map. Demand fades by a factor of 0.985 per second, so recent requests influence staging more strongly than older ones.

When a cell’s demand reaches the staging threshold, the dispatcher can move an idle drone toward it. Drones avoid staging points within six map units of their current position, and the system makes at most one staging decision per tick.

This gives the fleet a simple way to anticipate where future requests may arrive instead of leaving every idle drone at the depot. The heat map shows the demand estimate, while the side rail reports the number of drones being staged.

The forecast is deliberately lightweight: it tracks recent request locations and lets their influence fade over time. It does not predict demand using a trained model or external data.

Implementation

Component Implementation
Assignment Hungarian algorithm, with STAT requests prioritized
Routing Two-stage route construction, greedy stop insertion, and 2-opt improvement
Route size Up to three deliveries per tour
Battery management Tour energy estimate, charger diversion, charging thresholds, and a 95% target
Failure recovery Requeue requests after failure; restore the drone after 150 ticks
Demand model 10 × 6 grid with 0.985 decay per tick
Simulation Fixed-step 2D simulation, seed 20260918, simulation step 0.2, dispatcher interval 0.6
Request generation A request opportunity every seven seconds, with a 0.75 probability of creating an order
Rendering Canvas 2D map and a DOM-based activity rail, without external rendering libraries

Why use classical planning instead of a learned controller?

Assignment and short-route planning are well-studied problems with established algorithms. Here, the dispatcher needs to satisfy clear constraints, such as delivery priority, route length, and battery reserve. Classical methods make these decisions easier to inspect and debug than a learned controller whose choices may be harder to explain.

Learning could still be useful for estimating future demand, where patterns may be too complex for a simple rule-based model. In this demo, demand forecasting uses a fading grid instead.

Limitations

The results come entirely from a seeded simulation with generated requests. The map, delivery flow, battery behavior, and failures are simplified, and the reported KPIs do not represent real medical-drone operations.

The activity feed is also a condensed view: it retains only the newest six of up to 30 lines and merges some repeated parking messages. It should not be treated as a complete audit log, even though the displayed scores and counts come from the simulation.

The next meaningful evaluation would replay the dispatcher against logged delivery requests and realistic travel, battery, and weather constraints. That would help determine whether the assignment and staging rules remain useful under real operating conditions.

References