9.4 KiB
9.4 KiB
Phase 3 Implementation Report: Discrete-Event Simulation Engine
1. Phase Name and Objective
Phase 3: Discrete-Event Simulation Engine
The objective of Phase 3 is to design, implement, test, and document the core discrete-event simulation engine for the Warehouse Robot Fleet Digital Twin. This system coordinates:
- SimPy-driven discrete-event simulation with deterministic master clock execution.
- Multi-zone order generation processes:
- Zone A: High-frequency stochastic Poisson order arrivals for fast-moving goods.
- Zone B: Low-frequency stochastic arrivals for heavy specialized items, navigating wider heavy-duty aisles (
4.0\text{m}width) and strictly restricted to Heavy AMRs. - Zone C: Scheduled batch arrivals feeding production lines with strict delivery deadlines.
- Replenishment: Automated stock restock tasks triggered when inventory falls below minimum thresholds.
- Fleet dispatching with pluggable policies (
priority_nearest_idle), AMR payload ratings, zone accessibility checks, and battery headroom filtering. - Robot agent mission execution lifecycles: empty transit, picking & stock reservation, loaded transit, dropoff, and automatic opportunity/mandatory recharging.
- Structured event telemetry streamed to JSONL (
logs/simulation_events.jsonl). - CLI subcommand
run-simwith configurable duration and seed parameters.
2. Deliverables Completed
| Deliverable | Status | Description |
|---|---|---|
src/warehouse_twin/simulation/order_generator.py |
Complete | WorkloadConfig and OrderGenerator implementing Zone A (Poisson), Zone B (Gaussian / wide aisles), Zone C (Scheduled line feed), and Replenishment order generation. |
src/warehouse_twin/simulation/dispatcher.py |
Complete | DispatcherSettings and FleetDispatcher with priority queueing, shortest-path distance calculation, AMR compatibility filtering, and batch dispatching. |
src/warehouse_twin/simulation/sim_engine.py |
Complete | SimulationEnvironment and SimulationMetrics managing SimPy processes, robot mission lifecycles, stock reservation/consumption, opportunity charging, and KPI aggregation. |
src/warehouse_twin/simulation/__init__.py |
Complete | Exported simulation classes and dataclasses. |
src/warehouse_twin/domain/inventory.py |
Complete | Added items, available_quantity, and restock compatibility accessors. |
src/warehouse_twin/domain/robot.py |
Complete | Added is_available property, updated assign_task and complete_task. |
src/warehouse_twin/domain/task.py |
Complete | Added TaskPriority enum, TaskType aliases, assign_to_robot, start_execution, complete lifecycle helpers. |
src/warehouse_twin/domain/events.py |
Complete | Added aliases to SimulationEventType and optional spatial metadata attributes. |
src/warehouse_twin/routing/graph_builder.py |
Complete | Configured wider aisles (4.0\text{m} spacing) for slow-moving Zone B. |
src/warehouse_twin/cli.py |
Complete | Added run-sim CLI subcommand with --duration, --seed, --output-events. |
tests/unit/test_order_generator.py |
Complete | 6 unit tests covering all zone order generators, replenishment, and peak demand multipliers. |
tests/unit/test_dispatcher.py |
Complete | 4 unit tests covering priority queue sorting, heavy payload matching, Zone B restriction, and battery headroom. |
tests/unit/test_sim_engine.py |
Complete | 5 unit tests covering environment creation, short runs, deterministic seed reproducibility, event logging, and KPI metrics. |
3. Configuration Parameters Used
config/warehouse.json:zone_b:aisle_widthupdated to4.0\text{m}(wide heavy-duty aisles for specialized inventory and heavy AMRs).
config/simulation.json:duration_seconds: 3,600s (1.0 hour).random_seed: 42.- Workload arrival rates: Zone A (
60.0\,\text{orders/hr}), Zone B (15.0\,\text{orders/hr}), Zone C (600.0\,\text{s}feed interval). - Peak demand:
1.5\timesmultiplier betweent = 1200\text{s}andt = 2400\text{s}. - Operational times: Pickup
15.0\text{s}, Dropoff15.0\text{s}, Heavy pickup overhead30.0\text{s}, Lead time300.0\text{s}.
config/dispatch_policies.json:- Policy:
priority_nearest_idle(priority weight 0.6, distance weight 0.4). - Mandatory charging threshold:
20.0\%, Opportunistic threshold:60.0\%.
- Policy:
4. Architecture and Design Decisions
- Wider Aisles in Zone B (Slow-Moving & Specialized Inventory):
- In
WarehouseGraphBuilder, Zone B aisles are constructed with a4.0\text{m}column step (x \in [32.0, 36.0, 40.0, 44.0]), double the2.0\text{m}spacing of Zone A. - This accommodates heavy pallet chassis and wide loads (
650\,\text{kg}transmissions,850\,\text{kg}frames) while maintaining strong connectivity to the South and North perimeter transit highways.
- In
- Deterministic Discrete-Event Simulation:
- The master clock is driven by SimPy (
simpy.Environment). All stochastic generation is seeded via Python'srandom.Random(seed). - Executing two simulation runs with identical seeds produces byte-identical task sequences, robot paths, and metric reports.
- The master clock is driven by SimPy (
- Multi-Zone Decoupled Workload Generators:
- Zone A uses an exponential distribution (
expovariate) reflecting Poisson arrivals of fast-moving orders. - Zone B uses a normal distribution (
gauss) with larger inter-arrival times reflecting slow-moving heavy parts. - Zone C uses deterministic timers for scheduled factory production-line feeds.
- Zone A uses an exponential distribution (
- Pre-Dispatch Compatibility & Priority Scheduling:
- The task queue sorts tasks by
(priority, deadline, release_time)ensuring urgent production feeds (Priority 1) preempt lower-priority tasks. FleetDispatcherchecks AMR payload rating and zone restrictions, ensuringlight_amris never assigned heavy loads or Zone B routes.
- The task queue sorts tasks by
- Real-Time Energy Tracking & Opportunity Charging:
- Robots consume energy proportionally to mission phase (
moving_empty,idle,moving_loaded). - If State of Charge falls below
25\%, the AMR automatically disengages from task queues, routes to an available charging bay, and fast-charges to95\%SoC at10\,\text{kW}.
- Robots consume energy proportionally to mission phase (
5. Code Structure and Module Descriptions
src/warehouse_twin/simulation/
├── __init__.py # Package exports
├── dispatcher.py # FleetDispatcher and DispatcherSettings
├── order_generator.py # OrderGenerator and WorkloadConfig
└── sim_engine.py # SimulationEnvironment and SimulationMetrics
6. Integration Points with Previous Phases
- Phase 0 (Foundation): Consumes
ConfigBundle, logging configuration, and pytest test runner. - Phase 1 (Warehouse Model): Leverages
WarehouseModel, stations, racks, and the navigation graph for network shortest-path distances and travel times. - Phase 2 (Robot & Task Models): Utilizes
Robot,RobotState,Task,TaskType,TaskPriority,InventoryCatalog, andSimulationEvent.
7. Verification and Testing Results
- Unit Test Suite: 72 passing tests across 11 test suites in 0.37 seconds.
tests/unit/test_config_loader.py 9 passed tests/unit/test_dispatcher.py 4 passed tests/unit/test_environment.py 5 passed tests/unit/test_events_model.py 1 passed tests/unit/test_inventory_model.py 4 passed tests/unit/test_logging.py 3 passed tests/unit/test_order_generator.py 6 passed tests/unit/test_robot_model.py 14 passed tests/unit/test_sim_engine.py 5 passed tests/unit/test_task_model.py 9 passed tests/unit/test_warehouse_graph.py 12 passed ============================== 72 passed in 0.37s ============================== - CLI Benchmark (1-Hour Simulation):
warehouse-twin run-sim --duration 3600 --seed 42- Tasks Created: 86
- Tasks Completed: 84
- Throughput:
84.00\,\text{tasks/hr} - Average Turnaround Time:
96.3\,\text{s} - Average Wait Time:
31.9\,\text{s} - On-Time Delivery Rate:
100.0\% - Fleet Utilization:
53.2\% - Replenishment Triggers: 1
8. Known Limitations and Assumptions
- Movement between waypoints assumes constant nominal velocities and average turning overheads. Dynamic multi-robot conflict resolution and spatial reservation grids are scheduled for Phase 4.
- Telemetry events stream to single JSONL files without chunking (capped per run).
9. Instructions for Running and Validating
Run the Full Test Suite
./.venv/bin/pytest tests/
Run a 30-Minute Simulation
./.venv/bin/warehouse-twin run-sim --duration 1800 --seed 42
Run a 1-Hour Benchmark with Custom Event Output
./.venv/bin/warehouse-twin run-sim --duration 3600 --seed 42 --output-events logs/sim_run.jsonl
10. Next Phase Dependencies and Handoff
- Phase 4 (Routing and Fleet Assignment) will introduce:
- Time-space reservation grids to eliminate intersection and aisle deadlocks.
- Dynamic A* or multi-agent path finding (MAPF) over the warehouse graph.
- Real-time congestion-aware edge weighting.
11. Artifacts and Output Files
logs/simulation_events.jsonl: Discrete simulation telemetry events.results/reports/warehouse_graph.json: Topological navigation graph with wider Zone B aisles.omniverse/scenes/warehouse_phase2.usda: 3D OpenUSD scene representation.