jobshoplab.utils.state_machine_utils package

Submodules

jobshoplab.utils.state_machine_utils.buffer_type_utils module

replace_buffer_state(state, buffer_state)[source]
Parameters:
state : State

Return type:

State

get_output_buffers(instance)[source]

Get all output buffer configurations from the instance.

This function filters all buffers in the instance to return only those with the OUTPUT role, which are designated as final destinations for completed jobs in the job shop scheduling system.

Parameters:
instance : InstanceConfig

The instance configuration containing all buffers.

Returns:

A tuple of buffer configurations that have

the OUTPUT role. Used to determine where completed jobs should be transported to mark them as finished.

Return type:

tuple[BufferConfig, …]

get_buffer_config_by_id(buffers, buffer_id)[source]

Get a buffer config by its ID from a tuple of BufferConfig objects.

Parameters:
buffers : tuple[BufferConfig, ...]

A tuple of BufferConfig objects.

buffer_id : str

The ID of the desired buffer.

Returns:

The BufferConfig object with the specified ID.

Return type:

BufferConfig

Raises:

InvalidValue – If the desired buffer is not found in the given tuple of buffers.

is_job_in_buffer(buffer_state, job_id)[source]

Check if a job is in a buffer.

Parameters:
buffer_state : BufferState

The buffer to check.

job_id : str

The ID of the job to check.

Returns:

True if the job is in the buffer, False otherwise.

Return type:

bool

put_in_buffer(buffer_state, buffer_config, job_state)[source]

Put a job in a buffer.

Parameters:
buffer_state : BufferState

The buffer to put the job in.

job_state : JobState

The job to put in the buffer.

buffer_config : BufferConfig

Returns:

The updated buffer state.

Return type:

BufferState

switch_buffer(instance, buffer_from_state, buffer_to_state, job_state)[source]

Switch a job from one buffer to another.

Parameters:
buffer_from_state : BufferState

The buffer to remove the job from.

buffer_to_state : BufferState

The buffer to put the job in.

job_state : JobState

The job to switch buffers.

instance : InstanceConfig

Returns:

The updated buffer states and job state.

Return type:

tuple[BufferState, BufferState, JobState]

remove_from_buffer(buffer_state, job_id)[source]

Remove a job from a buffer.

Parameters:
buffer_state : BufferState

The buffer to remove the job from.

job_id : str

The id of the job to remove from the buffer.

Returns:

The updated buffer state.

Return type:

BufferState

get_all_buffer_configs(instance)[source]

Get all buffer configurations from the instance configuration.

Parameters:
instance : InstanceConfig

The instance configuration.

Returns:

A list of all buffer configurations.

Return type:

list[BufferConfig]

get_all_buffer_states(state)[source]

Get all buffer states from the state.

Parameters:
state : State

The state.

Returns:

A list of all buffer states.

Return type:

list[BufferState]

get_buffer_state_by_id(buffers, buffer_id)[source]

Get a buffer state by its ID from a tuple of BufferState objects.

Parameters:
buffers : tuple[BufferState, ...]

A tuple of BufferState objects.

buffer_id : str

The ID of the desired buffer.

Returns:

The BufferState object with the specified ID.

Return type:

BufferState

Raises:

InvalidValue – If the desired buffer is not found in the given tuple of buffers.

get_next_job_from_buffer(buffer_state, buffer_config)[source]

Get the next job ID to process based on buffer type.

Parameters:
buffer_state : BufferState

The current state of the buffer containing job IDs

buffer_config : BufferConfig

The buffer configuration specifying type (FIFO, LIFO, etc.)

Returns:

The job ID to process next, or None if no automatic ordering applies

Return type:

str < /dev/null | None

get_job_position_in_buffer(job_id, postbuffer_state)[source]

Get the position (index) of a job within a postbuffer.

Parameters:
job_id : str

The ID of the job to find

postbuffer_state : BufferState

The postbuffer state containing job IDs

Returns:

The index position of the job, or None if not found

Return type:

int | None

