discrete_optimization.alb.salbp.solvers package
Submodules
discrete_optimization.alb.salbp.solvers.asp module
- class discrete_optimization.alb.salbp.solvers.asp.AspSalbpSolver(problem: SalbpProblem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
AspClingoSolver,WarmstartMixinSolver based on Answer Set Programming for the Simple Assembly Line Balancing Problem.
- build_heuristic_input(solution: SalbpSolution) str[source]
Builds clingo heuristics based on an existing solution.
- init_model(**kwargs: Any) None[source]
Initialize internal model used to solve.
Can initialize a ortools, milp, gurobi, … model.
- problem: SalbpProblem
- retrieve_solution(model: Model) SalbpSolution[source]
Parses the Clingo model to construct a SalbpSolution.
- set_warm_start(solution: SalbpSolution) None[source]
Re-initializes the control object with a solution hint.
- upper_bound: int
discrete_optimization.alb.salbp.solvers.cpsat module
- class discrete_optimization.alb.salbp.solvers.cpsat.CpSatSalbp12Solver(problem: SalbpProblem_1_2, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs)[source]
Bases:
AllocationCpSolver[int,int],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:
- get_task_unary_resource_is_present_variable(task: int, unary_resource: int) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]
Return a 0-1 variable/expression telling if the unary_resource is used for the task.
This variable should be 0 whenever an optional task is absent.
NB: sometimes the given resource is never to be used by a task and the variable has not been created. The convention is to return 0 in that case.
- hyperparameters: list[Hyperparameter] = [EnumHyperparameter(name='modeling', default=<ModelingCpSatSalbp.SCHEDULING: 0>, depends_on=None, name_in_kwargs='modeling')]
Hyperparameters available for this solver.
- These hyperparameters are to be feed to **kwargs found in
__init__()
init_model() (when available)
solve()
- problem: SalbpProblem_1_2
- 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: SalbpSolution) None[source]
Make the solver warm start from the given solution.
- class discrete_optimization.alb.salbp.solvers.cpsat.CpSatSalbpSolver(problem: SalbpProblem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs)[source]
Bases:
AllocationCpSolver[int,int],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:
- get_task_unary_resource_is_present_variable(task: int, unary_resource: int) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]
Return a 0-1 variable/expression telling if the unary_resource is used for the task.
This variable should be 0 whenever an optional task is absent.
NB: sometimes the given resource is never to be used by a task and the variable has not been created. The convention is to return 0 in that case.
- hyperparameters: list[Hyperparameter] = [EnumHyperparameter(name='modeling', default=<ModelingCpSatSalbp.SCHEDULING: 0>, depends_on=None, name_in_kwargs='modeling'), CategoricalHyperparameter(name='use_lb', default=True, depends_on=None, name_in_kwargs='use_lb')]
Hyperparameters available for this solver.
- These hyperparameters are to be feed to **kwargs found in
__init__()
init_model() (when available)
solve()
- modeling: ModelingCpSatSalbp
- problem: SalbpProblem
- 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: SalbpSolution) None[source]
Make the solver warm start from the given solution.
discrete_optimization.alb.salbp.solvers.dp module
- class discrete_optimization.alb.salbp.solvers.dp.DpSalbpSolver(problem: SalbpProblem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs)[source]
Bases:
DpSolver,WarmstartMixin- init_model(**kwargs)[source]
Model adapted from : https://github.com/domain-independent-dp/didp-rs/blob/main/didppy/examples/salbp-1.ipynb
- problem: SalbpProblem
- set_warm_start(solution: SalbpSolution) None[source]
Make the solver warm start from the given solution.
discrete_optimization.alb.salbp.solvers.greedy module
- class discrete_optimization.alb.salbp.solvers.greedy.GreedySalbpSolver(problem: SalbpProblem, params_objective_function: ParamsObjectiveFunction | None = None)[source]
Bases:
SolverDO- problem: SalbpProblem
- solve(callbacks: list[Callback] = None, **kwargs)[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.alb.salbp.solvers.optal module
- class discrete_optimization.alb.salbp.solvers.optal.OptalSalbp12Solver(problem: SalbpProblem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs)[source]
Bases:
SchedulingOptalSolver[int],WarmstartMixin- add_lexico_constraint(obj: str, value: float) Iterable[Any][source]
Add a constraint on a computed sub-objective
- Parameters:
obj – a string representing the desired objective. Should be one of self.get_lexico_objectives_available().
value – the limiting value. If the optimization direction is maximizing, this is a lower bound, else this is an upper bound.
- Returns:
the created constraints.
- get_lexico_objective_value(obj: str, res: ResultStorage) float[source]
Get best internal model objective value found by last call to solve().
The default implementation consists in using the fit of the last solution in result_storage. This assumes: - that the last solution is the best one for the objective considered - that no aggregation was performed but rather that the fitness is a TupleFitness
with values in the same order as self.problem.get_objective_names().
- Parameters:
obj – a string representing the desired objective. Should be one of self.get_lexico_objectives_available().
res – result storage returned by last call to solve().
Returns:
- get_lexico_objectives_available() list[str][source]
List objectives available for lexico optimization
It corresponds to the labels accepted for obj argument for - set_lexico_objective() - add_lexico_constraint() - get_lexico_objective_value()
Default to self.problem.get_objective_names().
Returns:
- 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.
- implements_lexico_api() bool[source]
Tell whether this solver is implementing the api for lexicographic optimization.
Should return True only if
set_lexico_objective()
add_lexico_constraint()
get_lexico_objective_value()
have been really implemented, i.e. - calling set_lexico_objective() and add_lexico_constraint()
should actually change the next call to solve(),
get_lexico_objective_value() should correspond to the internal model objective
- problem: SalbpProblem_1_2
- retrieve_solution(solution: cp.Solution) Solution[source]
Construct a d-o solution from OptalCP solver solution.
- Parameters:
solution – OptalCP solution
- Returns:
d-o solution
- set_lexico_objective(obj: str) None[source]
Update internal model objective.
- Parameters:
obj – a string representing the desired objective. Should be one of self.get_lexico_objectives_available().
Returns:
- set_warm_start(solution: SalbpSolution) None[source]
Make the solver warm start from the given solution.
- class discrete_optimization.alb.salbp.solvers.optal.OptalSalbpSolver(problem: SalbpProblem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs)[source]
Bases:
SchedulingOptalSolver[int],WarmstartMixin- 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.
- hyperparameters = [CategoricalHyperparameter(name='use_lb', default=True, depends_on=None, name_in_kwargs='use_lb')]
Hyperparameters available for this solver.
- These hyperparameters are to be feed to **kwargs found in
__init__()
init_model() (when available)
solve()
- problem: SalbpProblem
- retrieve_solution(solution: cp.Solution) Solution[source]
Construct a d-o solution from OptalCP solver solution.
- Parameters:
solution – OptalCP solution
- Returns:
d-o solution
- set_warm_start(solution: SalbpSolution) None[source]
Make the solver warm start from the given solution.