Initial commit: Autonomous Mobile Robot (AMR) warehouse fleet simulator & OpenUSD digital twin
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
# Python virtual environment & caches
|
||||
.venv/
|
||||
env/
|
||||
venv/
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
*.egg-info/
|
||||
dist/
|
||||
build/
|
||||
|
||||
# IDE & OS files
|
||||
.idea/
|
||||
.vscode/
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 Om Karande
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,114 @@
|
||||
# Autonomous Mobile Robot (AMR) Warehouse Fleet Simulator & Digital Twin
|
||||
|
||||
[](https://www.python.org/)
|
||||
[](https://openusd.org/)
|
||||
[](https://www.blender.org/)
|
||||
[](LICENSE)
|
||||
|
||||
A discrete-event multi-robot warehouse fleet simulation and 3D digital twin built with **Python**, **Pixar OpenUSD**, and **Blender**. Solves dynamic pallet transport scheduling across 2 to 10 Autonomous Mobile Robots (AMRs), addressing congestion deadlocks at charging docks and narrow aisle livelocks through admission control and priority yielding.
|
||||
|
||||
---
|
||||
|
||||
## 🏭 Overview & Engineering Problem
|
||||
|
||||
In automated distribution centers, scaling multi-robot AMR fleets introduces exponential congestion:
|
||||
* **The Dock Bottleneck**: Multiple AMRs arriving simultaneously at drop-off bays cause deadlocks.
|
||||
* **Aisle Livelocks**: Head-on robot contention in two-way storage aisles causes infinite waiting cycles.
|
||||
* **Battery Depletion**: Unmanaged charging schedules lead to stranded robots blocking critical transit arteries.
|
||||
|
||||
This repository implements a benchmark discrete-event simulation comparing **Baseline**, **Congestion-Aware**, and **Optimized Admission Control** routing strategies, combined with an OpenUSD time-sampled trajectory export (`warehouse.usda`) for 3D physics and animation visualization in Blender.
|
||||
|
||||
---
|
||||
|
||||
## 📊 Performance Benchmarks & Throughput Scaling
|
||||
|
||||
Simulations run over 75 benchmark trials (3 strategies × 5 fleet sizes × 5 random seeds, 3,600 operational seconds each):
|
||||
|
||||
| Strategy | 2 Robots | 4 Robots | 6 Robots | 8 Robots | 10 Robots (Peak) | Congestion Behavior |
|
||||
| :--- | :---: | :---: | :---: | :---: | :---: | :--- |
|
||||
| **Baseline** | 148.8 t/h | 197.6 t/h | 125.8 t/h | 93.4 t/h | **78.6 t/h** | Collapses due to dock deadlocks & head-on aisle conflicts. |
|
||||
| **Congestion-Aware** | 190.2 t/h | 321.6 t/h | 261.0 t/h | 116.0 t/h | **84.0 t/h** | Reroutes around traffic, but bottlenecks at shared unloading zone. |
|
||||
| **Optimized (Admission Ctrl)** | **192.2 t/h** | **323.6 t/h** | **392.8 t/h** | **412.8 t/h** | **410.6 t/h** | **Scales cleanly (>5.2x baseline at 10 AMRs) with <39s wait/task.** |
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## 🏗️ System Architecture
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
subgraph S1["1. Discrete-Event Fleet Simulator (fleet_sim.py)"]
|
||||
A["Warehouse Grid (20x12)"] --> B["A* Pathfinding & Yield Rules"]
|
||||
C["Battery & Charging Management"] --> B
|
||||
D["Dock Admission Control"] --> B
|
||||
end
|
||||
|
||||
subgraph S2["2. Benchmarking & Analysis (experiments.py)"]
|
||||
B --> E["results/experiments.csv"]
|
||||
B --> F["results/throughput.png"]
|
||||
B --> G["results/demo.gif (Heatmap & Trajectories)"]
|
||||
end
|
||||
|
||||
subgraph S3["3. 3D Digital Twin Export (export_usd.py)"]
|
||||
B --> H["Pixar OpenUSD Stage (warehouse.usda)"]
|
||||
H --> I["Blender 5.2 Pick-and-Drop Automation"]
|
||||
end
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📁 Repository Structure
|
||||
|
||||
```
|
||||
├── experiments.py # Multi-seed throughput benchmark suite across 2-10 robots
|
||||
├── export_usd.py # Bakes 1200-frame time-sampled trajectory cache to warehouse.usda
|
||||
├── fleet_sim.py # Core discrete-event AMR simulation engine and A* routing
|
||||
├── visualize.py # Matplotlib animated live simulation & congestion heatmap
|
||||
├── results/
|
||||
│ ├── experiments.csv # Raw trial metrics (throughput, wait time, yields, replans)
|
||||
│ ├── throughput.png # Comparative scaling curves (tasks/hr vs fleet size)
|
||||
│ └── demo.gif # Animated multi-robot transit and heatmap
|
||||
├── scenes/
|
||||
│ └── warehouse.usda # Pixar OpenUSD digital twin stage
|
||||
├── .gitignore
|
||||
├── requirements.txt
|
||||
└── README.md
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Quickstart & Reproduction Guide
|
||||
|
||||
### 1. Environment Setup
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone https://github.com/omkarande14/warehouse-amr-simulation.git
|
||||
cd warehouse-amr-simulation
|
||||
|
||||
# Install dependencies
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### 2. Run Fleet Simulation & Visualizer
|
||||
```bash
|
||||
# Run animated live fleet visualization (6 robots, heatmap)
|
||||
python visualize.py
|
||||
```
|
||||
|
||||
### 3. Run Benchmark Scaling Experiments
|
||||
```bash
|
||||
# Run 75-trial benchmark suite and generate scaling curves
|
||||
python experiments.py
|
||||
```
|
||||
|
||||
### 4. Export to Pixar OpenUSD for Blender
|
||||
```bash
|
||||
# Export time-sampled 3D warehouse scene to scenes/warehouse.usda
|
||||
python export_usd.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📜 License
|
||||
Distributed under the MIT License. See `LICENSE` for details.
|
||||
@@ -0,0 +1,34 @@
|
||||
import pandas as pd
|
||||
import matplotlib
|
||||
matplotlib.use("Agg")
|
||||
import matplotlib.pyplot as plt
|
||||
from fleet_sim import run, STRATEGIES
|
||||
|
||||
KEYS = ("strategy", "robots", "seed", "tasks_per_hour", "total_wait",
|
||||
"wait_per_task", "replans", "yields", "charge_steps")
|
||||
ROBOT_COUNTS = (2, 4, 6, 8, 10)
|
||||
|
||||
rows = []
|
||||
for strat in STRATEGIES:
|
||||
for n in ROBOT_COUNTS:
|
||||
for seed in range(5):
|
||||
r = run(n, strat, seed=seed)
|
||||
rows.append({k: r[k] for k in KEYS})
|
||||
|
||||
df = pd.DataFrame(rows)
|
||||
df.to_csv("results/experiments.csv", index=False)
|
||||
summary = df.groupby(["strategy", "robots"]).mean(numeric_only=True).reset_index()
|
||||
print(summary[["strategy", "robots", "tasks_per_hour", "wait_per_task", "yields"]].round(1).to_string(index=False))
|
||||
|
||||
fig, ax = plt.subplots(1, 2, figsize=(11, 4))
|
||||
for strat, g in summary.groupby("strategy"):
|
||||
ax[0].plot(g.robots, g.tasks_per_hour, marker="o", label=strat)
|
||||
ax[1].plot(g.robots, g.wait_per_task, marker="o", label=strat)
|
||||
ax[0].set(title="Throughput vs fleet size", xlabel="Robots", ylabel="Tasks per hour")
|
||||
ax[1].set(title="Waiting time vs fleet size", xlabel="Robots", ylabel="Seconds waiting per task")
|
||||
ax[0].legend()
|
||||
ax[0].grid(alpha=0.3)
|
||||
ax[1].grid(alpha=0.3)
|
||||
fig.tight_layout()
|
||||
fig.savefig("results/throughput.png", dpi=150)
|
||||
# plt.show()
|
||||
@@ -0,0 +1,51 @@
|
||||
from pxr import Usd, UsdGeom, Gf
|
||||
from fleet_sim import run, make_grid, W, H, CHARGERS, DROP, PICKUPS
|
||||
|
||||
res = run(4, "optimized", steps=1200, seed=1, record=True)
|
||||
COL = {"TO_PICK": (0.1, 0.4, 1.0), "LOADING": (0.6, 0.2, 0.8), "TO_DROP": (0.1, 0.8, 0.2),
|
||||
"UNLOADING": (0.9, 0.2, 0.2), "TO_CHARGER": (1.0, 0.5, 0.0),
|
||||
"CHARGING": (1.0, 0.85, 0.0), "IDLE": (0.5, 0.5, 0.5)}
|
||||
Y = lambda y: H - 1 - y # flip so the 3D layout matches the 2D picture
|
||||
|
||||
stage = Usd.Stage.CreateNew("scenes/warehouse.usda")
|
||||
UsdGeom.SetStageUpAxis(stage, UsdGeom.Tokens.z)
|
||||
UsdGeom.SetStageMetersPerUnit(stage, 1.0)
|
||||
stage.SetStartTimeCode(0)
|
||||
stage.SetEndTimeCode(len(res["frames"]) - 1)
|
||||
stage.SetTimeCodesPerSecond(10) # plays 10x real time
|
||||
|
||||
def box(path, x, y, sx, sy, sz, color):
|
||||
c = UsdGeom.Cube.Define(stage, path)
|
||||
c.GetSizeAttr().Set(1.0)
|
||||
c.AddTranslateOp().Set(Gf.Vec3d(x, Y(y), sz / 2))
|
||||
c.AddScaleOp().Set(Gf.Vec3f(sx, sy, sz))
|
||||
c.GetDisplayColorAttr().Set([Gf.Vec3f(*color)])
|
||||
return c
|
||||
|
||||
UsdGeom.Xform.Define(stage, "/World")
|
||||
box("/World/Floor", W / 2 - 0.5, H / 2 - 0.5, W, H, 0.05, (0.8, 0.8, 0.8))
|
||||
for y, row in enumerate(make_grid()):
|
||||
for x, v in enumerate(row):
|
||||
if v:
|
||||
box(f"/World/Shelves/S_{x}_{y}", x, y, 0.9, 0.9, 2.0, (0.2, 0.4, 0.9))
|
||||
for i, (x, y) in enumerate(PICKUPS):
|
||||
box(f"/World/Pallets/P_{i}", x, y, 0.5, 0.5, 0.3, (0.55, 0.35, 0.15))
|
||||
box("/World/Dock", DROP[0], DROP[1], 1, 1, 0.1, (0.1, 0.8, 0.2))
|
||||
for i, (x, y) in enumerate(CHARGERS):
|
||||
box(f"/World/Charger_{i}", x, y, 1, 1, 0.1, (1.0, 0.8, 0.0))
|
||||
|
||||
robots = []
|
||||
for i in range(len(res["frames"][0])):
|
||||
c = UsdGeom.Cube.Define(stage, f"/World/Robots/R{i}")
|
||||
c.GetSizeAttr().Set(1.0)
|
||||
t_op = c.AddTranslateOp()
|
||||
c.AddScaleOp().Set(Gf.Vec3f(0.7, 0.7, 0.4))
|
||||
robots.append((c, t_op))
|
||||
|
||||
for t, frame in enumerate(res["frames"]):
|
||||
for (c, t_op), (pos, state, batt) in zip(robots, frame):
|
||||
t_op.Set(Gf.Vec3d(pos[0], Y(pos[1]), 0.3), t)
|
||||
c.GetDisplayColorAttr().Set([Gf.Vec3f(*COL[state])], t)
|
||||
|
||||
stage.GetRootLayer().Save()
|
||||
print("Saved scenes/warehouse.usda")
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
import heapq, random
|
||||
from collections import defaultdict
|
||||
|
||||
W, H = 20, 12
|
||||
PICKUPS = [(x, y) for x in range(3, 17) for y in (4, 8)]
|
||||
DROP = (19, 5)
|
||||
CHARGERS = [(0, 11), (19, 11)]
|
||||
STRATEGIES = ("baseline", "congestion", "optimized")
|
||||
|
||||
LOAD_TIME, UNLOAD_TIME = 3, 5 # seconds spent loading at a pickup / unloading at the dock
|
||||
YIELD_AFTER = 15 # blocked this long -> a dodging robot backs off to a free cell
|
||||
STATIONARY = ("LOADING", "UNLOADING", "CHARGING", "IDLE")
|
||||
|
||||
def make_grid():
|
||||
g = [[0] * W for _ in range(H)]
|
||||
for x in range(3, 17):
|
||||
for y in (2, 3, 6, 7): # shelf rows (blocked cells)
|
||||
g[y][x] = 1
|
||||
return g
|
||||
|
||||
def manhattan(a, b):
|
||||
return abs(a[0] - b[0]) + abs(a[1] - b[1])
|
||||
|
||||
def free_neighbors(grid, pos, occ):
|
||||
out = []
|
||||
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
|
||||
n = (pos[0] + dx, pos[1] + dy)
|
||||
if 0 <= n[0] < W and 0 <= n[1] < H and not grid[n[1]][n[0]] and n not in occ:
|
||||
out.append(n)
|
||||
return out
|
||||
|
||||
def astar(grid, start, goal, extra):
|
||||
pq, came, best = [(manhattan(start, goal), 0, start, None)], {}, {start: 0}
|
||||
while pq:
|
||||
_, g, cur, parent = heapq.heappop(pq)
|
||||
if cur in came:
|
||||
continue
|
||||
came[cur] = parent
|
||||
if cur == goal:
|
||||
break
|
||||
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
|
||||
n = (cur[0] + dx, cur[1] + dy)
|
||||
if not (0 <= n[0] < W and 0 <= n[1] < H) or grid[n[1]][n[0]]:
|
||||
continue
|
||||
c = g + 1 + extra.get(n, 0)
|
||||
if c < best.get(n, 1e9):
|
||||
best[n] = c
|
||||
heapq.heappush(pq, (c + manhattan(n, goal), c, n, cur))
|
||||
path, cur = [], goal
|
||||
while cur is not None:
|
||||
path.append(cur)
|
||||
cur = came[cur]
|
||||
return path[::-1]
|
||||
|
||||
class Robot:
|
||||
def __init__(self, i, pos):
|
||||
self.id, self.pos, self.goal = i, pos, pos
|
||||
self.path, self.stage = [], "IDLE"
|
||||
self.battery, self.wait, self.blocked, self.streak, self.timer = 100.0, 0, 0, 0, 0
|
||||
|
||||
def priority(self):
|
||||
# loaded robots beat charging-bound robots, which beat empty robots; ties broken by id
|
||||
rank = 2 if self.stage == "TO_DROP" else 1 if self.stage == "TO_CHARGER" else 0
|
||||
return (rank, -self.id)
|
||||
|
||||
def run(n, strategy, steps=3600, seed=1, record=False):
|
||||
rng = random.Random(seed)
|
||||
pool = [rng.choice(PICKUPS) for _ in range(5000)] # same demand for every strategy
|
||||
rng2 = random.Random(seed + 1000)
|
||||
grid = make_grid()
|
||||
robots = [Robot(i, (0, i)) for i in range(n)]
|
||||
occ = {r.pos: r for r in robots}
|
||||
patience = 10 if strategy == "baseline" else 2 # how fast a robot reroutes when blocked
|
||||
penalty = 0 if strategy == "baseline" else 5 # congestion-aware cost on occupied cells
|
||||
done = replans = charge_steps = yields = 0
|
||||
heat, frames = defaultdict(int), []
|
||||
|
||||
for t in range(steps):
|
||||
for r in robots:
|
||||
if r.stage == "IDLE":
|
||||
if r.battery < 25:
|
||||
r.goal = min(CHARGERS, key=lambda c: manhattan(c, r.pos))
|
||||
r.stage = "TO_CHARGER"
|
||||
else:
|
||||
if strategy == "optimized": # scheduling: nearest of the next 5 tasks
|
||||
j = min(range(5), key=lambda k: manhattan(pool[k], r.pos))
|
||||
r.goal = pool.pop(j)
|
||||
else: # first come, first served
|
||||
r.goal = pool.pop(0)
|
||||
r.stage = "TO_PICK"
|
||||
r.path = astar(grid, r.pos, r.goal, {p: penalty for p in occ})[1:]
|
||||
elif r.stage == "CHARGING":
|
||||
charge_steps += 1
|
||||
r.battery = min(100.0, r.battery + 1)
|
||||
if r.battery >= 100:
|
||||
r.stage = "IDLE"
|
||||
elif r.stage in ("LOADING", "UNLOADING"):
|
||||
r.timer -= 1
|
||||
if r.timer <= 0:
|
||||
if r.stage == "LOADING":
|
||||
r.goal, r.stage = DROP, "TO_DROP"
|
||||
r.path = astar(grid, r.pos, DROP, {})[1:]
|
||||
else:
|
||||
done += 1
|
||||
r.stage = "IDLE"
|
||||
elif r.path:
|
||||
nxt = r.path[0]
|
||||
# Admission control (optimized only): hold back at distance 3 from the dock
|
||||
# while 2+ robots are already within 2 cells of it, so the dock never gridlocks.
|
||||
if (strategy == "optimized" and r.stage == "TO_DROP"
|
||||
and manhattan(r.pos, DROP) == 3
|
||||
and sum(1 for o in robots if o is not r and manhattan(o.pos, DROP) <= 2) >= 2):
|
||||
r.wait += 1
|
||||
heat[r.pos] += 1
|
||||
continue
|
||||
if nxt in occ: # blocked: wait
|
||||
blocker = occ[nxt]
|
||||
r.blocked += 1
|
||||
r.streak += 1
|
||||
r.wait += 1
|
||||
heat[r.pos] += 1
|
||||
# Priority rule: only the lower-priority robot (or anyone blocked by a
|
||||
# stationary robot) dodges; the higher-priority robot simply waits.
|
||||
may_dodge = blocker.stage in STATIONARY or r.priority() < blocker.priority()
|
||||
limit = YIELD_AFTER if may_dodge else YIELD_AFTER * 3
|
||||
if r.streak >= limit: # deadlock recovery: back off to a free cell
|
||||
free = free_neighbors(grid, r.pos, occ)
|
||||
if free:
|
||||
nxt2 = rng2.choice(free)
|
||||
del occ[r.pos]
|
||||
r.pos = nxt2
|
||||
occ[nxt2] = r
|
||||
r.path = astar(grid, r.pos, r.goal, {p: 50 for p in occ if p != r.pos})[1:]
|
||||
r.blocked = r.streak = 0
|
||||
yields += 1
|
||||
continue
|
||||
if may_dodge and r.blocked >= patience: # reroute around the blocker
|
||||
r.path = astar(grid, r.pos, r.goal,
|
||||
{p: 50 for p in occ if p != r.pos})[1:]
|
||||
r.blocked = 0
|
||||
replans += 1
|
||||
else: # move one cell
|
||||
del occ[r.pos]
|
||||
r.pos = nxt
|
||||
occ[nxt] = r
|
||||
r.path.pop(0)
|
||||
r.blocked = r.streak = 0
|
||||
r.battery -= 0.05
|
||||
else: # arrived
|
||||
if r.stage == "TO_PICK":
|
||||
r.stage, r.timer = "LOADING", LOAD_TIME
|
||||
elif r.stage == "TO_DROP":
|
||||
r.stage, r.timer = "UNLOADING", UNLOAD_TIME
|
||||
elif r.stage == "TO_CHARGER":
|
||||
r.stage = "CHARGING"
|
||||
if record:
|
||||
frames.append([(r.pos, r.stage, round(r.battery)) for r in robots])
|
||||
|
||||
total_wait = sum(r.wait for r in robots)
|
||||
return {"strategy": strategy, "robots": n, "seed": seed,
|
||||
"tasks_per_hour": done * 3600 / steps, "total_wait": total_wait,
|
||||
"wait_per_task": total_wait / max(done, 1), "replans": replans,
|
||||
"yields": yields, "charge_steps": charge_steps,
|
||||
"heat": dict(heat), "frames": frames}
|
||||
|
||||
if __name__ == "__main__":
|
||||
for s in STRATEGIES:
|
||||
r = run(6, s)
|
||||
print(f"{s:11s} tasks/hr={r['tasks_per_hour']:.0f} wait/task={r['wait_per_task']:.1f}s")
|
||||
@@ -0,0 +1,5 @@
|
||||
# AMR Warehouse Fleet Simulator & Digital Twin
|
||||
numpy>=1.24.0
|
||||
matplotlib>=3.7.0
|
||||
pillow>=10.0.0
|
||||
usd-core>=24.05
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.6 MiB |
@@ -0,0 +1,76 @@
|
||||
strategy,robots,seed,tasks_per_hour,total_wait,wait_per_task,replans,yields,charge_steps
|
||||
baseline,2,0,149.0,1957,13.134228187919463,91,6,153
|
||||
baseline,2,1,151.0,1904,12.609271523178808,88,6,154
|
||||
baseline,2,2,148.0,2036,13.756756756756756,92,4,152
|
||||
baseline,2,3,151.0,1856,12.291390728476822,86,6,154
|
||||
baseline,2,4,145.0,1918,13.227586206896552,90,5,152
|
||||
baseline,4,0,199.0,7136,35.85929648241206,275,33,0
|
||||
baseline,4,1,196.0,7215,36.81122448979592,282,27,0
|
||||
baseline,4,2,199.0,7216,36.26130653266332,277,27,0
|
||||
baseline,4,3,199.0,7262,36.49246231155779,282,35,0
|
||||
baseline,4,4,195.0,7119,36.50769230769231,269,27,0
|
||||
baseline,6,0,126.0,15843,125.73809523809524,436,228,0
|
||||
baseline,6,1,136.0,15395,113.19852941176471,463,223,0
|
||||
baseline,6,2,120.0,15996,133.3,453,250,0
|
||||
baseline,6,3,120.0,16100,134.16666666666666,432,246,0
|
||||
baseline,6,4,127.0,15701,123.62992125984252,451,254,0
|
||||
baseline,8,0,89.0,23537,264.46067415730334,639,447,0
|
||||
baseline,8,1,91.0,23495,258.1868131868132,651,456,0
|
||||
baseline,8,2,92.0,23036,250.3913043478261,602,435,0
|
||||
baseline,8,3,97.0,22833,235.39175257731958,603,416,0
|
||||
baseline,8,4,98.0,22718,231.81632653061226,660,431,0
|
||||
baseline,10,0,82.0,29298,357.2926829268293,852,592,0
|
||||
baseline,10,1,80.0,29615,370.1875,807,574,0
|
||||
baseline,10,2,78.0,29825,382.37179487179486,815,615,0
|
||||
baseline,10,3,71.0,30286,426.5633802816901,836,627,0
|
||||
baseline,10,4,82.0,29153,355.5243902439024,813,574,0
|
||||
congestion,2,0,191.0,506,2.649214659685864,155,5,154
|
||||
congestion,2,1,194.0,498,2.5670103092783507,144,3,152
|
||||
congestion,2,2,188.0,534,2.8404255319148937,158,4,153
|
||||
congestion,2,3,194.0,442,2.2783505154639174,118,2,153
|
||||
congestion,2,4,184.0,479,2.6032608695652173,138,4,152
|
||||
congestion,4,0,325.0,2458,7.563076923076923,774,17,307
|
||||
congestion,4,1,327.0,2501,7.648318042813456,756,18,307
|
||||
congestion,4,2,308.0,2912,9.454545454545455,886,31,307
|
||||
congestion,4,3,329.0,2526,7.677811550151976,742,11,308
|
||||
congestion,4,4,319.0,2467,7.733542319749216,732,18,307
|
||||
congestion,6,0,306.0,9236,30.18300653594771,2061,117,135
|
||||
congestion,6,1,262.0,10769,41.103053435114504,2236,155,0
|
||||
congestion,6,2,223.0,12150,54.48430493273543,2333,190,0
|
||||
congestion,6,3,272.0,10392,38.205882352941174,2146,169,62
|
||||
congestion,6,4,242.0,11272,46.578512396694215,2245,173,0
|
||||
congestion,8,0,112.0,22355,199.59821428571428,3925,438,0
|
||||
congestion,8,1,121.0,21539,178.0082644628099,4032,444,0
|
||||
congestion,8,2,110.0,22173,201.57272727272726,3915,443,0
|
||||
congestion,8,3,87.0,23423,269.2298850574713,4075,473,0
|
||||
congestion,8,4,150.0,20572,137.14666666666668,3849,412,0
|
||||
congestion,10,0,94.0,28099,298.9255319148936,5051,591,0
|
||||
congestion,10,1,77.0,29081,377.6753246753247,4995,600,0
|
||||
congestion,10,2,84.0,28356,337.57142857142856,5058,613,0
|
||||
congestion,10,3,80.0,28919,361.4875,5186,640,0
|
||||
congestion,10,4,85.0,28252,332.3764705882353,5317,623,0
|
||||
optimized,2,0,194.0,514,2.649484536082474,153,4,153
|
||||
optimized,2,1,197.0,463,2.350253807106599,128,2,153
|
||||
optimized,2,2,189.0,531,2.8095238095238093,164,3,153
|
||||
optimized,2,3,195.0,485,2.4871794871794872,134,2,154
|
||||
optimized,2,4,186.0,449,2.413978494623656,131,3,154
|
||||
optimized,4,0,323.0,2735,8.467492260061919,626,21,307
|
||||
optimized,4,1,325.0,2792,8.590769230769231,640,20,306
|
||||
optimized,4,2,319.0,2730,8.557993730407523,625,22,307
|
||||
optimized,4,3,328.0,2697,8.222560975609756,643,21,307
|
||||
optimized,4,4,323.0,2451,7.588235294117647,573,12,307
|
||||
optimized,6,0,398.0,6522,16.386934673366834,1024,35,460
|
||||
optimized,6,1,387.0,6757,17.459948320413435,1178,59,463
|
||||
optimized,6,2,397.0,6149,15.488664987405542,932,20,459
|
||||
optimized,6,3,397.0,6202,15.622166246851386,960,26,463
|
||||
optimized,6,4,385.0,6878,17.864935064935064,1174,54,458
|
||||
optimized,8,0,413.0,11046,26.74576271186441,1312,44,386
|
||||
optimized,8,1,416.0,10879,26.151442307692307,1167,27,476
|
||||
optimized,8,2,408.0,11317,27.737745098039216,1411,59,310
|
||||
optimized,8,3,414.0,10740,25.942028985507246,1168,22,451
|
||||
optimized,8,4,413.0,10951,26.515738498789347,1299,46,384
|
||||
optimized,10,0,414.0,15678,37.869565217391305,1185,21,405
|
||||
optimized,10,1,405.0,16326,40.31111111111111,1536,56,207
|
||||
optimized,10,2,408.0,15666,38.39705882352941,1654,78,383
|
||||
optimized,10,3,412.0,16126,39.140776699029125,1216,26,307
|
||||
optimized,10,4,414.0,15674,37.85990338164251,1502,67,312
|
||||
|
Binary file not shown.
|
After Width: | Height: | Size: 107 KiB |
+10457
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,43 @@
|
||||
import numpy as np
|
||||
import matplotlib
|
||||
matplotlib.use("Agg")
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.animation import FuncAnimation, PillowWriter
|
||||
from matplotlib.lines import Line2D
|
||||
from fleet_sim import run, make_grid, W, H, CHARGERS, DROP, PICKUPS
|
||||
|
||||
N, STRATEGY, SKIP = 6, "optimized", 10
|
||||
res = run(N, STRATEGY, seed=1, record=True)
|
||||
COL = {"TO_PICK": "tab:blue", "LOADING": "tab:purple", "TO_DROP": "tab:green",
|
||||
"UNLOADING": "tab:red", "TO_CHARGER": "tab:orange", "CHARGING": "gold", "IDLE": "gray"}
|
||||
|
||||
fig, (ax, axh) = plt.subplots(1, 2, figsize=(14, 5))
|
||||
ax.imshow(np.array(make_grid()), cmap="Greys", alpha=0.6)
|
||||
ax.scatter(*zip(*CHARGERS), marker="s", s=150, c="gold", edgecolors="k")
|
||||
ax.scatter(*DROP, marker="s", s=150, c="limegreen", edgecolors="k")
|
||||
ax.scatter(*zip(*PICKUPS), marker=".", s=15, c="saddlebrown")
|
||||
sc = ax.scatter([], [], s=140, edgecolors="k")
|
||||
ax.set_title(f"{STRATEGY} strategy, {N} robots")
|
||||
ax.legend(handles=[Line2D([0], [0], marker="o", color="w", markerfacecolor=c, markeredgecolor="k",
|
||||
markersize=9, label=s) for s, c in COL.items()],
|
||||
loc="upper center", bbox_to_anchor=(0.5, -0.12), ncol=4, fontsize=8)
|
||||
|
||||
heat = np.zeros((H, W))
|
||||
for (x, y), v in res["heat"].items():
|
||||
heat[y, x] = v
|
||||
im = axh.imshow(heat, cmap="hot")
|
||||
axh.set_title("Congestion heatmap (seconds spent waiting per cell)")
|
||||
fig.colorbar(im, ax=axh, shrink=0.8)
|
||||
|
||||
def update(i):
|
||||
frame = res["frames"][i * SKIP]
|
||||
sc.set_offsets(np.c_[[p[0][0] for p in frame], [p[0][1] for p in frame]])
|
||||
sc.set_color([COL[p[1]] for p in frame])
|
||||
ax.set_xlabel(f"t={i*SKIP}s battery %: " + " ".join(f"R{k}:{p[2]}" for k, p in enumerate(frame)),
|
||||
fontsize=8)
|
||||
return (sc,)
|
||||
|
||||
ani = FuncAnimation(fig, update, frames=len(res["frames"]) // SKIP, interval=50)
|
||||
fig.tight_layout()
|
||||
ani.save("results/demo.gif", writer=PillowWriter(fps=20))
|
||||
# plt.show()
|
||||
Reference in New Issue
Block a user