Update warehouse digital twin and robot fleet optimization
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
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.routing.graph_builder import WarehouseGraphBuilder
|
||||
from warehouse_twin.routing.path_planner import PathPlanner
|
||||
|
||||
def build_candidate_a_graph(opt):
|
||||
"""Candidate A: Stage 3 baseline unchanged."""
|
||||
wh_cfg = opt.get_warehouse_config(LayoutVariant.HYBRID_OPTIMAL)
|
||||
model = WarehouseModel.from_dict(wh_cfg)
|
||||
builder = WarehouseGraphBuilder(model)
|
||||
graph = builder.build_topological_graph()
|
||||
opt._apply_directional_highways(graph)
|
||||
return model, graph, wh_cfg
|
||||
|
||||
def build_candidate_d_charging_config(opt):
|
||||
"""Candidate D: Optimized 3/3/2 charging bay distribution."""
|
||||
cfg = copy.deepcopy(opt.raw_config.get("warehouse", {}))
|
||||
cfg["charging_stations"] = [
|
||||
# Zone A (3 bays, 25kW)
|
||||
{"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"},
|
||||
# Zone B (3 bays, 50kW)
|
||||
{"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"},
|
||||
# Zone C (2 bays, 50kW)
|
||||
{"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"},
|
||||
]
|
||||
return cfg
|
||||
|
||||
def build_candidate_e_graph(opt, wh_cfg=None):
|
||||
"""Candidate E: Improved circulation highways and Zone A cross connectors."""
|
||||
if wh_cfg is None:
|
||||
wh_cfg = opt.get_warehouse_config(LayoutVariant.HYBRID_OPTIMAL)
|
||||
model = WarehouseModel.from_dict(wh_cfg)
|
||||
builder = WarehouseGraphBuilder(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",
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
return model, graph, wh_cfg
|
||||
|
||||
def run_experiment(opt, exp_id, name, desc, model, graph, wh_cfg, inv_cfg):
|
||||
runner = ExperimentRunner(opt.config_dir)
|
||||
runner.raw_config = dataclasses.replace(
|
||||
runner.raw_config,
|
||||
warehouse=wh_cfg,
|
||||
inventory=inv_cfg,
|
||||
)
|
||||
|
||||
config = ExperimentConfig(
|
||||
experiment_id=exp_id,
|
||||
name=name,
|
||||
description=desc,
|
||||
seed=42,
|
||||
duration_seconds=3600.0,
|
||||
output_dir=f"results/experiments/{exp_id}",
|
||||
orders_file="data/input/demo_orders.csv",
|
||||
preventive_traffic_coordination=True,
|
||||
custom_graph=graph,
|
||||
)
|
||||
|
||||
res = runner.run_single(config)
|
||||
return res.kpi_report
|
||||
|
||||
def main():
|
||||
opt = LayoutOptimizer()
|
||||
inv_cfg = opt.get_inventory_config(LayoutVariant.HYBRID_OPTIMAL)
|
||||
|
||||
print("Running Candidate A (Stage 3 Baseline)...")
|
||||
model_a, graph_a, wh_a = build_candidate_a_graph(opt)
|
||||
kpi_a = run_experiment(opt, "cand_a", "Candidate A", "Stage 3 Baseline", model_a, graph_a, wh_a, inv_cfg)
|
||||
|
||||
print("Running Candidate D (Optimized 3/3/2 Charging)...")
|
||||
wh_d = build_candidate_d_charging_config(opt)
|
||||
model_d = WarehouseModel.from_dict(wh_d)
|
||||
builder_d = WarehouseGraphBuilder(model_d)
|
||||
graph_d = builder_d.build_topological_graph()
|
||||
opt._apply_directional_highways(graph_d)
|
||||
kpi_d = run_experiment(opt, "cand_d", "Candidate D", "Optimized 3/3/2 Charging", model_d, graph_d, wh_d, inv_cfg)
|
||||
|
||||
print("Running Candidate E (Improved Traffic & Highways)...")
|
||||
model_e, graph_e, wh_e = build_candidate_e_graph(opt)
|
||||
kpi_e = run_experiment(opt, "cand_e", "Candidate E", "Improved Traffic & Highways", model_e, graph_e, wh_e, inv_cfg)
|
||||
|
||||
print("Running Candidate F (Combined Best - Stage 3.1)...")
|
||||
model_f, graph_f, wh_f = build_candidate_e_graph(opt, wh_d)
|
||||
kpi_f = run_experiment(opt, "cand_f", "Candidate F", "Combined Stage 3.1", model_f, graph_f, wh_f, inv_cfg)
|
||||
|
||||
candidates = [
|
||||
("Candidate A (Stage 3 Baseline)", kpi_a),
|
||||
("Candidate D (3/3/2 Charging)", kpi_d),
|
||||
("Candidate E (Circulation & Traffic)", kpi_e),
|
||||
("Candidate F (Combined Stage 3.1)", kpi_f),
|
||||
]
|
||||
|
||||
print("\n" + "="*105)
|
||||
print(f"{'Candidate':<35s} | {'Thru (t/h)':<10s} | {'Mean TT (s)':<11s} | {'p90 TT (s)':<10s} | {'Dist (m)':<10s} | {'Loaded %':<8s} | {'Energy (kWh)':<12s} | {'Wait (s)':<8s}")
|
||||
print("="*105)
|
||||
for name, kpi in candidates:
|
||||
print(f"{name:<35s} | {kpi.throughput_tasks_per_hour:<10.1f} | {kpi.turnaround_time.mean:<11.2f} | {kpi.turnaround_time.p90:<10.2f} | {kpi.total_travel_distance_meters:<10.2f} | {kpi.loaded_distance_ratio_percent:<8.1f} | {kpi.total_energy_consumed_kwh:<12.4f} | {kpi.total_yield_wait_time_seconds:<8.1f}")
|
||||
print("="*105)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user