jobshoplab.env package¶
Subpackages¶
- jobshoplab.env.factories package
- jobshoplab.env.rendering package
Submodules¶
jobshoplab.env.env module¶
- class DependencyBuilder[source]¶
Bases:
object
A builder class for managing dependencies in the JobShopLab environment.
This class handles initialization and configuration of various components needed for the JobShopLab environment, including logging, random seeds, and factory objects for observations, rewards, rendering, and state simulation.
- _config¶
Configuration object containing environment settings
- _logger¶
Logger instance for this class
- loglevel(loglevel
int | str | None) -> int | str: Gets loglevel from config or arguments
- logger(loglevel
int | str) -> tuple[any, int | str]: Creates and returns a logger instance
- seed(seed
int | None) -> int | None: Sets random seeds for reproducibility
- compiler(compiler
Compiler | None) -> Compiler: Returns compiler instance, creates new one if None provided
- lower_bound(instance_config
InstanceConfig) -> int: Calculates lower bound for given instance
- max_allowed_time(instance_config
InstanceConfig) -> int: Gets maximum allowed time for instance
- num_operations(instance_config
InstanceConfig) -> int: Returns total number of operations in instance
- observation_factory(observation_factory
any, log_level: int | str, instance: InstanceConfig) -> any: Builds observation factory instance
- reward_factory(reward_factory
any, log_level: int | str, instance: InstanceConfig, max_allowed_time: int) -> any: Builds reward factory instance
- render_backend(render_backend
any, log_level: int | str, instance: InstanceConfig) -> any: Builds render backend instance
- action_factory(action_factory
any, log_level: int | str, instance: InstanceConfig) -> any: Builds action_factory instance
- state_simulator(middleware
any, log_level: int | str, instance: InstanceConfig, action_factory: any, observation_factory: any) -> any: Builds state simulator instance
- Private Methods:
- _to_lowercase(string: str) -> str:
Converts string to lowercase
- _config_args_getter(kwd_list: list[str]) -> dict:
Gets configuration arguments from keyword list
- _get_args(log_level: str | int | None, instance: InstanceConfig, additional_args_kwd: list[str], additional_args: dict) -> dict:
Builds arguments dictionary for factory creation
- _get_instance_from_config(conf_obj: str) -> str:
Gets instance name from configuration
- _build_factory(module: any, env_arg: any, config_name: str, additional_args: dict, log_level: int | str, instance: InstanceConfig) -> any:
Generic factory builder method
- lower_bound(instance_config)[source]¶
- Parameters:¶
- instance_config : InstanceConfig¶
- Return type:¶
- max_allowed_time(instance_config)[source]¶
- Parameters:¶
- instance_config : InstanceConfig¶
- Return type:¶
- num_operations(instance_config)[source]¶
- Parameters:¶
- instance_config : InstanceConfig¶
- Return type:¶
- observation_factory(observation_factory, log_level, instance)[source]¶
- reward_factory(reward_factory, log_level, instance, max_allowed_time)[source]¶
- render_backend(render_backend, log_level, instance)[source]¶
- action_factory(action_factory, log_level, instance)[source]¶
- state_simulator(middleware, log_level, instance, action_factory, observation_factory)[source]¶
- class JobShopLabEnv[source]¶
Bases:
Env
JobShopLabEnv is an environment for job shop scheduling problems using the OpenAI Gym interface.
The environment simulates a job shop scheduling problem where jobs need to be processed on machines in a specific order. The goal is to minimize the makespan (total completion time) while respecting all constraints.
config (Config | None): Configuration object containing environment parameters. Defaults to None. seed (int | None): Random seed for reproducibility. Defaults to None. compiler (Compiler | None): Instance compiler to parse problem instances. Defaults to None. observation_factory (observations.ObservationFactory | None): ActionFactory for creating observations. Defaults to None. reward_factory (rewards.RewardFactory | None): ActionFactory for calculating rewards. Defaults to None. middleware (middleware_collection.Middleware | None): Middleware for state transitions. Defaults to None. action_factory (action_factory_collection.ActionFactory | None): ActionFactory for actions. Defaults to None. render_backend (Callable | None): Function for rendering the environment. Defaults to None. loglevel (int | str | None): Logging level. Defaults to None.
logger (Logger): Logger instance for the environment config (Config): Configuration object loglevel (int|str): Current logging level seed (int): Random seed used instance (InstanceConfig): Problem instance configuration lower_bound (int): Lower bound on makespan max_allowed_time (int): Maximum allowed timesteps num_operations (int): Total number of operations reward_factory (rewards.RewardFactory): ActionFactory for calculating rewards render_backend (Callable): Function for rendering state_simulator (middleware_collection.Middleware): Middleware for state transitions init_state (StateMachineResult): Initial state observation_space (gym.Space): Space of possible observations action_space (gym.Space): Space of possible actions state (StateMachineResult): Current state history (tuple[StateMachineResult]): History of states truncated (bool): Whether episode was truncated terminated (bool): Whether episode terminated naturally done (bool): Whether episode is done (terminated or truncated) current_observation (dict): Current observation
step(action): Takes an action and returns next observation, reward, done flags and info reset(seed): Resets environment to initial state with optional new seed render(): Renders current state of environment _is_done(): Checks if episode should terminate naturally _is_truncated(): Checks if episode should be truncated _get_info(): Returns info dict about current state _gen_render_metadata(): Generates metadata for rendering
observation (dict): Current observation of environment state reward (float): Reward from last action terminated (bool): Whether episode terminated naturally truncated (bool): Whether episode was truncated info (dict): Additional information about current state
-
__init__(config=
None
, seed=None
, compiler=None
, observation_factory=None
, reward_factory=None
, middleware=None
, action_factory=None
, render_backend=None
, loglevel=None
)[source]¶ Initialize JobShopLabEnv environment.
This class represents a Job Shop scheduling environment for reinforcement learning. It inherits from the base environment class and sets up the required components for simulation, observation generation, reward calculation and visualization.
- Parameters:¶
- config : Config, optional¶
Configuration object containing environment parameters. Defaults to None.
- seed : int, optional¶
Random seed for reproducibility. Defaults to None.
- compiler : Compiler, optional¶
Compiler instance for processing job shop problems. Defaults to None.
- observation_factory : ObservationFactory, optional¶
ActionFactory class for creating observations. Defaults to None.
- reward_factory : RewardFactory, optional¶
ActionFactory class for calculating rewards. Defaults to None.
- middleware : Middleware, optional¶
Middleware component for pre/post processing. Defaults to None.
- action_factory : ActionFactory, optional¶
ActionFactory component for action processing. Defaults to None.
- render_backend : Callable, optional¶
Backend function for visualization. Defaults to None.
- loglevel : int | str, optional¶
Logging level for the environment. Defaults to None.
- step(action)[source]¶
Take a step in the environment.
- Parameters:¶
- action¶
The action to take.
- Returns:¶
The observation after taking the action. reward: The reward after taking the action. terminated (bool): True if the episode is terminated, False otherwise. truncated (bool): True if the episode is truncated, False otherwise. info: Additional information.
- Return type:¶
observation
-
reset(seed=
None
)[source]¶ Reset the environment to its initial state.
This method initializes or reinitializes all the environment components including: - Configuration and logging setup - Instance compilation - Static instance-based values - Observation and reward factories - State machine and action_factory - Initial state and observation
-
__init__(config=