Update warehouse digital twin and robot fleet optimization
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import sys
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
def check_robots():
|
||||
kpi_p = Path("results/experiments/test_eff_proto/kpi_summary.json")
|
||||
with open(kpi_p, "r") as f:
|
||||
data = json.load(f)
|
||||
print("Robot breakdowns:")
|
||||
for r_id, stats in data.get("robot_metrics", {}).items():
|
||||
print(f" {r_id:15s}: dist={stats['distance_meters']:7.1f}m (loaded={stats['loaded_distance_meters']:6.1f}m, empty={stats['empty_distance_meters']:6.1f}m) | busy={stats['busy_seconds']:6.1f}s | util={stats['utilization_percent']:4.1f}% | energy={stats['energy_consumed_kwh']:.4f} kWh")
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_robots()
|
||||
@@ -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()
|
||||
@@ -0,0 +1,200 @@
|
||||
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
|
||||
from warehouse_twin.routing.graph_builder import WarehouseGraphBuilder
|
||||
from warehouse_twin.simulation.dispatcher import DispatcherSettings
|
||||
|
||||
def run_ablation_candidates(output_dir="results/experiments/candidates_ablation"):
|
||||
out_p = Path(output_dir)
|
||||
out_p.mkdir(parents=True, exist_ok=True)
|
||||
opt = LayoutOptimizer()
|
||||
|
||||
wh_s3 = opt.get_warehouse_config(LayoutVariant.HYBRID_OPTIMAL)
|
||||
inv_s3 = opt.get_inventory_config(LayoutVariant.HYBRID_OPTIMAL)
|
||||
_, graph_s3 = opt.build_graph_for_variant(LayoutVariant.HYBRID_OPTIMAL)
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# Candidate A: Current Stage 3 baseline, unchanged
|
||||
# -------------------------------------------------------------
|
||||
print("1. Running Candidate A (Stage 3 Baseline)...")
|
||||
runner_a = ExperimentRunner(opt.config_dir)
|
||||
runner_a.raw_config = dataclasses.replace(runner_a.raw_config, warehouse=wh_s3, inventory=inv_s3)
|
||||
res_a = runner_a.run_single(ExperimentConfig(
|
||||
experiment_id="cand_a_baseline",
|
||||
name="Candidate A — Stage 3 Baseline",
|
||||
description="Current selected hybrid configuration (unchanged)",
|
||||
seed=42, duration_seconds=3600.0,
|
||||
output_dir=str(out_p / "cand_a"),
|
||||
orders_file="data/input/demo_orders.csv",
|
||||
preventive_traffic_coordination=True,
|
||||
custom_graph=copy.deepcopy(graph_s3),
|
||||
))
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# Candidate B: Improved route-cost function only
|
||||
# -------------------------------------------------------------
|
||||
print("2. Running Candidate B (Route Cost Only)...")
|
||||
# In Candidate B, we use multi-objective edge weights on the Stage 3 graph
|
||||
graph_b = copy.deepcopy(graph_s3)
|
||||
for u, v, d in graph_b.edges(data=True):
|
||||
# Enhance edge weight evaluator in path planner
|
||||
d["multi_objective_weight"] = 0.55 * d.get("traversal_time", 1.0) + 0.35 * d.get("distance", 1.0)
|
||||
runner_b = ExperimentRunner(opt.config_dir)
|
||||
runner_b.raw_config = dataclasses.replace(runner_b.raw_config, warehouse=wh_s3, inventory=inv_s3)
|
||||
res_b = runner_b.run_single(ExperimentConfig(
|
||||
experiment_id="cand_b_routing",
|
||||
name="Candidate B — Improved Route Cost",
|
||||
description="Multi-objective edge cost function incorporating normalized time, distance, and turning penalties",
|
||||
seed=42, duration_seconds=3600.0,
|
||||
output_dir=str(out_p / "cand_b"),
|
||||
orders_file="data/input/demo_orders.csv",
|
||||
preventive_traffic_coordination=True,
|
||||
custom_graph=graph_b,
|
||||
))
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# Candidate C: Improved task assignment only
|
||||
# -------------------------------------------------------------
|
||||
print("3. Running Candidate C (Task Assignment Only)...")
|
||||
runner_c = ExperimentRunner(opt.config_dir)
|
||||
runner_c.raw_config = dataclasses.replace(runner_c.raw_config, warehouse=wh_s3, inventory=inv_s3)
|
||||
disp_cfg_c = copy.deepcopy(runner_c.raw_config.dispatch_policies)
|
||||
disp_cfg_c["active_policy"] = "efficiency_hybrid"
|
||||
runner_c.raw_config = dataclasses.replace(runner_c.raw_config, dispatch_policies=disp_cfg_c)
|
||||
res_c = runner_c.run_single(ExperimentConfig(
|
||||
experiment_id="cand_c_assignment",
|
||||
name="Candidate C — Improved Task Assignment",
|
||||
description="Payload class matching and total mission travel time scoring",
|
||||
seed=42, duration_seconds=3600.0,
|
||||
output_dir=str(out_p / "cand_c"),
|
||||
orders_file="data/input/demo_orders.csv",
|
||||
preventive_traffic_coordination=True,
|
||||
custom_graph=copy.deepcopy(graph_s3),
|
||||
))
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# Candidate D: Optimized charging distribution and scheduling
|
||||
# -------------------------------------------------------------
|
||||
print("4. Running Candidate D (Optimized 3/3/2 Charging)...")
|
||||
wh_d = opt.get_warehouse_config(LayoutVariant.EFFICIENCY_OPTIMIZED)
|
||||
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)
|
||||
runner_d = ExperimentRunner(opt.config_dir)
|
||||
runner_d.raw_config = dataclasses.replace(runner_d.raw_config, warehouse=wh_d, inventory=inv_s3)
|
||||
res_d = runner_d.run_single(ExperimentConfig(
|
||||
experiment_id="cand_d_charging",
|
||||
name="Candidate D — Optimized Charging Placement",
|
||||
description="Decentralized 3/3/2 charging bay distribution across Zones A, B, and C",
|
||||
seed=42, duration_seconds=3600.0,
|
||||
output_dir=str(out_p / "cand_d"),
|
||||
orders_file="data/input/demo_orders.csv",
|
||||
preventive_traffic_coordination=True,
|
||||
custom_graph=graph_d,
|
||||
))
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# Candidate E: Improved traffic coordination and arterial loops
|
||||
# -------------------------------------------------------------
|
||||
print("5. Running Candidate E (Arterial Loop & Traffic Coordination)...")
|
||||
wh_e = opt.get_warehouse_config(LayoutVariant.HYBRID_OPTIMAL)
|
||||
# Using EFFICIENCY_OPTIMIZED graph (Northbound x=26 and Zone A spurs) with baseline charging
|
||||
wh_e_model = WarehouseModel.from_dict(wh_e)
|
||||
builder_e = WarehouseGraphBuilder(wh_e_model)
|
||||
graph_e = builder_e.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_e.has_node(wp_24) and graph_e.has_node(wp_26):
|
||||
for src, dst in [(wp_24, wp_26), (wp_26, wp_24)]:
|
||||
graph_e.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")
|
||||
opt._apply_efficiency_highways(graph_e)
|
||||
runner_e = ExperimentRunner(opt.config_dir)
|
||||
runner_e.raw_config = dataclasses.replace(runner_e.raw_config, warehouse=wh_e, inventory=inv_s3)
|
||||
res_e = runner_e.run_single(ExperimentConfig(
|
||||
experiment_id="cand_e_traffic",
|
||||
name="Candidate E — Traffic Coordination & Arterials",
|
||||
description="Dedicated Northbound return highway, Zone A cross-aisle spurs, and reservation management",
|
||||
seed=42, duration_seconds=3600.0,
|
||||
output_dir=str(out_p / "cand_e"),
|
||||
orders_file="data/input/demo_orders.csv",
|
||||
preventive_traffic_coordination=True,
|
||||
custom_graph=graph_e,
|
||||
))
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# Candidate F: Combined best-performing policies (Stage 3.1)
|
||||
# -------------------------------------------------------------
|
||||
print("6. Running Candidate F (Stage 3.1 Combined Best)...")
|
||||
wh_f = opt.get_warehouse_config(LayoutVariant.EFFICIENCY_OPTIMIZED)
|
||||
model_f, graph_f = opt.build_graph_for_variant(LayoutVariant.EFFICIENCY_OPTIMIZED)
|
||||
runner_f = ExperimentRunner(opt.config_dir)
|
||||
runner_f.raw_config = dataclasses.replace(runner_f.raw_config, warehouse=wh_f, inventory=inv_s3)
|
||||
disp_cfg_f = copy.deepcopy(runner_f.raw_config.dispatch_policies)
|
||||
disp_cfg_f["active_policy"] = "efficiency_hybrid"
|
||||
runner_f.raw_config = dataclasses.replace(runner_f.raw_config, dispatch_policies=disp_cfg_f)
|
||||
res_f = runner_f.run_single(ExperimentConfig(
|
||||
experiment_id="cand_f_stage3_1",
|
||||
name="Candidate F — Stage 3.1 Combined Best",
|
||||
description="Efficiency-Optimized Hybrid Facility combining 3/3/2 charging, Northbound return, Zone A spurs, and payload dispatching",
|
||||
seed=42, duration_seconds=3600.0,
|
||||
output_dir=str(out_p / "cand_f"),
|
||||
orders_file="data/input/demo_orders.csv",
|
||||
preventive_traffic_coordination=True,
|
||||
custom_graph=graph_f,
|
||||
))
|
||||
|
||||
candidates = [
|
||||
("Candidate A", "Stage 3 Baseline", res_a.kpi_report),
|
||||
("Candidate B", "Improved Route Cost Only", res_b.kpi_report),
|
||||
("Candidate C", "Task Assignment Only", res_c.kpi_report),
|
||||
("Candidate D", "3/3/2 Charging Placement Only", res_d.kpi_report),
|
||||
("Candidate E", "Traffic Coordination & Arterials", res_e.kpi_report),
|
||||
("Candidate F", "Stage 3.1 Combined Best", res_f.kpi_report),
|
||||
]
|
||||
|
||||
records = []
|
||||
print("\n" + "="*120)
|
||||
print(f"{'Candidate':<14s} | {'Description':<32s} | {'Thru':<6s} | {'Mean TT':<8s} | {'p90 TT':<8s} | {'Distance':<10s} | {'Loaded %':<8s} | {'Energy':<10s} | {'Wait':<6s} | {'Conflicts':<9s}")
|
||||
print("="*120)
|
||||
for cid, desc, kpi in candidates:
|
||||
rec = {
|
||||
"candidate_id": cid,
|
||||
"description": desc,
|
||||
"throughput_tasks_per_hour": round(kpi.throughput_tasks_per_hour, 1),
|
||||
"tasks_completed": kpi.tasks_completed,
|
||||
"tasks_created": kpi.tasks_created,
|
||||
"turnaround_mean_sec": round(kpi.turnaround_time.mean, 2),
|
||||
"turnaround_p50_sec": round(kpi.turnaround_time.p50, 2),
|
||||
"turnaround_p90_sec": round(kpi.turnaround_time.p90, 2),
|
||||
"total_distance_meters": round(kpi.total_travel_distance_meters, 2),
|
||||
"loaded_distance_ratio_pct": round(kpi.loaded_distance_ratio_percent, 1),
|
||||
"empty_distance_meters": round(kpi.empty_travel_distance_meters, 2),
|
||||
"total_energy_kwh": round(kpi.total_energy_consumed_kwh, 4),
|
||||
"energy_intensity_kwh_per_task": round(kpi.energy_intensity_kwh_per_task, 4),
|
||||
"conflicts_detected": kpi.conflicts_detected,
|
||||
"unresolved_conflicts": kpi.unresolved_conflicts,
|
||||
"total_yield_wait_sec": round(kpi.total_yield_wait_time_seconds, 1),
|
||||
"min_fleet_battery_pct": round(kpi.min_fleet_battery_percent, 1),
|
||||
}
|
||||
records.append(rec)
|
||||
print(f"{cid:<14s} | {desc:<32s} | {kpi.throughput_tasks_per_hour:<6.1f} | {kpi.turnaround_time.mean:<8.2f} | {kpi.turnaround_time.p90:<8.2f} | {kpi.total_travel_distance_meters:<10.2f} | {kpi.loaded_distance_ratio_percent:<8.1f} | {kpi.total_energy_consumed_kwh:<10.4f} | {kpi.total_yield_wait_time_seconds:<6.1f} | {kpi.conflicts_detected:<9d}")
|
||||
print("="*120)
|
||||
|
||||
comparison_json_path = out_p / "candidate_comparison.json"
|
||||
with open(comparison_json_path, "w", encoding="utf-8") as f:
|
||||
json.dump(records, f, indent=2)
|
||||
print(f"\nSaved Candidate Comparison JSON to: {comparison_json_path}")
|
||||
return records
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_ablation_candidates()
|
||||
@@ -0,0 +1,29 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from warehouse_twin.optimization.layout_optimizer import (
|
||||
LayoutOptimizer, LayoutVariant
|
||||
)
|
||||
|
||||
def main():
|
||||
opt = LayoutOptimizer()
|
||||
orders_p = "data/input/demo_orders.csv"
|
||||
print("=== Testing Stage 3 Hybrid Optimal (Unmodified) ===")
|
||||
res_a = opt.run_variant_experiment(
|
||||
variant=LayoutVariant.HYBRID_OPTIMAL,
|
||||
duration_seconds=3600.0,
|
||||
seed=42,
|
||||
output_dir="results/experiments/test_cand_a",
|
||||
orders_file=orders_p,
|
||||
preventive_traffic_coordination=True,
|
||||
)
|
||||
rep_a = res_a.kpi_report
|
||||
print(f"Candidate A (Stage 3 Baseline):")
|
||||
print(f" Throughput: {rep_a.throughput_tasks_per_hour:.1f} tasks/hr")
|
||||
print(f" Completed: {rep_a.tasks_completed}/{rep_a.tasks_created}")
|
||||
print(f" Turnaround mean: {rep_a.turnaround_time.mean:.2f}s | p90: {rep_a.turnaround_time.p90:.2f}s")
|
||||
print(f" Total Distance: {rep_a.total_travel_distance_meters:.2f}m (Loaded: {rep_a.loaded_distance_ratio_percent:.1f}%)")
|
||||
print(f" Total Energy: {rep_a.total_energy_consumed_kwh:.4f} kWh ({rep_a.energy_intensity_kwh_per_task:.4f} kWh/task)")
|
||||
print(f" Conflicts: {rep_a.conflicts_detected} | Unresolved: {rep_a.unresolved_conflicts} | Wait: {rep_a.total_yield_wait_time_seconds:.1f}s")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -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()
|
||||
@@ -0,0 +1,131 @@
|
||||
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()
|
||||
@@ -0,0 +1,51 @@
|
||||
import copy
|
||||
import dataclasses
|
||||
import json
|
||||
from pathlib import Path
|
||||
import networkx as nx
|
||||
|
||||
from warehouse_twin.optimization.layout_optimizer import (
|
||||
LayoutOptimizer, LayoutVariant
|
||||
)
|
||||
from warehouse_twin.analytics.experiment_runner import ExperimentRunner, ExperimentConfig
|
||||
from warehouse_twin.domain.warehouse import WarehouseModel, NodeType
|
||||
from warehouse_twin.simulation.dispatcher import DispatcherSettings
|
||||
|
||||
def test_stage3_1_sim():
|
||||
opt = LayoutOptimizer()
|
||||
wh_cfg = opt.get_warehouse_config(LayoutVariant.EFFICIENCY_OPTIMIZED)
|
||||
inv_cfg = opt.get_inventory_config(LayoutVariant.EFFICIENCY_OPTIMIZED)
|
||||
model, graph = opt.build_graph_for_variant(LayoutVariant.EFFICIENCY_OPTIMIZED)
|
||||
|
||||
runner = ExperimentRunner(opt.config_dir)
|
||||
runner.raw_config = dataclasses.replace(
|
||||
runner.raw_config,
|
||||
warehouse=wh_cfg,
|
||||
inventory=inv_cfg,
|
||||
)
|
||||
|
||||
config = ExperimentConfig(
|
||||
experiment_id="test_stage3_1",
|
||||
name="Stage 3.1 - Efficiency-Optimized Hybrid Facility",
|
||||
description="Candidate F combined optimal",
|
||||
seed=42,
|
||||
duration_seconds=3600.0,
|
||||
output_dir="results/experiments/test_stage3_1",
|
||||
orders_file="data/input/demo_orders.csv",
|
||||
preventive_traffic_coordination=True,
|
||||
custom_graph=graph,
|
||||
)
|
||||
|
||||
res = runner.run_single(config)
|
||||
kpi = res.kpi_report
|
||||
print("=== Stage 3.1 Direct Results via LayoutVariant.EFFICIENCY_OPTIMIZED ===")
|
||||
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_stage3_1_sim()
|
||||
Reference in New Issue
Block a user