Skip to content

Commit

Permalink
out of service instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
robfitzgerald committed Sep 29, 2023
1 parent 64a7614 commit f1fd7af
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions nrel/hive/dispatcher/instruction/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from nrel.hive.state.vehicle_state.dispatch_trip import DispatchTrip
from nrel.hive.state.vehicle_state.idle import Idle
from nrel.hive.state.vehicle_state.repositioning import Repositioning
from nrel.hive.state.vehicle_state.out_of_service import OutOfService
from nrel.hive.state.vehicle_state.reserve_base import ReserveBase
from nrel.hive.state.vehicle_state.servicing_pooling_trip import ServicingPoolingTrip
from nrel.hive.util.exception import SimulationStateError, InstructionError
Expand Down Expand Up @@ -341,3 +342,22 @@ def apply_instruction(
next_state = ReserveBase.build(self.vehicle_id, self.base_id)

return None, InstructionResult(prev_state, next_state)


@dataclass(frozen=True)
class OutOfServiceInstruction(Instruction):
vehicle_id: VehicleId

def apply_instruction(
self, sim_state: SimulationState, env: Environment
) -> Tuple[Optional[Exception], Optional[InstructionResult]]:
vehicle = sim_state.vehicles.get(self.vehicle_id)
if not vehicle:
msg = (
f"vehicle {self.vehicle_id} not found; context: applying out of service instruction"
)
return (SimulationStateError(msg), None)

prev_state = vehicle.vehicle_state
next_state = OutOfService.build(self.vehicle_id)
return None, InstructionResult(prev_state, next_state)

0 comments on commit f1fd7af

Please sign in to comment.