job_shop_lib.generation

Package for generating job shop instances.

InstanceGenerator

Common interface for all generators.

GeneralInstanceGenerator

Generates instances for job shop problems.

generate_duration_matrix

Generates a duration matrix.

generate_machine_matrix_with_recirculation

Generate a machine matrix with recirculation.

generate_machine_matrix_without_recirculation

Generate a machine matrix without recirculation.

class InstanceGenerator(num_jobs=(10, 20), num_machines=(5, 10), duration_range=(1, 99), name_suffix='generated_instance', seed=None, iteration_limit=None)[source]

Bases: ABC

Common interface for all generators.

The class supports both single instance generation and iteration over multiple instances, controlled by the iteration_limit parameter. It implements the iterator protocol, allowing it to be used in a for loop.

Note

When used as an iterator, the generator will produce instances until it reaches the specified iteration_limit. If iteration_limit is None, it will continue indefinitely.

num_jobs_range

The range of the number of jobs to generate. If a single int is provided, it is used as both the minimum and maximum.

duration_range

The range of durations for each operation.

num_machines_range

The range of the number of machines available. If a single int is provided, it is used as both the minimum and maximum.

name_suffix

A suffix to append to each instance's name for identification.

seed

Seed for the random number generator to ensure reproducibility.

Parameters:
  • num_jobs (int | tuple[int, int]) -- The range of the number of jobs to generate.

  • num_machines (int | tuple[int, int]) -- The range of the number of machines available.

  • duration_range (tuple[int, int]) -- The range of durations for each operation.

  • name_suffix (str) -- Suffix for instance names.

  • seed (int | None) -- Seed for the random number generator.

  • iteration_limit (int | None) -- Maximum number of instances to generate in iteration mode.

abstract generate(num_jobs=None, num_machines=None)[source]

Generates a single job shop instance

Parameters:
  • num_jobs (int | None) -- The number of jobs to generate. If None, a random value within the specified range will be used.

  • num_machines (int | None) -- The number of machines to generate. If None, a random value within the specified range will be used.

Return type:

JobShopInstance

property max_num_jobs: int

Returns the maximum number of jobs that can be generated.

property min_num_jobs: int

Returns the minimum number of jobs that can be generated.

property max_num_machines: int

Returns the maximum number of machines that can be generated.

property min_num_machines: int

Returns the minimum number of machines that can be generated.

class GeneralInstanceGenerator(num_jobs=(10, 20), num_machines=(5, 10), duration_range=(1, 99), allow_less_jobs_than_machines=True, allow_recirculation=False, machines_per_operation=1, name_suffix='classic_generated_instance', seed=None, iteration_limit=None)[source]

Bases: InstanceGenerator

Generates instances for job shop problems.

This class is designed to be versatile, enabling the creation of various job shop instances without the need for multiple dedicated classes.

It supports customization of the number of jobs, machines, operation durations, and more.

The class supports both single instance generation and iteration over multiple instances, controlled by the iteration_limit parameter. It implements the iterator protocol, allowing it to be used in a for loop.

The number of operations per machine is equal to the number of machines

Note

When used as an iterator, the generator will produce instances until it reaches the specified iteration_limit. If iteration_limit is None, it will continue indefinitely.

num_jobs_range

The range of the number of jobs to generate. If a single int is provided, it is used as both the minimum and maximum.

duration_range

The range of durations for each operation.

num_machines_range

The range of the number of machines available. If a single int is provided, it is used as both the minimum and maximum.

machines_per_operation

Specifies how many machines each operation can be assigned to. If a single int is provided, it is used for all operations.

allow_less_jobs_than_machines

If True, allows generating instances where the number of jobs is less than the number of machines.

allow_recirculation

If True, a job can visit the same machine more than once.

name_suffix

A suffix to append to each instance's name for identification.

seed

Seed for the random number generator to ensure reproducibility.

Parameters:
  • num_jobs (int | tuple[int, int]) -- The range of the number of jobs to generate.

  • num_machines (int | tuple[int, int]) -- The range of the number of machines available.

  • duration_range (tuple[int, int]) -- The range of durations for each operation.

  • allow_less_jobs_than_machines (bool) -- Allows instances with fewer jobs than machines.

  • allow_recirculation (bool) -- Allows jobs to visit the same machine multiple times.

  • machines_per_operation (int | tuple[int, int]) -- Specifies how many machines each operation can be assigned to. If a single int is provided, it is used for all operations.

  • name_suffix (str) -- Suffix for instance names.

  • seed (int | None) -- Seed for the random number generator.

  • iteration_limit (int | None) -- Maximum number of instances to generate in iteration mode.

generate(num_jobs=None, num_machines=None)[source]

Generates a single job shop instance

Parameters:
  • num_jobs (int | None) -- The number of jobs to generate. If None, a random value within the specified range will be used.

  • num_machines (int | None) -- The number of machines to generate. If None, a random value within the specified range will be used.

Return type:

JobShopInstance

generate_duration_matrix(num_jobs, num_machines, duration_range, rng=None)[source]

Generates a duration matrix.

Parameters:
  • num_jobs (int) -- The number of jobs.

  • num_machines (int) -- The number of machines.

  • duration_range (tuple[int, int]) -- The range of the duration values.

  • rng (Generator | None) -- A numpy random number generator.

Returns:

A duration matrix with shape (num_jobs, num_machines).

Return type:

ndarray[tuple[int, ...], dtype[int32]]

generate_machine_matrix_with_recirculation(num_jobs, num_machines, rng=None)[source]

Generate a machine matrix with recirculation.

Parameters:
  • num_jobs (int) -- The number of jobs.

  • num_machines (int) -- The number of machines.

  • rng (Generator | None) -- A numpy random number generator.

Returns:

A machine matrix with recirculation with shape (num_machines, num_jobs).

Return type:

ndarray[tuple[int, ...], dtype[int32]]

generate_machine_matrix_without_recirculation(num_jobs, num_machines, rng=None)[source]

Generate a machine matrix without recirculation.

Parameters:
  • num_jobs (int) -- The number of jobs.

  • num_machines (int) -- The number of machines.

  • rng (Generator | None) -- A numpy random number generator.

Returns:

A machine matrix without recirculation.

Return type:

ndarray[tuple[int, ...], dtype[int32]]