jobshoplab.state_machine.core.state_machine package

Submodules

jobshoplab.state_machine.core.state_machine.handler module

Handler module for state machine transitions.

This module contains functions for handling transitions between different states for machines and transports in the JobShopLab simulation. Each handler function is responsible for updating the state of the system based on the specific transition being processed.

create_timed_machine_transitions(loglevel, state)[source]

Create timed machine transitions based on the given state.

This function checks all machines in the system to determine if any have reached their occupied_till time and need to transition to their next state. It creates appropriate ComponentTransitions based on the current state of each machine.

Parameters:
loglevel : int | str

Log level for the function

state : State

Current state of the system

Returns:

A tuple of ComponentTransition objects for machines

that need to transition to their next state

Return type:

tuple[ComponentTransition, …]

create_avg_pickup_to_drop_transition(state, transport)[source]

Creates transition from PICKUP to move to drop location.

This function creates a transition for an AGV (Automated Guided Vehicle) to move from the PICKUP state to the OUTAGE state, representing the completion of a pickup operation and the transition to dropping off the job.

Parameters:
state : State

Current state of the system

transport : TransportState

The transport state that is performing the transition

Returns:

A transition for the transport to move to OUTAGE state

Return type:

ComponentTransition

Raises:

NotImplementedError – If the transport buffer contains more than one job

create_avg_idle_to_pick_transition(state, transport)[source]

Creates transition from IDLE to PICKUP or WAITINGPICKUP.

This function determines the appropriate next transition for an AGV based on the job’s readiness state. It has three possible outcomes: 1. If job has no processing operations pending: return TRANSIT transition 2. If AGV is in PICKUP state and job is not ready: return WAITINGPICKUP transition 3. If job has waiting time and operation time differ: return WAITINGPICKUP transition

Parameters:
state : State

Current state of the system

transport : TransportState

The transport state that is performing the transition

Returns:

A transition for the transport’s next state,

or None if no appropriate transition is found

Return type:

Optional[ComponentTransition]

Raises:

TransportJobError – If the transport has no assigned job (transport_job is None)

create_agv_drop_to_idle_transition(state, transport)[source]

Creates a transition from drop-off completion to IDLE state.

This function creates a transition for an AGV to return to the IDLE state after completing a job delivery, allowing it to be assigned to a new job.

Parameters:
state : State

Current state of the system

transport : TransportState

The transport state that is performing the transition

Returns:

A transition for the transport to return to IDLE state

Return type:

ComponentTransition

create_timed_transport_transitions(loglevel, state)[source]

Creates timed transport transitions based on the given state.

This function examines all transports to determine if any have reached their occupied_till time and need to transition to a new state. It creates appropriate transitions based on each transport’s current state and context.

Parameters:
loglevel : int | str

The log level to use

state : State

Current state of the system

Returns:

A tuple of transitions for transports that

have reached their occupied_till time

Return type:

Tuple[ComponentTransition, …]

Raises:

NotImplementedError – If a transport is in the WORKING state and needs a transition (this state is not yet implemented)

create_timed_transitions(loglevel, state)[source]

Create timed transitions for the given state.

This function combines machine and transport timed transitions into a single list. It checks if occupation time of components is over and creates transitions to advance them to their next state.

The order of transitions is important to ensure proper sequencing of events: 1. Machine transitions are processed first 2. Transport transitions are processed second

Parameters:
loglevel : int | str

The log level to use

state : State

Current state of the system

Returns:

A tuple of all timed transitions for the current state

Return type:

Tuple[ComponentTransition, …]

handle_machine_idle_to_setup_transition(state, instance, transition, machine)[source]

Handles the transition from machine IDLE to SETUP state.

This function moves a job from the machine’s prebuffer to its buffer and sets up the machine to start processing the job. It calculates setup times based on the tools needed for the operation.

Parameters:
state : State

Current state of the system

instance : InstanceConfig

The instance configuration

transition : ComponentTransition

The transition object containing component and job IDs

machine : MachineState

The machine state being transitioned

Returns:

Updated state after handling the transition

Return type:

State

Raises:

InvalidValue – If transition has no job_id or job is not in prebuffer

