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, int]] = None, permutation: list[int] = 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[source]
get_start_time(task: int) int[source]
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: SchedulingProblem[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_makespan_upper_bound() int[source]

Get a upper bound on global makespan.

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.

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