"""Home of the `ScheduledOperation` class."""fromjob_shop_libimportOperationfromjob_shop_lib.exceptionsimportValidationError
[docs]classScheduledOperation:"""Data structure to store a scheduled operation. Args: operation: The :class:`Operation` object that is scheduled. start_time: The time at which the operation is scheduled to start. machine_id: The id of the machine on which the operation is scheduled. Raises: ValidationError: If the given machine_id is not in the list of valid machines for the operation. """__slots__={"operation":"The :class:`Operation` object that is scheduled.","start_time":"The time at which the operation is scheduled to start.","_machine_id":("The id of the machine on which the operation is scheduled."),}def__init__(self,operation:Operation,start_time:int,machine_id:int):self.operation:Operation=operationself.start_time:int=start_timeself._machine_id=machine_idself.machine_id=machine_id# Validate machine_id@propertydefmachine_id(self)->int:"""Returns the id of the machine on which the operation has been scheduled."""returnself._machine_id@machine_id.setterdefmachine_id(self,value:int):ifvaluenotinself.operation.machines:raiseValidationError(f"Operation cannot be scheduled on machine {value}. "f"Valid machines are {self.operation.machines}.")self._machine_id=value@propertydefjob_id(self)->int:"""Returns the id of the job that the operation belongs to."""returnself.operation.job_id@propertydefposition_in_job(self)->int:"""Returns the position (starting at zero) of the operation in the job."""returnself.operation.position_in_job@propertydefend_time(self)->int:"""Returns the time at which the operation is scheduled to end."""returnself.start_time+self.operation.durationdef__repr__(self)->str:return(f"S-Op(operation={self.operation}, "f"start_time={self.start_time}, machine_id={self.machine_id})")def__eq__(self,value:object)->bool:ifnotisinstance(value,ScheduledOperation):returnFalsereturn(self.operation==value.operationandself.start_time==value.start_timeandself.machine_id==value.machine_id)def__hash__(self)->int:returnhash((self.operation,self.start_time,self.machine_id))