"""Home of the `Operation` class."""from__future__importannotationsfromjob_shop_lib.exceptionsimportValidationError
[docs]classOperation:"""Stores machine and duration information for a job operation. An operation is a task that must be performed on a machine. It is part of a job and has a duration that represents the time it takes to complete the task. Tip: To use custom attributes, such as due dates or priorities, subclass this class and add the desired attributes. Note: To increase performance, some solvers such as the CP-SAT solver use only integers to represent the operation's attributes. Should a problem involve operations with non-integer durations, it would be necessary to multiply all durations by a sufficiently large integer so that every duration is an integer. Args: machines: A list of machine ids that can perform the operation. If only one machine can perform the operation, it can be passed as an integer. duration: The time it takes to perform the operation. """__slots__={"machines":("A list of machine ids that can perform the operation. If ""only one machine can perform the operation, it can be passed as ""an integer."),"duration":("The time it takes to perform the operation. Often referred"" to as the processing time."),"job_id":("The id of the job the operation belongs to. Defaults to -1. ""It is usually set by the :class:`JobShopInstance` class after ""initialization."),"position_in_job":("The index of the operation in the job. Defaults to -1. ""It is usually set by the :class:`JobShopInstance` class after ""initialization."),"operation_id":("The id of the operation. This is unique within a "":class:`JobShopInstance`. Defaults to -1. It is usually set by ""the :class:`JobShopInstance` class after initialization."),}def__init__(self,machines:int|list[int],duration:int):self.machines:list[int]=([machines]ifisinstance(machines,int)elsemachines)self.duration:int=duration# Defined outside the class by the JobShopInstance class:self.job_id:int=-1self.position_in_job:int=-1self.operation_id:int=-1@propertydefmachine_id(self)->int:"""Returns the id of the machine associated with the operation. Raises: UninitializedAttributeError: If the operation has multiple machines in its list. """iflen(self.machines)>1:raiseValidationError("Operation has multiple machines. The `machine_id` property ""should only be used when working with a classic JSSP ""instance. This error prevents silent bugs. To handle ""operations with more machines you have to use the machines ""attribute. If you get this error using `job_shop_lib` ""objects, it means that that object does not support ""operations with multiple machines yet.")returnself.machines[0]
[docs]defis_initialized(self)->bool:"""Returns whether the operation has been initialized."""return(self.job_id==-1orself.position_in_job==-1orself.operation_id==-1)