handle_machine_setup_to_working_transition(state, instance, transition, machine)[source]

Handles the transition from machine SETUP to WORKING state.

This function moves a job from setup phase to active processing. It updates both job and machine state to reflect the new processing status and calculates the operation duration.

Parameters:
state : State

Current state of the system

instance : InstanceConfig

The instance configuration

transition : ComponentTransition

The transition object containing component and job IDs

machine : MachineState

The machine state being transitioned

Returns:

Updated state after handling the transition

Return type:

State

Raises:

InvalidValue – If transition has no job_id or job is not in machine’s buffer

handle_machine_working_to_outage_transition(state, instance, transition, machine)[source]

Handles the transition from machine WORKING to OUTAGE state.

This function places the machine in an outage state, which may represent planned maintenance, a breakdown, or other non-operational period. It calculates the duration of the outage and updates both the machine and job states accordingly.

Parameters:
state : State

Current state of the system

instance : InstanceConfig

The instance configuration

transition : ComponentTransition

The transition object containing component and job IDs

machine : MachineState

The machine state being transitioned

Returns:

Updated state after handling the transition

Return type:

State

handle_machine_outage_to_idle_transition(state, instance, _transition, machine)[source]

Handles the transition from machine OUTAGE to IDLE state.

This function completes the current outage period and finishes the job operation. It moves the job to the machine’s postbuffer, marks the operation as complete, and resets the machine to idle state.

Parameters:
state : State

Current state of the system

instance : InstanceConfig

The instance configuration

_transition : ComponentTransition

The transition object (not directly used in this function)

machine : MachineState

The machine state being transitioned

Returns:

Updated state after handling the transition

Return type:

State

handle_agv_transport_pickup_to_waitingpickup_transition(state, instance, transition, transport)[source]

Handles when an AGV is at the pickup location and waits for the job to be ready.

This function updates the transport to wait at the pickup location until the job completes its current processing operation. It sets the transport’s occupied_till time to match the job’s operation end time.

Parameters:
state : State

Current state of the system

instance : InstanceConfig

The instance configuration

transition : ComponentTransition

The transition object containing component and job IDs

transport : TransportState

The transport state being transitioned

Returns:

Updated state after handling the transition

Return type:

State

Raises:
handle_agv_transport_pickup_to_transit_transition(state, instance, transition, transport)[source]

Handles picking up a job and moving it to the next operation location.

This function picks up a job from its current location (either a standalone buffer or a machine’s buffer), transfers it to the transport’s buffer, and sets up the transport to move the job to its next destination.

Parameters:
state : State

Current state of the system

instance : InstanceConfig

The instance configuration

transition : ComponentTransition

The transition object containing component and job IDs

transport : TransportState

The transport state being transitioned

Returns:

Updated state after handling the transition

Return type:

State

Raises:

MissingJobIdError – If transition has no job_id

handle_agv_transport_idle_to_working_transition(state, instance, transition, transport_state)[source]

Moves the transport to the pickup location of the next operation.

This function calculates the time required to reach the pickup location based on the transport’s current position and the job’s location. It updates the transport’s state and sets its occupied_till time accordingly.

Parameters:
state : State

Current state of the system

instance : InstanceConfig

The instance configuration

transition : ComponentTransition

The transition object containing component and job IDs

transport_state : TransportState

The transport state being transitioned

Returns:

Updated state after handling the transition

Return type:

State

Raises:
  • InvalidValue – If transition has no job_id or transport location is invalid

  • TransportConfigError – If source buffer configuration is invalid or travel time is not found

handle_agv_transport_transit_to_outage_transition(state, instance, transition, transport)[source]

Handles the transition from transport TRANSIT to OUTAGE state.

This function completes the transport task by delivering the job to its destination machine. It moves the job from the transport buffer to the machine’s prebuffer and updates all relevant states.

Parameters:
state : State

Current state of the system

instance : InstanceConfig

The instance configuration

transition : ComponentTransition

The transition object containing component and job IDs

transport : TransportState

The transport state being transitioned

Returns:

Updated state after handling the transition

Return type:

State

Raises:

MissingJobIdError – If transition has no job_id

