import sys import copy from pathlib import Path import networkx as nx from warehouse_twin.optimization.layout_optimizer import ( LayoutOptimizer, LayoutVariant, LAYOUT_REGISTRY ) from warehouse_twin.analytics.experiment_runner import ExperimentRunner, ExperimentConfig from warehouse_twin.domain.warehouse import WarehouseModel, NodeType, Position3D from warehouse_twin.routing.graph_builder import WarehouseGraphBuilder def test_efficiency_prototype(): opt = LayoutOptimizer() wh_cfg = opt.get_warehouse_config(LayoutVariant.HYBRID_OPTIMAL) inv_cfg = opt.get_inventory_config(LayoutVariant.HYBRID_OPTIMAL) warehouse_model = WarehouseModel.from_dict(wh_cfg) builder = WarehouseGraphBuilder(warehouse_model) graph = builder.build_topological_graph() # Add cross connectors from x=26.0 to x=24.0 (Zone A) at y=6, 10, 14, 18, 22, 26, 30, 34 for y in [6.0, 10.0, 14.0, 18.0, 22.0, 26.0, 30.0, 34.0]: wp_24 = f"wp_240_{int(round(y * 10))}" wp_26 = f"wp_260_{int(round(y * 10))}" if graph.has_node(wp_24) and graph.has_node(wp_26): for src, dst in [(wp_24, wp_26), (wp_26, wp_24)]: graph.add_edge( src, dst, distance=2.0, speed_limit=1.5, traversal_time=2.0 / 1.5, is_one_way=False, allowed_robot_types={"light_amr", "heavy_amr"}, zone="zone_a", ) # Apply directional highways for efficiency: # South y=2.0: Eastbound # North y=38.0: Westbound # West x=2.0: Southbound # East x=58.0: Northbound # Connector x=26.0: Northbound (vy > uy) # Connector x=46.0: Northbound (vy > uy) edges_to_remove = [] for u, v, data in graph.edges(data=True): u_data = graph.nodes[u] v_data = graph.nodes[v] if u_data.get("node_type") != NodeType.WAYPOINT.value or v_data.get("node_type") != NodeType.WAYPOINT.value: continue ux, uy = round(float(u_data["x"]), 1), round(float(u_data["y"]), 1) vx, vy = round(float(v_data["x"]), 1), round(float(v_data["y"]), 1) # South perimeter highway (y=2.0): Eastbound only if uy == 2.0 and vy == 2.0: if vx < ux: edges_to_remove.append((u, v)) elif vx > ux: data["is_one_way"] = True # North perimeter highway (y=38.0): Westbound only elif uy == 38.0 and vy == 38.0: if vx > ux: edges_to_remove.append((u, v)) elif vx < ux: data["is_one_way"] = True # West perimeter highway (x=2.0): Southbound only elif ux == 2.0 and vx == 2.0: if vy > uy: edges_to_remove.append((u, v)) elif vy < uy: data["is_one_way"] = True # East perimeter highway (x=58.0): Northbound only elif ux == 58.0 and vx == 58.0: if vy < uy: edges_to_remove.append((u, v)) elif vy > uy: data["is_one_way"] = True # Connector at x=26.0: Northbound only (vy > uy) elif ux == 26.0 and vx == 26.0: if vy < uy: edges_to_remove.append((u, v)) elif vy > uy: data["is_one_way"] = True # Connector at x=46.0: Northbound only elif ux == 46.0 and vx == 46.0: if vy < uy: edges_to_remove.append((u, v)) elif vy > uy: data["is_one_way"] = True for u, v in edges_to_remove: if graph.has_edge(u, v): graph.remove_edge(u, v) import dataclasses runner = ExperimentRunner(opt.config_dir) runner.raw_config = dataclasses.replace( runner.raw_config, warehouse=wh_cfg, inventory=inv_cfg, ) config = ExperimentConfig( experiment_id="test_eff_prototype", name="Efficiency Prototype", description="Testing Northbound x=26 and Zone A spurs", seed=42, duration_seconds=3600.0, output_dir="results/experiments/test_eff_proto", orders_file="data/input/demo_orders.csv", preventive_traffic_coordination=True, custom_graph=graph, ) res = runner.run_single(config) kpi = res.kpi_report print("=== Efficiency Prototype Results ===") print(f" Throughput: {kpi.throughput_tasks_per_hour:.1f} tasks/hr") print(f" Completed: {kpi.tasks_completed}/{kpi.tasks_created}") print(f" Turnaround mean: {kpi.turnaround_time.mean:.2f}s | p90: {kpi.turnaround_time.p90:.2f}s") print(f" Total Distance: {kpi.total_travel_distance_meters:.2f}m (Loaded: {kpi.loaded_distance_ratio_percent:.1f}%)") print(f" Total Energy: {kpi.total_energy_consumed_kwh:.4f} kWh ({kpi.energy_intensity_kwh_per_task:.4f} kWh/task)") print(f" Conflicts: {kpi.conflicts_detected} | Unresolved: {kpi.unresolved_conflicts} | Wait: {kpi.total_yield_wait_time_seconds:.1f}s") print(f" Min Fleet Battery: {kpi.min_fleet_battery_percent:.1f}%") if __name__ == "__main__": test_efficiency_prototype()