is_correct_position_for_buffer_type(job_position, buffer_length, buffer_type)[source]

Check if a job position is valid for pickup based on buffer type.

Parameters:
job_position : int

The index position of the job in the buffer

buffer_length : int

The total number of jobs in the buffer

buffer_type : BufferTypeConfig

The type of buffer (FIFO, LIFO, FLEX, etc.)

Returns:

True if the job can be picked up from this position, False otherwise

Return type:

bool

job_in_correct_buffer_for_pickup(instance, buffer)[source]

Check if a job is in the correct buffer for pickup based on buffer type constraints. :param instance: The instance configuration containing buffer configurations :param buffer: The buffer to check against

Parameters:
instance : InstanceConfig

buffer : BufferState

Return type:

bool

is_job_ready_for_pickup_from_postbuffer(job_state, state, instance_config)[source]

Check if a job is ready for pickup from its postbuffer based on buffer type constraints.

Parameters:
job_state : JobState

The state of the job to check

state : State

The current state of the system

instance_config : InstanceConfig

The instance configuration containing buffer configurations

Returns:

True if the job can be picked up, False otherwise

Return type:

bool

jobshoplab.utils.state_machine_utils.component_type_utils module

get_obj_by_id(obj, id)[source]

Get an object by its ID from a tuple of objects.

Parameters:
obj : Tuple[T, ...]

A tuple of objects.

id : str

The ID of the desired object.

Returns:

The object with the specified ID.

Return type:

T

Raises:

InvalidValue – If the desired object is not found in the given tuple of objects.

get_comp_by_id(state, id)[source]
Parameters:
state : State

id : str

jobshoplab.utils.state_machine_utils.core_utils module

print_state(state)[source]
Parameters:
state : State

Return type:

None

is_done(state, instance)[source]

Check if the state machine is done by verifying all jobs are in output buffers.

This function determines completion based on job locations rather than operation states. A job shop system is considered complete when all jobs have been transported to their final destination (output buffers), not just when their operations are finished. This ensures proper material flow and system closure.

Parameters:
state : State

The current state of the state machine containing all jobs.

instance : InstanceConfig

The instance configuration containing buffer definitions.

Returns:

True if all jobs are located in output buffers, False otherwise.

This indicates whether the entire job shop scheduling process is complete.

Return type:

bool

no_processing_operations(job)[source]

Checks if a job has any processing operations.

Parameters:
job : JobState

The job to check.

Returns:

True if the job has no processing operations, False otherwise.

Return type:

bool

is_machine_transition_from_idle_to_setup(machine, transition)[source]
Parameters:
machine : MachineState

transition : ComponentTransition

Return type:

bool

is_machine_transition_from_setup_to_working(machine, transition)[source]
Parameters:
machine : MachineState

transition : ComponentTransition

Return type:

bool

is_machine_transition_from_working_to_outage(machine, transition)[source]
Parameters:
machine : MachineState

transition : ComponentTransition

Return type:

bool

is_machine_transition_from_outage_to_idle(machine, transition)[source]
Parameters:
machine : MachineState

transition : ComponentTransition

Return type:

bool

is_transport_transition_from_idle_to_working(transport, transition)[source]
Parameters:
transport : TransportState

transition : ComponentTransition

Return type:

bool

is_transport_transition_from_pickup_to_transit(transport, transition)[source]
Parameters:
transport : TransportState

transition : ComponentTransition

Return type:

bool

is_transport_transition_from_pickup_to_waitingpickup(transport, transition)[source]
Parameters:
transport : TransportState

transition : ComponentTransition

Return type:

bool

is_transport_transition_from_waitingpickup_to_transit(transport, transition)[source]
Parameters:
transport : TransportState

transition : ComponentTransition

Return type:

bool

is_transport_transition_from_working_to_outage(transport, transition)[source]
Parameters:
transport : TransportState

transition : ComponentTransition

Return type:

bool

is_transport_transition_from_transit_to_outage(transport, transition)[source]
Parameters:
transport : TransportState

transition : ComponentTransition

Return type:

bool