handle_agv_transport_outage_to_idle_transition(state, instance, transition, transport)[source]

Handles the transition from transport OUTAGE to IDLE state.

This function releases all outages on the transport and returns it to idle state so it can be assigned to a new task.

Parameters:
state : State

Current state of the system

instance : InstanceConfig

The instance configuration

transition : ComponentTransition

The transition object containing component and job IDs

transport : TransportState

The transport state being transitioned

Returns:

Updated state after handling the transition

Return type:

State

handle_agv_waiting_pickup_to_waiting_pickup_transition(state, instance, transition, transport)[source]

Handles the transition from AGV WAITINGPICKUP to WAITINGPICKUP state.

This function updates the transport’s occupied_till time based on the job’s processing operation end time. This is used to extend waiting time, especially in cases of stochastic operation durations.

Parameters:
state : State

Current state of the system

instance : InstanceConfig

The instance configuration

transition : ComponentTransition

The transition object containing component and job IDs

transport : TransportState

The transport state being transitioned

Returns:

Updated state after handling the transition

Return type:

State

Raises:
handle_transition(state, instance, transition, component, transition_handlers)[source]

Handle a transition by finding and executing the appropriate handler function.

This function acts as a dispatcher that finds the correct handler for a given transition based on conditional functions. It iterates through a dictionary of condition-handler pairs, where conditions are functions that determine if the handler should be applied based on the component and transition state.

Parameters:
state : State

Current state of the system

instance : InstanceConfig

Instance configuration

transition : ComponentTransition

The transition object containing component and job IDs

component : Any

The component (machine, transport, etc.) being transitioned

transition_handlers : dict[callable, callable]

Dictionary mapping condition functions to handler functions

Returns:

Updated state after handling the transition

Return type:

State

Raises:

NotImplementedError – If no matching handler is found for the transition

handle_transport_transition(state, instance, transition)[source]

Handle transitions for transport components in the state machine.

This function identifies the appropriate transition handler based on the transport type (currently only AGV supported) and the transition requested. It maintains a dictionary of transition conditions and their corresponding handler functions.

Parameters:
state : State

Current state of the system

instance : InstanceConfig

Instance configuration

transition : ComponentTransition

The transition object containing component and job IDs

Returns:

Updated state after handling the transport transition

Return type:

State

Raises:

NotImplementedError – If the transport type is not supported or no matching handler is found for the transition

handle_machine_transition(state, instance, transition)[source]

Handle transitions for machine components in the state machine.

This function identifies and executes the appropriate transition handler for machines based on the current state and requested transition. It maintains a dictionary of transition conditions and their corresponding handler functions.

Parameters:
state : State

Current state of the system

instance : InstanceConfig

Instance configuration

transition : ComponentTransition

The transition object containing component and job IDs

Returns:

Updated state after handling the machine transition

Return type:

State

Raises:

NotImplementedError – If no matching handler is found for the transition

extract_time(time_obj)[source]

Extract the integer time value from a Time object or raise an error for NoTime.

This utility function safely extracts the numeric time value from a Time object, or raises an error if given a NoTime object.

Parameters:
time_obj : Time | NoTime

A Time or NoTime object

Returns:

The time value as an integer

Return type:

int

Raises:

NotImplementedError – If time_obj is not a Time instance

jobshoplab.state_machine.core.state_machine.manipulate module

State manipulation functions for JobShopLab state machine.

This module contains functions that manipulate the state of machines, jobs, and transport systems within the JobShopLab simulation. These functions handle the core state transitions and ensure the correct movement of jobs and updating of component states.

complete_transport_task(instance, job_state, transport, machine, time)[source]

Complete a transport task by delivering a job to its destination machine.

This function handles the process of: 1. Moving the job from the transport buffer to the machine prebuffer 2. Setting the transport to OUTAGE state (representing drop-off time) 3. Calculating and setting the time required for drop-off 4. Clearing the transport’s job assignment

Parameters:
instance : InstanceConfig

The instance configuration containing time information

job_state : JobState

The state of the job being transported

transport : TransportState

The transport state carrying the job

machine : MachineState

The destination machine state

time : Time | NoTime

