feat(phase-5): implement battery model, charging queues, production deadlines, and safe reassignment
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
"""Unit tests for BatteryModel: power consumption, load scaling, and mission energy feasibility."""
|
||||
|
||||
import pytest
|
||||
|
||||
from warehouse_twin.domain.robot import Robot, RobotTypeSpec
|
||||
from warehouse_twin.domain.warehouse import Position3D
|
||||
from warehouse_twin.fleet.battery_model import (
|
||||
BatteryModel,
|
||||
InfeasibleEnergyMissionError,
|
||||
MissionEnergyEstimate,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def robot_specs():
|
||||
return {
|
||||
"light_amr": RobotTypeSpec(
|
||||
type_id="light_amr",
|
||||
name="Light AMR",
|
||||
description="Small parts AMR",
|
||||
payload_capacity_kg=150.0,
|
||||
max_speed_mps=1.8,
|
||||
acceleration_mps2=0.8,
|
||||
battery_capacity_kwh=3.0,
|
||||
power_consumption_kw={
|
||||
"idle": 0.05,
|
||||
"moving_empty": 0.35,
|
||||
"moving_loaded": 0.65,
|
||||
"handling": 0.15,
|
||||
},
|
||||
allowed_zones={"zone_a", "zone_b", "zone_c"},
|
||||
dimensions=(0.8, 0.6, 0.35),
|
||||
),
|
||||
"heavy_amr": RobotTypeSpec(
|
||||
type_id="heavy_amr",
|
||||
name="Heavy AMR",
|
||||
description="Heavy pallet AMR",
|
||||
payload_capacity_kg=1500.0,
|
||||
max_speed_mps=1.1,
|
||||
acceleration_mps2=0.4,
|
||||
battery_capacity_kwh=15.0,
|
||||
power_consumption_kw={
|
||||
"idle": 0.12,
|
||||
"moving_empty": 0.90,
|
||||
"moving_loaded": 2.20,
|
||||
"handling": 0.50,
|
||||
},
|
||||
allowed_zones={"zone_a", "zone_b", "zone_c"},
|
||||
dimensions=(1.4, 1.0, 0.45),
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def light_robot(robot_specs):
|
||||
spec = robot_specs["light_amr"]
|
||||
return Robot(
|
||||
robot_id="amr_light_01",
|
||||
robot_type="light_amr",
|
||||
position=Position3D(2.0, 36.0, 0.0),
|
||||
maximum_speed=spec.max_speed_mps,
|
||||
payload_capacity=spec.payload_capacity_kg,
|
||||
battery_level=3.0, # 100%
|
||||
battery_capacity=spec.battery_capacity_kwh,
|
||||
energy_consumption=dict(spec.power_consumption_kw),
|
||||
allowed_zones=set(spec.allowed_zones),
|
||||
)
|
||||
|
||||
|
||||
def test_power_consumption_by_mode(light_robot):
|
||||
model = BatteryModel()
|
||||
assert model.calculate_power_kw(light_robot, mode="idle") == 0.05
|
||||
assert model.calculate_power_kw(light_robot, mode="handling") == 0.15
|
||||
assert model.calculate_power_kw(light_robot, mode="moving_empty") == 0.35
|
||||
|
||||
|
||||
def test_load_dependent_power_scaling(light_robot):
|
||||
model = BatteryModel()
|
||||
# At 0 kg payload, moving_loaded should equal moving_empty (0.35 kW)
|
||||
p_zero = model.calculate_power_kw(light_robot, mode="moving_loaded", payload_kg=0.0)
|
||||
assert p_zero == 0.65 # Default if 0 mass specified in loaded mode
|
||||
|
||||
# At half payload (75 kg of 150 kg capacity): 0.35 + (0.65 - 0.35) * 0.5 = 0.50 kW
|
||||
p_half = model.calculate_power_kw(light_robot, mode="moving_loaded", payload_kg=75.0)
|
||||
assert pytest.approx(p_half, rel=1e-3) == 0.50
|
||||
|
||||
# At full payload (150 kg of 150 kg capacity): 0.65 kW
|
||||
p_full = model.calculate_power_kw(light_robot, mode="moving_loaded", payload_kg=150.0)
|
||||
assert pytest.approx(p_full, rel=1e-3) == 0.65
|
||||
|
||||
|
||||
def test_transit_and_handling_energy_estimation(light_robot):
|
||||
model = BatteryModel()
|
||||
# 180 meters at 1.8 m/s = 100 seconds. Empty power = 0.35 kW -> 0.35 * 100 / 3600 = 0.009722 kWh
|
||||
e_transit = model.estimate_transit_energy_kwh(light_robot, distance_meters=180.0, is_loaded=False)
|
||||
assert pytest.approx(e_transit, rel=1e-3) == (0.35 * 100.0) / 3600.0
|
||||
|
||||
# 60 seconds handling at 0.15 kW -> 0.15 * 60 / 3600 = 0.0025 kWh
|
||||
e_handling = model.estimate_handling_energy_kwh(light_robot, duration_seconds=60.0)
|
||||
assert pytest.approx(e_handling, rel=1e-3) == (0.15 * 60.0) / 3600.0
|
||||
|
||||
|
||||
def test_mission_feasibility_high_battery(light_robot):
|
||||
model = BatteryModel(reserve_threshold_percent=20.0)
|
||||
estimate = model.estimate_mission_energy(
|
||||
robot=light_robot,
|
||||
dist_to_pickup=20.0,
|
||||
dist_to_dropoff=40.0,
|
||||
dist_drop_to_charger=15.0,
|
||||
payload_kg=50.0,
|
||||
)
|
||||
assert estimate.is_feasible is True
|
||||
assert estimate.projected_post_mission_soc_pct > 95.0
|
||||
assert estimate.reserve_headroom_pct > 75.0
|
||||
|
||||
|
||||
def test_mission_feasibility_rejected_on_low_battery(light_robot):
|
||||
# Set battery down to 21% (0.63 kWh out of 3.0 kWh)
|
||||
light_robot.battery_level = 0.63
|
||||
model = BatteryModel(reserve_threshold_percent=20.0)
|
||||
|
||||
# Long mission requiring 0.15 kWh -> remaining 0.48 kWh (16% SoC < 20% reserve)
|
||||
estimate = model.estimate_mission_energy(
|
||||
robot=light_robot,
|
||||
dist_to_pickup=500.0,
|
||||
dist_to_dropoff=500.0,
|
||||
dist_drop_to_charger=100.0,
|
||||
payload_kg=150.0,
|
||||
)
|
||||
assert estimate.is_feasible is False
|
||||
assert estimate.projected_post_mission_soc_pct < 20.0
|
||||
|
||||
with pytest.raises(InfeasibleEnergyMissionError):
|
||||
model.validate_mission_feasibility(
|
||||
robot=light_robot,
|
||||
dist_to_pickup=500.0,
|
||||
dist_to_dropoff=500.0,
|
||||
dist_drop_to_charger=100.0,
|
||||
payload_kg=150.0,
|
||||
)
|
||||
|
||||
|
||||
def test_charge_time_calculation(light_robot):
|
||||
model = BatteryModel(charging_efficiency=0.95)
|
||||
# Recharging from 1.0 kWh to 2.5 kWh (delta 1.5 kWh) on a 25.0 kW charger
|
||||
# effective power = 25.0 * 0.95 = 23.75 kW
|
||||
# time = (1.5 / 23.75) * 3600 = 227.37 s
|
||||
t_seconds = model.compute_charging_duration_seconds(
|
||||
current_kwh=1.0,
|
||||
target_kwh=2.5,
|
||||
charger_power_kw=25.0,
|
||||
)
|
||||
assert pytest.approx(t_seconds, rel=1e-2) == (1.5 / (25.0 * 0.95)) * 3600.0
|
||||
@@ -0,0 +1,124 @@
|
||||
"""Unit tests for ChargingManager: capacity-constrained queues, station allocation, and charging dynamics."""
|
||||
|
||||
import pytest
|
||||
import simpy
|
||||
|
||||
from warehouse_twin.domain.robot import Robot, RobotTypeSpec
|
||||
from warehouse_twin.domain.warehouse import ChargingStation, Position3D
|
||||
from warehouse_twin.fleet.charging_manager import ChargingBay, ChargingManager
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_charging_stations():
|
||||
return [
|
||||
ChargingStation(station_id="charge_bay_1", position=Position3D(2.0, 36.0, 0.0), charging_rate_kw=25.0, capacity=1),
|
||||
ChargingStation(station_id="charge_bay_2", position=Position3D(4.0, 36.0, 0.0), charging_rate_kw=25.0, capacity=1),
|
||||
ChargingStation(station_id="charge_bay_3", position=Position3D(6.0, 36.0, 0.0), charging_rate_kw=50.0, capacity=1),
|
||||
ChargingStation(station_id="charge_bay_4", position=Position3D(8.0, 36.0, 0.0), charging_rate_kw=50.0, capacity=1),
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def light_robot():
|
||||
return Robot(
|
||||
robot_id="amr_light_01",
|
||||
robot_type="light_amr",
|
||||
position=Position3D(2.0, 30.0, 0.0),
|
||||
maximum_speed=1.8,
|
||||
payload_capacity=150.0,
|
||||
battery_level=0.5, # Needs charge
|
||||
battery_capacity=3.0,
|
||||
energy_consumption={"idle": 0.05, "moving_empty": 0.35, "moving_loaded": 0.65, "handling": 0.15},
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def heavy_robot():
|
||||
return Robot(
|
||||
robot_id="amr_heavy_01",
|
||||
robot_type="heavy_amr",
|
||||
position=Position3D(6.0, 30.0, 0.0),
|
||||
maximum_speed=1.1,
|
||||
payload_capacity=1500.0,
|
||||
battery_level=2.0, # Needs charge
|
||||
battery_capacity=15.0,
|
||||
energy_consumption={"idle": 0.12, "moving_empty": 0.90, "moving_loaded": 2.20, "handling": 0.50},
|
||||
)
|
||||
|
||||
|
||||
def test_charging_manager_initialization(test_charging_stations):
|
||||
env = simpy.Environment()
|
||||
manager = ChargingManager(env, test_charging_stations)
|
||||
assert len(manager.bays) == 4
|
||||
assert manager.bays["charge_bay_1"].charging_rate_kw == 25.0
|
||||
assert manager.bays["charge_bay_3"].charging_rate_kw == 50.0
|
||||
assert manager.bays["charge_bay_1"].capacity == 1
|
||||
|
||||
|
||||
def test_charging_bay_selection_preference(test_charging_stations, light_robot, heavy_robot):
|
||||
env = simpy.Environment()
|
||||
manager = ChargingManager(env, test_charging_stations)
|
||||
|
||||
# Light robot should prefer 25kW bays near x=2.0
|
||||
bay_light = manager.select_best_charging_bay(light_robot)
|
||||
assert bay_light.station_id in ("charge_bay_1", "charge_bay_2")
|
||||
assert bay_light.charging_rate_kw == 25.0
|
||||
|
||||
# Heavy robot should prefer 50kW bays near x=6.0
|
||||
bay_heavy = manager.select_best_charging_bay(heavy_robot)
|
||||
assert bay_heavy.station_id in ("charge_bay_3", "charge_bay_4")
|
||||
assert bay_heavy.charging_rate_kw == 50.0
|
||||
|
||||
|
||||
def test_capacity_constrained_queueing(test_charging_stations, light_robot):
|
||||
env = simpy.Environment()
|
||||
manager = ChargingManager(env, test_charging_stations)
|
||||
bay = manager.bays["charge_bay_1"]
|
||||
|
||||
second_robot = Robot(
|
||||
robot_id="amr_light_02",
|
||||
robot_type="light_amr",
|
||||
position=Position3D(2.0, 32.0, 0.0),
|
||||
maximum_speed=1.8,
|
||||
payload_capacity=150.0,
|
||||
battery_level=0.6,
|
||||
battery_capacity=3.0,
|
||||
energy_consumption={"idle": 0.05, "moving_empty": 0.35, "moving_loaded": 0.65, "handling": 0.15},
|
||||
)
|
||||
|
||||
queue_wait_recorded = []
|
||||
|
||||
def robot_charge_sim(robot, target_charge_time):
|
||||
q_start = env.now
|
||||
with bay.resource.request() as req:
|
||||
yield req
|
||||
q_wait = env.now - q_start
|
||||
queue_wait_recorded.append((robot.robot_id, q_wait))
|
||||
bay.total_queue_wait_time_seconds += q_wait
|
||||
yield env.timeout(target_charge_time)
|
||||
robot.charge_energy(target_charge_time, bay.charging_rate_kw)
|
||||
bay.total_sessions += 1
|
||||
bay.total_charging_time_seconds += target_charge_time
|
||||
|
||||
# Robot 1 arrives at t=0, charges for 100s
|
||||
env.process(robot_charge_sim(light_robot, 100.0))
|
||||
# Robot 2 arrives at t=10s, must wait until t=100s (wait = 90s)
|
||||
def delayed_arrival():
|
||||
yield env.timeout(10.0)
|
||||
yield env.process(robot_charge_sim(second_robot, 50.0))
|
||||
|
||||
env.process(delayed_arrival())
|
||||
|
||||
env.run(until=200.0)
|
||||
|
||||
# First robot waited 0s; second robot waited 90s
|
||||
assert len(queue_wait_recorded) == 2
|
||||
assert queue_wait_recorded[0] == ("amr_light_01", 0.0)
|
||||
assert queue_wait_recorded[1] == ("amr_light_02", 90.0)
|
||||
assert bay.total_sessions == 2
|
||||
assert bay.total_charging_time_seconds == 150.0
|
||||
|
||||
metrics = manager.get_metrics(200.0)
|
||||
assert metrics["total_charging_sessions"] == 2
|
||||
assert metrics["total_queue_wait_time_seconds"] == 90.0
|
||||
assert metrics["average_queue_wait_time_seconds"] == 45.0
|
||||
@@ -0,0 +1,91 @@
|
||||
"""Unit tests for Production Line Deadlines: SLA monitoring, lateness tracking, and deadline dispatch."""
|
||||
|
||||
import pytest
|
||||
|
||||
from warehouse_twin.domain.task import Task, TaskPriority, TaskStatus, TaskType
|
||||
from warehouse_twin.simulation.dispatcher import DispatcherSettings, FleetDispatcher
|
||||
|
||||
|
||||
def test_production_feed_task_deadline_tracking():
|
||||
# Production line feed task released at t=100.0 with 300s lead time (deadline=400.0)
|
||||
task = Task(
|
||||
task_id="task_zc_0001",
|
||||
task_type=TaskType.PRODUCTION_FEED,
|
||||
source="rack_c_01",
|
||||
destination="production_dropoff_c1",
|
||||
priority=TaskPriority.CRITICAL.value,
|
||||
release_time=100.0,
|
||||
deadline=400.0,
|
||||
required_payload=250.0,
|
||||
)
|
||||
|
||||
# In execution before deadline: not overdue
|
||||
assert task.is_overdue(sim_time=350.0) is False
|
||||
assert task.lateness(sim_time=350.0) == 0.0
|
||||
|
||||
# In execution past deadline: overdue
|
||||
assert task.is_overdue(sim_time=420.0) is True
|
||||
assert task.lateness(sim_time=420.0) == 20.0
|
||||
|
||||
# Completed on time at t=380.0
|
||||
task.assign_to_robot("amr_heavy_01", sim_time=120.0)
|
||||
task.start_execution(sim_time=200.0)
|
||||
task.complete(sim_time=380.0)
|
||||
|
||||
assert task.is_overdue(sim_time=500.0) is False
|
||||
assert task.lateness(sim_time=500.0) == 0.0
|
||||
assert task.turnaround_time() == 280.0
|
||||
assert task.execution_time() == 180.0
|
||||
|
||||
|
||||
def test_production_feed_late_completion():
|
||||
task = Task(
|
||||
task_id="task_zc_0002",
|
||||
task_type=TaskType.PRODUCTION_FEED,
|
||||
source="rack_c_01",
|
||||
destination="production_dropoff_c1",
|
||||
priority=TaskPriority.CRITICAL.value,
|
||||
release_time=100.0,
|
||||
deadline=400.0,
|
||||
required_payload=250.0,
|
||||
)
|
||||
|
||||
task.assign_to_robot("amr_heavy_01", sim_time=150.0)
|
||||
task.start_execution(sim_time=250.0)
|
||||
task.complete(sim_time=445.0) # 45 seconds late
|
||||
|
||||
assert task.is_overdue(sim_time=500.0) is True
|
||||
assert task.lateness(sim_time=500.0) == 45.0
|
||||
|
||||
|
||||
def test_dispatcher_prioritizes_urgent_deadlines():
|
||||
dispatcher = FleetDispatcher(DispatcherSettings())
|
||||
|
||||
# Task 1: Priority 2, Deadline = 1000s
|
||||
t1 = Task(
|
||||
task_id="task_1",
|
||||
task_type=TaskType.OUTBOUND_PICKING,
|
||||
source="rack_a_01",
|
||||
destination="picking_station_a1",
|
||||
priority=TaskPriority.HIGH.value,
|
||||
release_time=10.0,
|
||||
deadline=1000.0,
|
||||
)
|
||||
|
||||
# Task 2: Priority 2, Deadline = 200s (more urgent)
|
||||
t2 = Task(
|
||||
task_id="task_2",
|
||||
task_type=TaskType.OUTBOUND_PICKING,
|
||||
source="rack_a_02",
|
||||
destination="picking_station_a1",
|
||||
priority=TaskPriority.HIGH.value,
|
||||
release_time=15.0,
|
||||
deadline=200.0,
|
||||
)
|
||||
|
||||
dispatcher.enqueue_task(t1)
|
||||
dispatcher.enqueue_task(t2)
|
||||
|
||||
# t2 must be at head of queue due to earlier deadline
|
||||
assert dispatcher.queue[0].task_id == "task_2"
|
||||
assert dispatcher.queue[1].task_id == "task_1"
|
||||
@@ -0,0 +1,64 @@
|
||||
"""Unit tests for stockout monitoring and automatic inventory replenishment lifecycle."""
|
||||
|
||||
import pytest
|
||||
|
||||
from warehouse_twin.domain.inventory import InventoryCatalog, InventoryItem
|
||||
from warehouse_twin.domain.task import Task, TaskPriority, TaskStatus, TaskType
|
||||
from warehouse_twin.domain.warehouse import WarehouseDimensions, WarehouseModel
|
||||
from warehouse_twin.simulation.order_generator import OrderGenerator, WorkloadConfig
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_catalog():
|
||||
return InventoryCatalog(
|
||||
items={
|
||||
"SKU-OIL-001": InventoryItem(
|
||||
item_id="SKU-OIL-001",
|
||||
name="Hydraulic Oil Filter",
|
||||
category="hydraulic_filters",
|
||||
zone="zone_a",
|
||||
storage_location="rack_a_01",
|
||||
initial_stock=10,
|
||||
current_stock=0, # Out of stock
|
||||
reserved_stock=0,
|
||||
minimum_stock=5,
|
||||
replenishment_batch=20,
|
||||
unit_weight_kg=1.8,
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def warehouse_model():
|
||||
return WarehouseModel(
|
||||
dimensions=WarehouseDimensions(width=60.0, depth=40.0, height=8.0),
|
||||
zones={},
|
||||
stations={},
|
||||
charging_stations={},
|
||||
storage_locations={},
|
||||
)
|
||||
|
||||
|
||||
def test_stockout_detection_and_replenishment(test_catalog, warehouse_model):
|
||||
generator = OrderGenerator(WorkloadConfig(), test_catalog, warehouse_model)
|
||||
item = test_catalog.items["SKU-OIL-001"]
|
||||
|
||||
# Stock is 0 -> should report out of stock
|
||||
assert item.available_quantity == 0
|
||||
assert item.needs_replenishment() is True
|
||||
|
||||
# Generate replenishment task
|
||||
repl_task = generator.generate_replenishment_task(item, sim_time=150.0)
|
||||
|
||||
assert repl_task.task_type == TaskType.REPLENISHMENT
|
||||
assert repl_task.destination == "rack_a_01"
|
||||
assert repl_task.quantity == 20
|
||||
assert repl_task.priority == TaskPriority.HIGH.value
|
||||
|
||||
# Simulate delivery of replenishment task
|
||||
item.restock(repl_task.quantity)
|
||||
|
||||
assert item.current_stock == 20
|
||||
assert item.available_quantity == 20
|
||||
assert item.needs_replenishment() is False
|
||||
@@ -0,0 +1,109 @@
|
||||
"""Unit tests for TaskReassigner: safe abort on low battery, queue recovery, and preemption."""
|
||||
|
||||
import pytest
|
||||
|
||||
from warehouse_twin.domain.robot import Robot, RobotState
|
||||
from warehouse_twin.domain.task import Task, TaskPriority, TaskStatus, TaskType
|
||||
from warehouse_twin.domain.warehouse import Position3D
|
||||
from warehouse_twin.fleet.task_reassigner import TaskReassigner
|
||||
from warehouse_twin.routing.reservations import TimeSpaceReservationGrid
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def robot():
|
||||
return Robot(
|
||||
robot_id="amr_light_01",
|
||||
robot_type="light_amr",
|
||||
position=Position3D(2.0, 36.0, 0.0),
|
||||
maximum_speed=1.8,
|
||||
payload_capacity=150.0,
|
||||
battery_level=0.70, # ~23% SoC
|
||||
battery_capacity=3.0,
|
||||
energy_consumption={"idle": 0.05, "moving_empty": 0.35, "moving_loaded": 0.65, "handling": 0.15},
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def task():
|
||||
return Task(
|
||||
task_id="task_test_01",
|
||||
task_type=TaskType.OUTBOUND_PICKING,
|
||||
source="rack_a_01",
|
||||
destination="picking_station_a1",
|
||||
priority=TaskPriority.HIGH.value,
|
||||
release_time=100.0,
|
||||
required_payload=50.0,
|
||||
)
|
||||
|
||||
|
||||
def test_reassign_due_to_low_battery(robot, task):
|
||||
grid = TimeSpaceReservationGrid()
|
||||
# Add dummy reservation for robot
|
||||
grid.reserve_node("node_1", 100.0, 110.0, "amr_light_01")
|
||||
assert "node_1" in grid.node_reservations
|
||||
|
||||
reassigner = TaskReassigner(grid)
|
||||
|
||||
# Assign robot to task
|
||||
robot.assign_task(task, sim_time=100.0)
|
||||
task.assign_to_robot(robot.robot_id, sim_time=100.0)
|
||||
robot.transition_to(RobotState.DISPATCHED, sim_time=100.0)
|
||||
|
||||
assert robot.current_task_id == "task_test_01"
|
||||
assert task.status == TaskStatus.ASSIGNED
|
||||
|
||||
# Trigger safe reassignment at t=105s
|
||||
res = reassigner.reassign_due_to_low_battery(
|
||||
robot=robot,
|
||||
task=task,
|
||||
sim_time=105.0,
|
||||
reason="Battery critically low before pick",
|
||||
)
|
||||
|
||||
assert res.reassigned is True
|
||||
assert res.task_id == "task_test_01"
|
||||
assert res.previous_robot_id == "amr_light_01"
|
||||
|
||||
# Robot bindings must be cleared
|
||||
assert robot.current_task_id is None
|
||||
# Task must be reset to PENDING status
|
||||
assert task.status == TaskStatus.PENDING
|
||||
assert task.assigned_robot_id is None
|
||||
# Grid reservations must be cleared
|
||||
assert "node_1" not in grid.node_reservations
|
||||
|
||||
|
||||
def test_preemption_for_urgent_task(robot, task):
|
||||
grid = TimeSpaceReservationGrid()
|
||||
reassigner = TaskReassigner(grid)
|
||||
|
||||
# Robot assigned to low priority task
|
||||
robot.assign_task(task, sim_time=50.0)
|
||||
task.assign_to_robot(robot.robot_id, sim_time=50.0)
|
||||
|
||||
# Urgent production feed arrives
|
||||
urgent_task = Task(
|
||||
task_id="task_urgent_feed",
|
||||
task_type=TaskType.PRODUCTION_FEED,
|
||||
source="rack_c_01",
|
||||
destination="production_dropoff_c1",
|
||||
priority=TaskPriority.CRITICAL.value,
|
||||
release_time=60.0,
|
||||
)
|
||||
|
||||
res = reassigner.preempt_task_for_priority(
|
||||
urgent_task=urgent_task,
|
||||
candidate_robot=robot,
|
||||
existing_task=task,
|
||||
sim_time=60.0,
|
||||
)
|
||||
|
||||
assert res.reassigned is True
|
||||
# Existing task reverted to PENDING
|
||||
assert task.status == TaskStatus.PENDING
|
||||
assert task.assigned_robot_id is None
|
||||
|
||||
# Urgent task now assigned to robot
|
||||
assert robot.current_task_id == "task_urgent_feed"
|
||||
assert urgent_task.status == TaskStatus.ASSIGNED
|
||||
assert urgent_task.assigned_robot_id == "amr_light_01"
|
||||
Reference in New Issue
Block a user