is_transport_transition_from_outage_to_idle(transport, transition)[source]
Parameters:
transport : TransportState

transition : ComponentTransition

Return type:

bool

is_transport_transition_from_waiting_pickup_waiting_pickup(transport, transition)[source]
Parameters:
transport : TransportState

transition : ComponentTransition

Return type:

bool

sorted_by_transport(transitions)[source]
Parameters:
transitions : tuple[ComponentTransition, ...]

Return type:

tuple[ComponentTransition, …]

create_transport_location_from_job(current_dest, pickup_dest, dropoff_dest)[source]
Parameters:
current_dest : str

pickup_dest : str

dropoff_dest : str

Return type:

TransportLocation

sorted_done_operations(job_states)[source]
Parameters:
job_states : tuple[JobState, ...]

Return type:

tuple[OperationState, …]

jobshoplab.utils.state_machine_utils.dispatch_rules_uitls module

get_inbuffer_jobs_for_machine(instance, state, machine_id)[source]
Parameters:
instance : InstanceConfig

state : State

machine_id : str

get_prebuffer_operations_for_machine(instance, state, machine_id)[source]
Parameters:
instance : InstanceConfig

state : State

machine_id : str

find_job_state_from_operation(state, operation_id)[source]
Parameters:
state : State

operation_id : str

Return type:

JobState | None

find_job_config_from_operation(instance, operation_id)[source]
Parameters:
instance : InstanceConfig

operation_id : str

get_machine_prebuffer_jobs_by_processing_time(instance, state, mode='SPT')[source]

Gets jobs for machines based on the processing time of their next operation.

Parameters:
instance : InstanceConfig

state : State

get_machine_jobs_by_remaining_processing_time(instance, state, mode='srpt')[source]

Assigns jobs to machines based on Shortest/Longest Remaining Processing Time.

Parameters:
instance : InstanceConfig

state : State

get_all_outbuffer_jobs(instance, state)[source]

Retrieves all jobs in outbuffer and postbuffer across machines.

Parameters:
instance : InstanceConfig

state : State

get_job_with_most_remaining_processing_time(instance, job_states)[source]

Returns the job with the most remaining processing time.

Parameters:
instance : InstanceConfig

job_states : tuple[JobState, ...]

get_job_by_operation_count(job_states, find_max=True)[source]

Returns the job with the most or least remaining operations.

jobshoplab.utils.state_machine_utils.job_type_utils module

job_at_machine(job, machine)[source]

Check if a job is at a machine.

Parameters:
job : JobState

The job to check.

machine : MachineState

The machine to check.

Returns:

True if the job is at the machine, False otherwise.

Return type:

bool

get_job_state_by_id(jobs, job_id)[source]

Get a job by its ID from a tuple of JobState objects.

Parameters:
jobs : tuple[JobState, ...]

A tuple of JobState objects.

job_id : str

The ID of the desired job.

Returns:

The JobState object with the specified ID.

Return type:

JobState

Raises:

InvalidValue – If the desired job is not found in the given tuple of jobs.

get_job_config_by_id(jobs, job_id)[source]

Get a job config by its ID from a tuple of JobConfig objects.

Parameters:
jobs : tuple[JobConfig, ...]

A tuple of JobConfig objects.

job_id : str

The ID of the desired job.

Returns:

The JobConfig object with the specified ID.

Return type:

JobConfig

Raises:

InvalidValue – If the desired job is not found in the given tuple of jobs.

get_operation_state_by_id(jobs, operation_id)[source]

Get an operation by its ID from a tuple of JobState objects.

Parameters:
jobs : tuple[JobState, ...]

A tuple of JobState objects.

operation_id : str

The ID of the desired operation.

Returns:

The JobState object with the specified ID.

Return type:

JobState

Raises:

InvalidValue – If the desired operation is not found in the given tuple of jobs.

get_operation_config_by_id(jobs, operation_id)[source]

Get an operation config by its ID from a tuple of JobConfig objects.

Parameters:
jobs : tuple[JobConfig, ...]

A tuple of JobConfig objects.