The current simulation time

Returns:

Tuple containing updated job_state, transport, and machine states

Raises:

NotImplementedError – If time is not a Time instance

Return type:

Tuple[JobState, TransportState, MachineState]

complete_active_operation_on_machine(instance, jobs, machine_state, time)[source]

Complete the active operation on a machine.

This function handles the process of: 1. Moving the job from the machine buffer to the postbuffer 2. Setting the operation state to DONE 3. Setting the machine state to IDLE 4. Clearing machine outages

Parameters:
instance : InstanceConfig

The instance configuration

jobs : tuple[JobState, ...]

Tuple of all job states in the system

machine_state : MachineState

The machine state to update

time : Time | NoTime

The current simulation time

Returns:

Tuple containing updated job_state and machine_state

Raises:
Return type:

Tuple[JobState, MachineState]

begin_next_job_on_machine(instance, job_state, machine_state, time)[source]

Start processing a job on a machine after setup is complete.

This function handles the transition from setup to working state by: 1. Setting the operation state to PROCESSING 2. Calculating operation duration based on the operation configuration 3. Setting the machine state to WORKING 4. Setting the machine’s occupied_till time based on the operation duration

Parameters:
instance : InstanceConfig

The instance configuration containing operation durations

job_state : JobState

The state of the job to process

machine_state : MachineState

The machine state to update

time : Time | NoTime

The current simulation time

Returns:

Tuple containing updated job_state and machine_state

Return type:

Tuple[JobState, MachineState]

begin_machine_outage(instance, job_state, machine_state, time, occupied_for, outages)[source]

Start a machine outage (e.g., maintenance or breakdown).

This function transitions a machine from WORKING to OUTAGE state: 1. Sets the machine state to OUTAGE 2. Updates the machine’s outage records 3. Sets the machine’s occupied_till time based on the outage duration 4. Updates the job’s operation end time to match the outage end time

Parameters:
instance : InstanceConfig

The instance configuration

job_state : JobState

The state of the job currently on the machine

machine_state : MachineState

The machine state to update

time : Time | NoTime

The current simulation time

occupied_for : int

The duration of the outage in time units

outages : Sequence

Sequence of outage states for the machine

Returns:

Tuple containing updated job_state and machine_state

Raises:

NotImplementedError – If time is not a Time instance

Return type:

Tuple[JobState, MachineState]

begin_machine_setup(instance, job_state, machine_state, time)[source]

Start setting up a machine for a new operation.

This function handles the transition from IDLE to SETUP by: 1. Moving the job from the machine’s prebuffer to its buffer 2. Setting the machine state to SETUP 3. Calculating setup time based on tool change requirements 4. Setting the machine’s occupied_till time based on the setup duration 5. Updating the machine’s mounted tool 6. Setting the operation state to PROCESSING (during setup)

Parameters:
instance : InstanceConfig

The instance configuration containing setup time information

job_state : JobState

The state of the job to process

machine_state : MachineState

The machine state to update

time : Time | NoTime

The current simulation time

Returns:

Tuple containing updated job_state and machine_state

Return type:

Tuple[JobState, MachineState]

jobshoplab.state_machine.core.state_machine.state module

Functional state machine implementation for JobShopLab.

This module contains the core state machine functionality for the JobShopLab simulation. It handles state transitions, action processing, and determines possible transitions for a given state. The state machine is responsible for advancing the simulation state according to specified transitions and time progression.

is_done(state)[source]

Check if the state machine has completed all jobs.

This function determines if all operations across all jobs have reached completion status. The simulation is considered complete when all required tasks have been processed.

Parameters:
state : StateMachineResult

The state machine result containing the simulation state to check

Returns:

True if all operations are done, False otherwise

Return type:

bool

apply_transition(loglevel, state, instance, transition)[source]

Apply a transition to the state machine.

This function routes the transition to the appropriate handler based on the component type (machine or transport). It acts as a dispatcher that determines the specific component type and calls the corresponding handler function.

Parameters:
loglevel : int | str

The logging level to use for debug information

state : State

The current state of the system containing all component states

instance : InstanceConfig

The instance configuration containing problem setup information

transition : ComponentTransition

