Update warehouse digital twin and robot fleet optimization
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
import copy
|
||||
import dataclasses
|
||||
import json
|
||||
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.domain.robot import Robot, RobotState
|
||||
from warehouse_twin.domain.task import Task
|
||||
from warehouse_twin.simulation.dispatcher import FleetDispatcher, DispatcherSettings
|
||||
from warehouse_twin.routing.graph_builder import WarehouseGraphBuilder
|
||||
from warehouse_twin.routing.path_planner import PathPlanner
|
||||
|
||||
def test_all_six_candidates():
|
||||
opt = LayoutOptimizer()
|
||||
wh_baseline = opt.get_warehouse_config(LayoutVariant.HYBRID_OPTIMAL)
|
||||
inv_cfg = opt.get_inventory_config(LayoutVariant.HYBRID_OPTIMAL)
|
||||
|
||||
# 1. Candidate A: Baseline Stage 3
|
||||
print("Testing Candidate A (Stage 3 Baseline)...")
|
||||
res_a = opt.run_variant_experiment(
|
||||
variant=LayoutVariant.HYBRID_OPTIMAL,
|
||||
duration_seconds=3600.0,
|
||||
seed=42,
|
||||
output_dir="results/experiments/cand_a",
|
||||
orders_file="data/input/demo_orders.csv",
|
||||
preventive_traffic_coordination=True,
|
||||
)
|
||||
kpi_a = res_a.kpi_report
|
||||
|
||||
# Candidate D Charging Config
|
||||
wh_d = copy.deepcopy(opt.raw_config.get("warehouse", {}))
|
||||
wh_d["charging_stations"] = [
|
||||
{"station_id": "charge_bay_1", "position": [4.0, 36.0, 0.0], "charging_rate_kw": 25.0, "capacity": 1, "description": "Zone A Inbound Charger 1"},
|
||||
{"station_id": "charge_bay_2", "position": [8.0, 36.0, 0.0], "charging_rate_kw": 25.0, "capacity": 1, "description": "Zone A Inbound Charger 2"},
|
||||
{"station_id": "charge_bay_3", "position": [12.0, 36.0, 0.0], "charging_rate_kw": 25.0, "capacity": 1, "description": "Zone A Outbound Charger 1"},
|
||||
{"station_id": "charge_bay_4", "position": [30.0, 2.0, 0.0], "charging_rate_kw": 50.0, "capacity": 1, "description": "Zone B Heavy AMR Charger 1"},
|
||||
{"station_id": "charge_bay_5", "position": [34.0, 2.0, 0.0], "charging_rate_kw": 50.0, "capacity": 1, "description": "Zone B Heavy AMR Charger 2"},
|
||||
{"station_id": "charge_bay_6", "position": [42.0, 36.0, 0.0], "charging_rate_kw": 50.0, "capacity": 1, "description": "Zone B North Transfer Charger"},
|
||||
{"station_id": "charge_bay_7", "position": [48.0, 36.0, 0.0], "charging_rate_kw": 50.0, "capacity": 1, "description": "Zone C Production Charger 1"},
|
||||
{"station_id": "charge_bay_8", "position": [52.0, 36.0, 0.0], "charging_rate_kw": 50.0, "capacity": 1, "description": "Zone C Production Charger 2"},
|
||||
]
|
||||
|
||||
# Graph with improved circulation
|
||||
def get_circ_graph(wh_config):
|
||||
model = WarehouseModel.from_dict(wh_config)
|
||||
builder = WarehouseGraphBuilder(model)
|
||||
graph = builder.build_topological_graph()
|
||||
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",
|
||||
)
|
||||
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)
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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)
|
||||
return graph
|
||||
|
||||
# Candidate E: Improved traffic & circulation
|
||||
print("Testing Candidate E (Circulation & Traffic)...")
|
||||
runner_e = ExperimentRunner(opt.config_dir)
|
||||
runner_e.raw_config = dataclasses.replace(
|
||||
runner_e.raw_config,
|
||||
warehouse=wh_baseline,
|
||||
inventory=inv_cfg,
|
||||
)
|
||||
graph_e = get_circ_graph(wh_baseline)
|
||||
res_e = runner_e.run_single(ExperimentConfig(
|
||||
experiment_id="cand_e",
|
||||
name="Candidate E",
|
||||
description="Circulation & Traffic Coordination",
|
||||
seed=42,
|
||||
duration_seconds=3600.0,
|
||||
output_dir="results/experiments/cand_e",
|
||||
orders_file="data/input/demo_orders.csv",
|
||||
preventive_traffic_coordination=True,
|
||||
custom_graph=graph_e,
|
||||
))
|
||||
kpi_e = res_e.kpi_report
|
||||
|
||||
# Candidate F: Combined Stage 3.1
|
||||
print("Testing Candidate F (Combined Best)...")
|
||||
runner_f = ExperimentRunner(opt.config_dir)
|
||||
runner_f.raw_config = dataclasses.replace(
|
||||
runner_f.raw_config,
|
||||
warehouse=wh_d,
|
||||
inventory=inv_cfg,
|
||||
)
|
||||
graph_f = get_circ_graph(wh_d)
|
||||
res_f = runner_f.run_single(ExperimentConfig(
|
||||
experiment_id="cand_f",
|
||||
name="Candidate F",
|
||||
description="Combined Best (Stage 3.1)",
|
||||
seed=42,
|
||||
duration_seconds=3600.0,
|
||||
output_dir="results/experiments/cand_f",
|
||||
orders_file="data/input/demo_orders.csv",
|
||||
preventive_traffic_coordination=True,
|
||||
custom_graph=graph_f,
|
||||
))
|
||||
kpi_f = res_f.kpi_report
|
||||
|
||||
print("\nCandidate Comparison Summary:")
|
||||
print(f"Cand A: Thru={kpi_a.throughput_tasks_per_hour:.1f} | Turnaround={kpi_a.turnaround_time.mean:.2f}s (p90={kpi_a.turnaround_time.p90:.2f}s) | Dist={kpi_a.total_travel_distance_meters:.2f}m | Energy={kpi_a.total_energy_consumed_kwh:.4f} kWh")
|
||||
print(f"Cand E: Thru={kpi_e.throughput_tasks_per_hour:.1f} | Turnaround={kpi_e.turnaround_time.mean:.2f}s (p90={kpi_e.turnaround_time.p90:.2f}s) | Dist={kpi_e.total_travel_distance_meters:.2f}m | Energy={kpi_e.total_energy_consumed_kwh:.4f} kWh")
|
||||
print(f"Cand F: Thru={kpi_f.throughput_tasks_per_hour:.1f} | Turnaround={kpi_f.turnaround_time.mean:.2f}s (p90={kpi_f.turnaround_time.p90:.2f}s) | Dist={kpi_f.total_travel_distance_meters:.2f}m | Energy={kpi_f.total_energy_consumed_kwh:.4f} kWh")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_all_six_candidates()
|
||||
Reference in New Issue
Block a user