operation_id : str

The ID of the desired operation.

Returns:

The JobConfig object with the specified ID.

Return type:

JobConfig

Raises:

InvalidValue – If the desired operation is not found in the given tuple of jobs.

is_last_operation_running(job)[source]

Check if the last operation of a job is running.

Parameters:
job : JobState

The job to check.

Returns:

True if the last operation of the job is running, False otherwise.

Return type:

bool

is_job_running(job)[source]

Check if a job is running.

Parameters:
job : JobState

The job to check.

Returns:

True if the job is running, False otherwise.

Return type:

bool

get_next_not_done_operation(job)[source]

Get the next operation from a job.

Parameters:
job : JobState

The job to get the next operation from.

Returns:

The next operation from the job.

Return type:

OperationState

Raises:

InvalidValue – If the job has no more operations.

get_next_idle_operation(job)[source]

Get the next idle operation from a job that needs to be executed.

This function searches for the first operation in the job that is in IDLE state, meaning it’s ready to be processed. Unlike get_next_not_done_operation, this function returns None if no idle operations exist, allowing graceful handling of jobs where all operations are complete or in progress.

Parameters:
job : JobState

The job to get the next idle operation from.

Returns:

The next idle operation from the job, or None

if no idle operations remain. This allows proper handling of completed jobs without raising exceptions.

Return type:

Optional[OperationState]

get_next_operation_for_machine(machine_id, jobs)[source]
Parameters:
jobs : JobState

Return type:

OperationState

get_prior_executed_operation(job)[source]

Get the last operation from a job that is in the DONE state. :param job: The job to get the last operation from. :type job: JobState

Returns:

The last operation from the job that is in the DONE state.

Return type:

OperationState

Raises:

InvalidValue – If the job has no operations in the DONE state.

Parameters:
job : JobState

get_processing_operation(job)[source]

Get the active operation from a job.

Parameters:
job : JobState

The job to get the active operation from.

Returns:

The active operation from the job.

Return type:

OperationState

Raises:

InvalidValue – If the job has no active operations.

group_operations_by_state(job_states)[source]

Group all operations from job states by their operation state state.

Parameters:
job_states : Iterable[JobState]

An iterable of JobState objects.

Returns:

A dictionary with the operation state state as the key and a list of operations as the value.

Return type:

dict[OperationStateState, list[OperationState]]

is_done(job, instance)[source]

Check if a job is completely done in the job shop system.

A job is considered done when two conditions are met: 1. All operations are completed (DONE state) 2. The job has been transported to an output buffer

This dual-condition approach ensures that job completion includes both processing completion and proper material flow to the final destination.

Parameters:
job : JobState

The job to check for completion.

instance : InstanceConfig

The instance configuration containing buffer definitions.

Returns:

True if the job is completely done (operations complete AND in output buffer),

False otherwise. This indicates full job shop process completion for the job.

Return type:

bool

all_operations_done(job)[source]

Check if all operations in a single job are in DONE state.

This function verifies that every operation within a job has been completed by checking their state. It’s used as a prerequisite for job completion but doesn’t guarantee the job is fully done (transportation to output buffer is also required).

Parameters:
job : JobState

The job to check for operation completion.

Returns:

True if all operations in the job are in DONE state, False otherwise.

This indicates processing completion but not necessarily full job completion.

Return type:

bool

no_operation_idle(job)[source]

Check if no operations in a job are in IDLE state.

This function determines if a job has any remaining operations that need to be executed. When this returns True, it means all operations are either in progress (PROCESSING) or completed (DONE), indicating the job may need transportation to the output buffer rather than to another machine for processing.

Parameters:
job : JobState

The job to check for idle operations.

Returns:

True if no operations are in IDLE state (all are PROCESSING or DONE),

False if at least one operation is still waiting to be processed. Used to determine if job needs transport to output vs. next operation.

Return type:

bool

jobshoplab.utils.state_machine_utils.logisitcs_type_uitls module

get_travel_time(logistics)[source]
Parameters:
logistics : LogisticsConfig

Return type:

