discrete_optimization.singlebatch package

Subpackages

Submodules

discrete_optimization.singlebatch.problem module

class discrete_optimization.singlebatch.problem.BatchProcessingSolution(problem: SingleBatchProcessingProblem, job_to_batch: list[int], schedule_batch: list[tuple[int, int]] = None)[source]

Bases: GenericSchedulingSolution[int, None, None, str, str, None], WithoutSkillSolution[int, None, str, None], WithoutAllocationSolution[int], SinglemodeSolution[int], BatchingSolution[int]

A solution mapping jobs to distinct batches.

change_problem(new_problem: SingleBatchProcessingProblem) → None[source]

If relevant to the optimisation problem, change the underlying problem instance for the solution.

This method can be used to evaluate a solution for different instance of problems. It should be implemented in child classes when caching subresults depending on the problem.

Parameters:

new_problem (Problem) – another problem instance from which the solution can be evaluated

Returns: None

copy() → BatchProcessingSolution[source]

Deep copy of the solution.

The copy() function should return a new object containing the same input as the current object, that respects the following expected behaviour: -y = x.copy() -if do some inplace change of y, the changes are not done in x.

Returns: a new object from which you can manipulate attributes without changing the original object.

get_end_time(task: int) → int | AbsentValue[source]

Get end time of a task (job).

get_start_time(task: int) → int | AbsentValue[source]

Get start time of a task (job).

get_task_batch_assignment(task: int) → Hashable | None[source]

Get which batch a task is assigned to.

is_present(task: int) → bool[source]

All tasks are present (not optional).

problem: SingleBatchProcessingProblem
class discrete_optimization.singlebatch.problem.Job(job_id: int, processing_time: int, size: int)[source]

Bases: object

Representation of a single job to be batched.

class discrete_optimization.singlebatch.problem.SingleBatchProcessingProblem(jobs: list[Job], capacity: int, max_batches: int | None = None)[source]

Bases: GenericSchedulingProblem[int, None, None, str, str, None], WithoutSkillProblem[int, None, str, None], SinglemodeProblem[int], WithoutCalendarResourceProblem[int], WithoutCumulativeResourceProblem[int, None], WithoutNonRenewableResourceProblem[int, None], WithoutAllocationProblem[int], WithoutPrecedenceProblem[int], BatchingProblem[int]

The Single Batch-Processing Machine Scheduling Problem.

Jobs must be grouped into batches that execute sequentially. Each batch: - Has a capacity constraint (sum of job sizes <= capacity) - Executes for duration = max(processing_times of jobs in batch) - Batches execute in sequence (batch[i] finishes before batch[i+1] starts)

build_schedule_batch(variable: BatchProcessingSolution) → list[tuple[int, int]][source]
can_be_batched(task: int) → bool[source]

All jobs can be batched.

compute_batches_violation(variable: BatchProcessingSolution) → int[source]

Returns sum of all batch processing violations.

compute_processing_time_batch(variable: BatchProcessingSolution) → dict[int, int][source]
evaluate(variable: BatchProcessingSolution) → dict[str, float][source]

Calculate the Makespan (Cmax) of the current batching solution.

get_attribute_register() → EncodingRegister[source]

Returns how the Solution should be encoded.

Useful to find automatically available mutations for local search. Used by genetic algorithms Ga and Nsga.

This needs only to be implemented in child classes when GA or LS solvers are to be used.

Returns (EncodingRegister): content of the encoding of the solution

get_batch_capacity(batch_id: int) → int[source]

Return capacity of a batch.

get_batch_duration_bounds(batch_id: int, tasks: frozenset[int]) → tuple[int | None, int | None][source]

Batch duration is max of job processing times.

get_batch_entities() → list[VariableBatchEntity[int]][source]

Return all batch entities.

get_batch_presence_chains() → list[list[int]][source]

Enforce presence ordering: if batch[i+1] is used, batch[i] must be used.

This is a symmetry-breaking constraint for single-machine batching.

get_candidate_tasks_for_batch(batch_id: int) → frozenset[int][source]

All jobs can go into any batch.

get_dummy_solution() → BatchProcessingSolution[source]

Create a trivial valid solution (one job per batch).

get_entity_precedence_constraints()[source]

Enforce temporal precedence: batch[i] must finish before batch[i+1] starts.

get_list_objective_computer() → list[ObjectiveComputer][source]
get_makespan_upper_bound() → int[source]

Upper bound on makespan (all jobs run sequentially).

get_objective_register() → ObjectiveRegister[source]

Returns the objective definition.

Returns (ObjectiveRegister): object defining the objective criteria.

get_solution_type() → type[Solution][source]

Returns the class implementation of a Solution.

Returns (class): class object of the given Problem.

get_task_duration(task: int, mode: int = 1) → int[source]

Return processing time of a job.

get_task_mode_duration(task: int, mode: int) → int[source]

Get task duration according to mode.

Parameters:
  • task

  • mode – not used for single-mode problems

Returns:

get_task_size(task: int) → int[source]

Return size of a job (for capacity constraint).

get_task_start_or_end_lower_bound(task: int, start_or_end: StartOrEnd) → int[source]

Lower bound on task start/end time.

get_task_start_or_end_upper_bound(task: int, start_or_end: StartOrEnd) → int[source]

Upper bound on task start/end time.

is_batch_optional(batch_id: int) → bool[source]

Batches can be empty (unused).

is_optional(task: int) → bool[source]

All jobs must be scheduled.

must_be_batched(task: int) → bool[source]

All jobs must be assigned to a batch.

property non_skill_cumulative_resources_list: list[Skill]

List of cumulative resources that are not skills.

satisfy(variable: BatchProcessingSolution) → bool[source]

Check if all capacity constraints are respected.

property tasks_list: list[int]

Return list of all tasks (jobs).

discrete_optimization.singlebatch.utils module

class discrete_optimization.singlebatch.utils.GenerationMode(*values)[source]

Bases: Enum

Modes for generating job sizes and processing times.

NEGATIVE_CORRELATION = 'negative'
POSITIVE_CORRELATION = 'positive'
RANDOM = 'random'
discrete_optimization.singlebatch.utils.generate_random_batch_problem(nb_jobs: int = 50, capacity: int = 100, size_range: Tuple[int, int] = (10, 50), duration_range: Tuple[int, int] = (5, 100), mode: GenerationMode = GenerationMode.RANDOM, noise_level: float = 0.2, seed: int = 42) → SingleBatchProcessingProblem[source]

Generates a SingleBatchProcessingProblem instance.

Parameters:
  • nb_jobs – Number of jobs to generate.

  • capacity – Maximum capacity of the batch processing machine.

  • size_range – Tuple (min_size, max_size) for jobs.

  • duration_range – Tuple (min_duration, max_duration) for jobs.

  • mode – GenerationMode defining the correlation between size and duration.

  • noise_level – Float between 0 and 1 defining how much randomness to add to correlated modes.

  • seed – Random seed for reproducibility.

Returns:

A populated SingleBatchProcessingProblem.

Module contents