The transition to apply, specifying component and desired state

Returns:

The updated state after applying the transition

Return type:

State

Raises:
process_state_transitions(transitions, state, instance, loglevel, sort=None)[source]

Process a list of transitions for a given state.

This function validates and applies each transition in sequence. If a sorting function is provided, the transitions will be sorted before processing to ensure proper execution order.

Parameters:
transitions : tuple[ComponentTransition, ...]

A tuple of transitions to process sequentially

state : State

The current state of the system

instance : InstanceConfig

The instance configuration

loglevel : int | str

The logging level to use for debug information

sort : Callable[[tuple[ComponentTransition, ...]], tuple[ComponentTransition, ...]] | None

Optional function to sort transitions in a specific order

Returns:

The result of processing the transitions containing

the updated state and any errors that occurred during processing

Return type:

TransitionResult

step(loglevel, instance, config, state, action)[source]

Execute a single step in the state machine.

This function applies the transitions provided in the action, advances time, and creates and processes any timed transitions that should occur. It handles teleport transitions (zero travel time) and ensures that the state machine correctly processes all events in the proper sequence.

The step process involves several phases: 1. Applying initial transitions from the action 2. Advancing time using the specified time machine 3. Processing any timed transitions that become active 4. Handling teleport transitions with zero travel time 5. Repeating the process until no more timed transitions are available

Parameters:
loglevel : int | str

The logging level to use for debug information

instance : InstanceConfig

The instance configuration containing problem setup

config : __SPHINX_IMMATERIAL_TYPE_VAR__V_Config

The global configuration of the simulation

state : State

The current state of the system

action : Action

The action to apply, containing transitions and time machine

Returns:

The result of the step, including the updated state,

intermediate sub-states, success status, and possible next transitions

Return type:

StateMachineResult

get_possible_transitions(state, instance)[source]

Get all possible transitions for a given state.

This function identifies jobs that can be processed and transports that can move jobs, then creates appropriate transitions for each. The function examines the current state to determine what actions are possible next.

Parameters:
state : State

The current state of the system containing all components

instance : InstanceConfig

The instance configuration with problem setup information

Returns:

A tuple of all possible transitions that

can be executed from the current state

Return type:

tuple[ComponentTransition, …]

jobshoplab.state_machine.core.state_machine.validate module

Validation module for state machine transitions.

This module contains functions for validating transitions between different states in the JobShopLab simulation. It ensures that transitions requested by components (machines, transports, etc.) are valid according to the state machine rules.

is_machine_transition_valid(state, machine, transition)[source]

Check if a machine transition is valid according to transition rules.

This function validates machine state transitions by checking: 1. If the transition is allowed according to the machine transition rules 2. Special cases for transitions from outage to idle and working to outage 3. Whether the job’s next operation is assigned to this machine

Parameters:
state : State

The current state of the job shop system

machine : MachineState

The machine state to be transitioned

transition : ComponentTransition

The requested transition to validate

Returns:

A tuple containing:
  • Boolean indicating if the transition is valid

  • String with an error message if invalid, empty string if valid

Return type:

Tuple[bool, str]

is_transport_transition_valid(state, component, transition)[source]

Check if a transport transition is valid according to transition rules.

This function validates transport state transitions using the TransportTransition rules defined in the transitions module.

Parameters:
state : State

The current state of the system

component : TransportState

The transport component whose state is being checked

transition : ComponentTransition

The component transition to be validated

Returns:

A tuple containing:
  • Boolean indicating if the transition is valid

  • String with an error message if invalid, empty string if valid

Return type:

Tuple[bool, str]

is_transition_valid(loglevel, state, transition)[source]

Check if a transition is valid for a given component.

This function dispatches the validation to the appropriate component-specific validation function based on the type of component being transitioned.

Parameters:
loglevel : int | str

The log level for logging messages

state : State

The current state of the system

transition : ComponentTransition

The component transition to be validated

Returns:

A tuple containing:
  • Boolean indicating if the transition is valid

  • String with an error message if invalid, empty string if valid

Return type:

Tuple[bool, str]

Raises:

NotImplementedError – If the component type is not supported for validation

Module contents