int

jobshoplab.utils.state_machine_utils.machine_type_utils module

get_machine_state_by_id(machines, machine_id)[source]

Get a machine by its ID from a tuple of MachineState objects.

Parameters:
machines : tuple[MachineState, ...]

A tuple of MachineState objects.

machine_id : str

The ID of the desired machine.

Returns:

The MachineState object with the specified ID.

Return type:

MachineState

Raises:

InvalidValue – If the desired machine is not found in the given tuple of machines.

get_machine_config_by_id(machine_configs, machine_id)[source]

Get a machine config by its ID from a tuple of MachineConfig objects.

Parameters:
machine_configs : tuple[MachineConfig, ...]

A tuple of MachineConfig objects.

machine_id : str

The ID of the desired machine.

Returns:

The MachineConfig object with the specified ID.

Return type:

MachineConfig

Raises:

InvalidValue – If the desired machine config is not found in the given tuple of machine configs.

get_machine_id_from_buffer(machine_configs, buffer_id)[source]

Get the Machine where the buffer is located.

Checks if buffer is prebuffer, postbuffer or buffer and returns the corresponding machine id.

Parameters:
machine_configs : tuple[MachineConfig, ...]

buffer_id : str

Return type:

str | None

get_buffer_state_from_machine(machine_state, buffer_id)[source]

Get the buffer state from a machine state.

Parameters:
machine_state : MachineState

buffer_id : str

Return type:

BufferState

replace_buffer_state_in_machine(machine_state, buffer_state)[source]

Update the buffer state in a machine state.

Parameters:
machine_state : MachineState

buffer_state : BufferState

Return type:

MachineState

jobshoplab.utils.state_machine_utils.outage_utils module

get_new_outage_states(component, instance, current_time)[source]

Get the time until the transport is available again.

Parameters:
component : TransportState | MachineState

instance : InstanceConfig

current_time : Time | NoTime

Return type:

tuple[OutageState, …]

get_occupied_time_from_outage_iterator(outage_states)[source]

Get the occupied time from the outage iterator.

Parameters:
outage_states : Iterable

Return type:

int

release_outage(outage)[source]

Release the outage.

jobshoplab.utils.state_machine_utils.possible_transition_utils module

is_job_next_operation_free(job_state)[source]

Checks if a operation at a job is possible -> Job is not finished -> Job is not active

Parameters:
job_state : JobState

Return type:

bool

is_job_at_machine(job_state, machine_state)[source]

Check if a job is at a machine.

Parameters:
job_state : JobState

The job to check.

machine : MachineState

The machine to check.

machine_state : MachineState

Returns:

True if the job is at the machine, False otherwise.

Return type:

bool

is_action_possible(job_state, state, instance)[source]

Checks if a action at a job is possible -> Machine action -> Transport action

Returns: True if the operation is possible, False otherwise

Parameters:
job_state : JobState

state : State

instance : InstanceConfig

Return type:

bool

get_possible_transports(transport_states, transport_configs)[source]

Checks if the transport is possible

Returns: True if the transport is possible, False otherwise

Parameters:
transport_states : tuple[TransportState, ...]

transport_configs : tuple[TransportTypeConfig, ...]

Return type:

Generator[TransportState, None, None]

get_num_possible_events(state, instance, config)[source]

Get the number of possible events

Returns: The number of possible events

Return type:

int

sort_by_id(components)[source]
Parameters:
components : tuple[JobState | TransportState, ...]

Return type:

tuple[JobState | TransportState, …]

is_transportable(job_state, state, instance)[source]

Determine if a job needs transportation in the job shop system.

This function implements the core logic for deciding when jobs require transport: 1. Jobs already at output buffers don’t need transport (fully complete) 2. Jobs with all operations done but not at output need transport to finish 3. Jobs with remaining operations need transport if they’re not at the correct machine 4. Jobs already at their next operation’s machine don’t need transport

Parameters:
job_state : JobState

The job to evaluate for transport needs.

state : State

Current system state containing all component states.

instance : InstanceConfig

