discrete_optimization.salbp.solvers package

Submodules

discrete_optimization.salbp.solvers.asp module

class discrete_optimization.salbp.solvers.asp.AspSalbpSolver(problem: SalbpProblem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: AspClingoSolver, WarmstartMixin

Solver 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.

build_string_data_input() str[source]

Converts SalbpProblem instance data into ASP facts.

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.salbp.solvers.cpsat module

class discrete_optimization.salbp.solvers.cpsat.CpSatSalbp12Solver(problem: SalbpProblem_1_2, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs)[source]

Bases: AllocationCpSatSolver[int, int], SchedulingCpSatSolver[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.

Parameters:
  • task

  • start_or_end

Returns:

get_task_unary_resource_is_present_variable(task: int, unary_resource: UnaryResource) 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.

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()

init_model(**kwargs: Any) None[source]

Init cp model and reset stored variables if any.

init_model_binary(**kwargs: Any) None[source]
init_model_scheduling(**kwargs: Any) None[source]
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.salbp.solvers.cpsat.CpSatSalbpSolver(problem: SalbpProblem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs)[source]

Bases: AllocationCpSatSolver[int, int], SchedulingCpSatSolver[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.

Parameters:
  • task

  • start_or_end

Returns:

get_task_unary_resource_is_present_variable(task: int, unary_resource: UnaryResource) 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.

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()

init_model(**kwargs: Any) None[source]

Init cp model and reset stored variables if any.

init_model_binary(**kwargs: Any) None[source]
init_model_scheduling(**kwargs: Any) None[source]
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.

class discrete_optimization.salbp.solvers.cpsat.ModelingCpsatSalbp(*values)[source]

Bases: Enum

BINARY = 1
SCHEDULING = 0

discrete_optimization.salbp.solvers.dp module

class discrete_optimization.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
retrieve_solution(sol: Solution) Solution[source]
set_warm_start(solution: SalbpSolution) None[source]

Make the solver warm start from the given solution.

discrete_optimization.salbp.solvers.greedy module

class discrete_optimization.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.salbp.solvers.optal module

class discrete_optimization.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_variable(task: int) cp.IntervalVar[source]

Retrieve the interval variable of given 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

init_model(**kwargs: Any) None[source]

Instantiate a CP model instance

Afterwards, self.instance should not be None anymore.

init_model_scheduling(**kwargs: Any) None[source]
problem: SalbpProblem_1_2
retrieve_solution(result: cp.SolveResult) Solution[source]

Return a d-o solution from the variables computed by minizinc.

Parameters:

result – output of the cp.solve

Returns:

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.salbp.solvers.optal.OptalSalbpSolver(problem: SalbpProblem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs)[source]

Bases: SchedulingOptalSolver[int], WarmstartMixin

get_task_interval_variable(task: int) cp.IntervalVar[source]

Retrieve the interval variable of given 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()

init_model(**kwargs: Any) None[source]

Instantiate a CP model instance

Afterwards, self.instance should not be None anymore.

init_model_scheduling(**kwargs: Any) None[source]
problem: SalbpProblem
retrieve_solution(result: cp.SolveResult) Solution[source]

Return a d-o solution from the variables computed by minizinc.

Parameters:

result – output of the cp.solve

Returns:

set_warm_start(solution: SalbpSolution) None[source]

Make the solver warm start from the given solution.

Module contents