discrete_optimization.singlemachine package

Subpackages

Submodules

discrete_optimization.singlemachine.parser module

discrete_optimization.singlemachine.parser.get_data_available(data_folder: str | None = None, data_home: str | None = None) → list[str][source]

Get datasets available for tsp.

Params:
data_folder: folder where datasets for weighted tardiness problem should be found.

If None, we look in “wt” subdirectory of data_home.

data_home: root directory for all datasets. Is None, set by

default to “~/discrete_optimization_data “

discrete_optimization.singlemachine.parser.parse_file(path: str, num_jobs: int = None)[source]
discrete_optimization.singlemachine.parser.parse_wt_content(file_content: str, num_jobs: int) → list[WeightedTardinessProblem][source]

Parses a weighted tardiness file with a known number of jobs per instance.

Parameters:
  • file_content (str) – The full content of the text file.

  • num_jobs (int) – The number of jobs per instance (e.g., 40 for wt40.txt).

Returns:

A list of parsed problem instances.

Return type:

List[WeightedTardinessProblem]

discrete_optimization.singlemachine.problem module

class discrete_optimization.singlemachine.problem.WTSolution(problem: WeightedTardinessProblem, schedule: list[tuple[int | AbsentValue.ABSENT, int | AbsentValue.ABSENT]] | None = None, permutation: list[int] | None = None)[source]

Bases: SchedulingSolution[int]

change_problem(new_problem: Problem) → 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

compute_schedule_from_permutation()[source]
copy() → Solution[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 the task

Hypothesis:

The returned time can have AbsentValue.ABSENT only if self.is_present(task) is False.

Parameters:

task

Returns:

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

Get start time of the task

Hypothesis:

The returned time can have AbsentValue.ABSENT only if self.is_present(task) is False.

Parameters:

task

Returns:

is_present(task: int) → bool[source]

Tell whether the task is present in the solution.

It can mean several thing: - scheduling problem: start and end of the task are defined - allocation problem: a ressource has been allocated to the task - multimode: a mode has been chosen for the task - or a mix of it

Sometimes a scheduling allocation problem will allow no resource allocation for present task, it has to be defined problem by problem.

For convenience, a default implementation is provided which assumes that all tasks are present. To be overriden in subclasses.

If and only if this method returns False, the mode, start, and end of the task can have the value AbsentValue.ABSENT.

If the method returns False, the task is removed from all constraints during checks.

lazy_copy() → Solution[source]

This function should return a new object but possibly with mutable attributes from the original objects.

A typical use of lazy copy is in evolutionary algorithms or genetic algorithm where the use of local move don’t need to do a possibly costly deepcopy.

Returns (Solution): copy (possibly shallow) of the Solution

problem: WeightedTardinessProblem
class discrete_optimization.singlemachine.problem.WeightedTardinessProblem(num_jobs: int, processing_times: List[int], weights: List[int], due_dates: List[int], release_dates: List[int] | None = None)[source]

Bases: GenericSchedulingProblem[int, None, None, NonSkillCumulativeResource, None, ExclusionResource], SinglemodeSchedulingProblem[int], WithoutPrecedenceProblem[int], WithoutSkillProblem[int, None, NonSkillCumulativeResource, None], WithoutCumulativeResourceProblem[int, NonSkillCumulativeResource], WithoutNonRenewableResourceProblem[int, None], WithoutAllocationProblem[int]

Represents a single instance of the single-machine weighted tardiness problem.

evaluate(variable: WTSolution) → dict[str, float][source]

Evaluate a given solution object for the given problem.

This method should return a dictionnary of KPI, that can be then used for mono or multiobjective optimization.

Parameters:

variable (Solution) – the Solution object to evaluate.

Returns: dictionnary of float kpi for the 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_dummy_solution() → WTSolution[source]

Create a trivial solution for the problem.

Should satisfy the problem ideally. Does not exist for all kind of problems.

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

Get an upper bound on global makespan.

get_no_overlap() → set[frozenset[int]][source]

An object in this returned set is a (frozen) set of task, where no task should overlap with another one in this set.

Default to no such sets.

get_objective_register() → ObjectiveRegister[source]

Returns the objective definition.

Returns (ObjectiveRegister): object defining the objective criteria.

get_resource_availabilities(resource: Resource) → list[tuple[int, int, int]][source]

Get availabilities intervals for a given resource

List of availability intervals of a resource. If the resource is not available, potentially no interval returned.

It is assumed that the intervals are disjunct though.

Parameters:

resource

Returns:

list of intervals of the form (start, end, value), which means from time start to time end, there are value of the resource available. NB: the start is included, the end is excluded (start <= t < end)

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) → int[source]

Get task duration.

Parameters:

task

Returns:

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

Get a lower bound on start or end of a given task as specified by the problem.

For tighter computed bounds, see GenericSchedulingProblem.get_tight_task_start_or_end_lower_bound() and GenericSchedulingProblem.compute_task_bounds().

Default implementation: 0

Parameters:
  • task

  • start_or_end

Returns:

is_optional(task: int) → bool[source]

Whether a task is optional or not.

It means that the task can be ignored in the solution. If absent of the solution, it can also be removed from the constraints.

Default to no optional task.

property non_skill_cumulative_resources_list: list[Resource]

List of cumulative resources that are not skills.

satisfy(variable: WTSolution) → bool[source]

Computes if a solution satisfies or not the constraints of the problem.

Parameters:

variable – the Solution object to check satisfability

Returns (bool): boolean true if the constraints are fulfilled, false elsewhere.

property tasks_list: list[int]

List of all tasks to schedule or allocate to.

Module contents