Configuration with buffer and machine definitions.

Returns:

True if the job needs transport (either to next operation or output buffer),

False if the job is already at the correct location or fully complete.

Return type:

bool

Raises:

InvalidValue – If job state is inconsistent (no operations but not at output).

is_early_transport(job_state, state, instance)[source]

Determine if a job is eligible for early transport in the job shop system.

An early transport is triggered once the job (operation) has started its processing cycle on a machine. Some systems allow scheduling a transport “early” meaning the AGV is “called” early to avoid waiting times. This can lead to deadlock situations in AGV traffic management. Hence some systems disallow early transport.

In this function we are checking if a job is early meaning not in the correct buffer location.

Parameters:
job_state : JobState

The job state to evaluate.

state : State

The current state of the system.

instance : InstanceConfig

The instance configuration.

Returns:

True if the job is eligible for early transport, False otherwise.

Return type:

bool

get_possible_transport_transition(state, instance, allow_early_transport)[source]

Get all available transports and mach each transport with each possible job Jobs are possible when:

  • Job is in state working -> when finised it need to be transported to next op

  • Job is in state idle and next op is not the current location

  • Jobs that are not getting are already assigned to an agv

  • Jobs where all operations are done but not at the output buffer

Returns: The tuple of possible ComponentTransitions

Parameters:
state : State

allow_early_transport : bool

Return type:

tuple[ComponentTransition, …]

get_possible_transitions(state, instance)[source]

Get all possible transitions for the state

Return type:

tuple[ComponentTransition, …]

replace_machine_state(state, machine_state)[source]
replace_buffer_state(state, buffer_state)[source]
Return type:

State

replace_job_state(state, job_state)[source]
Return type:

State

replace_transport_state(state, transport_state)[source]
Return type:

State

replace_job_operation_state(job, operation)[source]
Parameters:
job : JobState

operation : OperationState

Return type:

JobState

get_component_by_obj(state, obj)[source]
get_component_by_id(components, id)[source]
get_component_by_id_and_type(state, id, dtype)[source]
replace_component_by_id_and_type(state, id, dtype, new_obj)[source]
replace_component_by_obj(state, obj)[source]
replace_components(state, updated_components)[source]

jobshoplab.utils.state_machine_utils.time_utils module

jobshoplab.utils.state_machine_utils.transport_type_utils module

get_transport_state_by_id(transports, transport_id)[source]

Get a transport by its ID from a tuple of TransportState objects.

Parameters:
transports : tuple[TransportState, ...]

A tuple of TransportState objects.

transport_id : str

The ID of the desired transport.

Returns:

The TransportState object with the specified ID.

Return type:

TransportState

Raises:

InvalidValue – If the desired transport is not found in the given tuple of transports.

get_transport_config_by_id(transports, transport_id)[source]

Get a transport by its ID from a tuple of TransportConfig objects.

Parameters:
transports : tuple[TransportConfig, ...]

A tuple of TransportConfig objects.

transport_id : str

The ID of the desired transport.

Returns:

The TransportConfig object with the specified ID.

Return type:

TransportConfig

Raises:

InvalidValue – If the desired transport is not found in the given tuple of transports.

group_transports_by_state(transports)[source]

Group all transports by their state.

Parameters:
transports : tuple[TransportState, ...]

A tuple of TransportState objects.

Returns:

A dictionary with the transport state as the key and a tuple of transports as the value.

Return type:

dict[str, tuple[TransportState, …]]

get_transport_id_by_job_id(state, job_id)[source]

Find which transport is currently assigned to handle a specific job.

Parameters:
state : State

Current state of the system.

job_id : str

ID of the job to find transport for.

Returns:

Transport ID if found, None if no transport is assigned to this job.

Return type:

str | None

get_transport_state_by_job_id(state, job_id)[source]

Find which transport state is currently assigned to handle a specific job.

Parameters:
state : State

Current state of the system.

job_id : str

ID of the job to find transport for.

Returns:

TransportState object if found, None if no transport is assigned to this job.

Return type:

TransportState | None

Module contents