discrete_optimization.singlemachine.solvers package
Submodules
discrete_optimization.singlemachine.solvers.cpmpy_solver module
- class discrete_optimization.singlemachine.solvers.cpmpy_solver.CpmpySingleMachineSolver(problem: WeightedTardinessProblem, **kwargs: Any)[source]
Bases:
CpmpySolverCPMPy-based solver for the Single Machine Weighted Tardiness Problem.
This solver can use two different formulations: - CP (Constraint Programming): A model based on temporal variables and disjunctive constraints. It’s generally more efficient for scheduling problems. - LP (Mixed-Integer Linear Programming): A model based on relative ordering variables and “big-M” constraints.
- get_hard_meta_constraints() List[MetaCpmpyConstraint][source]
Returns the list of hard meta-constraints. These constraints define the core logic of the problem and should not be relaxed.
- get_soft_meta_constraints() List[MetaCpmpyConstraint][source]
Returns the list of soft meta-constraints for explanation purposes. These are constraints that can potentially be relaxed if the model is UNSAT.
- init_model(model_type: SingleMachineModel = SingleMachineModel.CP, add_impossible_constraints: bool = False, **kwargs: Any) None[source]
Builds the CPMpy model based on the chosen formalism (CP or LP). It defines variables, constraints, meta-constraints, and the objective function.
discrete_optimization.singlemachine.solvers.cpsat module
- class discrete_optimization.singlemachine.solvers.cpsat.CpSatWTSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
SchedulingCpSolver[int],TasksCpSatSolver[int],WarmstartMixin- get_task_start_or_end_variable(task: int, start_or_end: StartOrEnd) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]
Retrieve the variable storing the start or end time of given task.
For optional tasks, the start and end should be 0/False when absent so that the makespan/sum of starts/sum of ends variables do not take them into account.
- Parameters:
task
start_or_end
Returns:
- problem: WeightedTardinessProblem
- retrieve_solution(cpsolvercb: CpSolverSolutionCallback) Solution[source]
Construct a do solution from the cpsat solver internal solution.
It will be called each time the cpsat solver find a new solution. At that point, value of internal variables are accessible via cpsolvercb.Value(VARIABLE_NAME).
- Parameters:
cpsolvercb – the ortools callback called when the cpsat solver finds a new solution.
- Returns:
the intermediate solution, at do format.
- set_warm_start(solution: WTSolution) None[source]
Make the solver warm start from the given solution.
- variables: dict
discrete_optimization.singlemachine.solvers.cpsat_auto module
- class discrete_optimization.singlemachine.solvers.cpsat_auto.CpSatAutoWTSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
GenericSchedulingAutoCpSatSolver[int,None,None,NonSkillCumulativeResource,None,None]- convert_task_variables_to_solution(raw_sol: RawSolution[int, None, None]) GenericSchedulingSolution[int, None, None, NonSkillCumulativeResource, None, None][source]
Convert solution from autosolver format into do format.
To be used in self.retrieve_solution().
- Parameters:
raw_sol
Returns:
discrete_optimization.singlemachine.solvers.dp module
- class discrete_optimization.singlemachine.solvers.dp.DpWTSolver(problem: WeightedTardinessProblem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
DpSolver,WarmstartMixin- hyperparameters: list[Hyperparameter] = [CategoricalHyperparameter(name='add_dominated_transition', default=False, depends_on=None, name_in_kwargs='add_dominated_transition')]
Hyperparameters available for this solver.
- These hyperparameters are to be feed to **kwargs found in
__init__()
init_model() (when available)
solve()
- init_model(**kwargs: Any) None[source]
Initialize internal model used to solve.
Can initialize a ortools, milp, gurobi, … model.
- problem: WeightedTardinessProblem
- set_warm_start(solution: WTSolution) None[source]
Make the solver warm start from the given solution.
discrete_optimization.singlemachine.solvers.greedy module
- class discrete_optimization.singlemachine.solvers.greedy.GreedySingleMachineSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
SolverDOGreedy solver inserting jobs only using their initial index.
- problem: WeightedTardinessProblem
- solve(callbacks: list[Callback] | None = None, **kwargs: Any) ResultStorage[source]
Generic solving function.
- Parameters:
callbacks – list of callbacks used to hook into the various stage of the solve
**kwargs – any argument specific to the solver
Solvers deriving from SolverDo should use callbacks methods .on_step_end(), … during solve(). But some solvers are not yet updated and are just ignoring it.
Returns (ResultStorage): a result object containing potentially a pool of solutions to a discrete-optimization problem
- class discrete_optimization.singlemachine.solvers.greedy.GreedySingleMachineWSPT(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
SolverDOGreedy solver for the Single Machine Weighted Tardiness problem based on the Weighted Shortest Processing Time (WSPT) heuristic.
It sorts jobs in increasing order of (processing_time / weight).
- problem: WeightedTardinessProblem
- solve(callbacks: list[Callback] | None = None, **kwargs: Any) ResultStorage[source]
Generic solving function.
- Parameters:
callbacks – list of callbacks used to hook into the various stage of the solve
**kwargs – any argument specific to the solver
Solvers deriving from SolverDo should use callbacks methods .on_step_end(), … during solve(). But some solvers are not yet updated and are just ignoring it.
Returns (ResultStorage): a result object containing potentially a pool of solutions to a discrete-optimization problem
discrete_optimization.singlemachine.solvers.lp module
- class discrete_optimization.singlemachine.solvers.lp.GurobiSingleMachineSolver(problem: WeightedTardinessProblem, **kwargs: Any)[source]
Bases:
_BaseLpSingleMachineSolver,GurobiMilpSolver- convert_to_variable_values(solution: Solution) dict[gurobipy.Var, float][source]
Convert a solution to a mapping between model variables and their values.
Will be used by set_warm_start().
Override it in subclasses to have a proper warm start. You can also override set_warm_start() if default behaviour is not sufficient.
- class discrete_optimization.singlemachine.solvers.lp.MathOptSingleMachineSolver(problem: WeightedTardinessProblem, **kwargs: Any)[source]
Bases:
_BaseLpSingleMachineSolver,OrtoolsMathOptMilpSolver- convert_to_variable_values(solution: Solution) dict[Variable, float][source]
Convert a solution to a mapping between model variables and their values.
Will be used by set_warm_start() to provide a suitable SolutionHint.variable_values. See https://or-tools.github.io/docs/pdoc/ortools/math_opt/python/model_parameters.html#SolutionHint for more information.
Implement it in subclasses to have a proper warm start.
discrete_optimization.singlemachine.solvers.optal module
- class discrete_optimization.singlemachine.solvers.optal.OptalSingleMachineSolver(problem: WeightedTardinessProblem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
SchedulingOptalSolver[int]- get_task_interval(task: Task) cp.IntervalVar[source]
Return interval variable for the task.
This variable corresponds to the task schedule, whatever the mode. This is the main optal variable (start, end and duration are derived from it)
If the task is optional, this interval should be also taken into account the presence/absence of the task.
- problem: WeightedTardinessProblem
- retrieve_solution(solution: cp.Solution) WTSolution[source]
Construct a d-o solution from OptalCP solver solution.
- Parameters:
solution – OptalCP solution
- Returns:
d-o solution