discrete_optimization.alb.rcalbp_l.solvers package

Submodules

discrete_optimization.alb.rcalbp_l.solvers.cpsat module

class discrete_optimization.alb.rcalbp_l.solvers.cpsat.CpSatRCALBPLSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: AllocationCpSolver[Tuple[int, int], int], SchedulingCpSolver[Tuple[int, int]], TasksCpSatSolver[Tuple[int, int]], WarmstartMixin

add_cycle_time_lower_bound(p: int, lower_bound: int)[source]

Ensures cycle time monotonicity across independent chunk boundaries.

constraint_only_one_station_allocation()[source]
create_cumulative_resource_constraint()[source]
create_cycle_time_variables()[source]
create_heuristic_target_reached_constraints(apply_heuristic: bool = True)[source]
create_main_unfolded_intervals()[source]
create_precedence_constraints()[source]
create_resource_dispatch()[source]
create_zone_blocking()[source]

Be careful on the fact that this constraint only is valid with capa==1 for now

fix_allocations(wks: dict)[source]

Hard-fixes the allocation variables to a known configuration. This transforms the complex ALBP problem into a scheduling problem.

fix_allocations_and_resources(wks: dict, raw: dict)[source]

Hard-fixes the allocation and resource variables to a known configuration. This transforms the complex ALBP problem into a purely independent scheduling problem.

get_task_start_or_end_variable(task: Task, start_or_end: StartOrEnd) → LinearExprT[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: Task, unary_resource: WorkStation) → cp.BoolExpr[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.

init_model(minimize_used_cycle_time: bool = False, add_heuristic_constraint: bool = True, **kwargs: Any) → None[source]

Init cp model and reset stored variables if any.

objective_value(minimize_used_cycle_time: bool = False)[source]
problem: RCALBPLProblem
retrieve_solution(cpsolvercb: CpSolverSolutionCallback) → RCALBPLSolution[source]

Parses the CP-SAT result back into a native RCALBPLSolution.

set_warm_start(solution: RCALBPLSolution) → None[source]

Injects an almost complete model state as a hint to the CP-SAT solver.

property subset_tasks_of_interest: Iterable[Tuple[int, int]]

Subset of tasks of interest for the allocation…

variables: dict

discrete_optimization.alb.rcalbp_l.solvers.meta_solvers module

class discrete_optimization.alb.rcalbp_l.solvers.meta_solvers.BackwardSequentialRCALBPLSolver(problem: RCALBPLProblem, future_chunk_size: int = 5, phase2_chunk_size: int = 10, time_limit_phase1: int = 120, time_limit_phase2: int = 30, use_sgs_warm_start: bool = True, **kwargs: Any)[source]

Bases: SolverDO

Independent Chunk Backward Reasoning Solver with SGS Warm-Starting.

problem: RCALBPLProblem
solve(**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.alb.rcalbp_l.solvers.meta_solvers.BackwardSequentialRCALBPLSolverSGS(problem: RCALBPLProblem, future_chunk_size: int = 5, phase2_chunk_size: int = 10, time_limit_phase1: int = 120, time_limit_phase2: int = 30, use_sgs_warm_start: bool = True, **kwargs: Any)[source]

Bases: BackwardSequentialRCALBPLSolver

Independent Chunk Backward Reasoning Solver with SGS Warm-Starting.

problem: RCALBPLProblem
class discrete_optimization.alb.rcalbp_l.solvers.meta_solvers.BalancedBackwardSequentialRCALBPLSolver(problem: RCALBPLProblem, future_chunk_size: int = 5, phase2_chunk_size: int = 10, time_limit_phase1: int = 120, time_limit_phase2: int = 30, use_sgs_warm_start: bool = True, **kwargs: Any)[source]

Bases: BackwardSequentialRCALBPLSolver

Upgraded Backward Solver using the ‘Two-Period Extremes’ heuristic. Phase 1 isolates ONLY the first unstable period and the final steady-state period.

solve(**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.alb.rcalbp_l.solvers.optal module

class discrete_optimization.alb.rcalbp_l.solvers.optal.OptalRCALBPLSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: AllocationCpSolver[Tuple[int, int], int], SchedulingOptalSolver[Tuple[int, int]]

constraint_only_one_station_allocation()[source]
create_cumulative_resource_constraint()[source]
create_cycle_time_variables()[source]
create_heuristic_target_reached_constraints(apply_heuristic: bool = True)[source]
create_main_unfolded_intervals()[source]
create_precedence_constraints()[source]
create_resource_dispatch()[source]
create_zone_blocking()[source]
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.

get_task_unary_resource_is_present_variable(task: Task, unary_resource: WorkStation) → cp.BoolExpr[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.

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

Init cp model and reset stored variables if any.

objective_value()[source]
problem: RCALBPLProblem
retrieve_solution(solution: cp.Solution) → RCALBPLSolution[source]

Parses the OptalCP result back into a native RCALBPLSolution, translating absolute unfolded times back to relative workstation times.

variables: dict
class discrete_optimization.alb.rcalbp_l.solvers.optal.OptalRCALBPLSolverV2(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: AllocationCpSolver[Tuple[int, int], int], SchedulingOptalSolver[Tuple[int, int]]

create_cumulative_resource_constraint()[source]
create_cycle_time_variables()[source]
create_heuristic_target_reached_constraints(apply_heuristic: bool = True)[source]
create_main_unfolded_intervals()[source]
create_precedence_constraints()[source]
create_resource_dispatch()[source]
create_zone_blocking()[source]
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.

get_task_unary_resource_is_present_variable(task: Task, unary_resource: WorkStation) → cp.BoolExpr[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.

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

Init cp model and reset stored variables if any.

objective_value()[source]
problem: RCALBPLProblem
retrieve_solution(solution: cp.Solution) → RCALBPLSolution[source]

Parses the OptalCP result back into a native RCALBPLSolution, translating absolute unfolded times back to relative workstation times.

variables: dict

discrete_optimization.alb.rcalbp_l.solvers.pareto_postprocess module

class discrete_optimization.alb.rcalbp_l.solvers.pareto_postprocess.DpRCALBPLPostProSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: DpSolver

init_model(from_solution: RCALBPLSolution, max_nb_adjustments: int = None, **kwargs: Any) → None[source]

Initialize internal model used to solve.

Can initialize a ortools, milp, gurobi, … model.

problem: RCALBPLProblem
retrieve_solution(sol: Solution) → RCALBPLSolution[source]
solution: RCALBPLSolution
class discrete_optimization.alb.rcalbp_l.solvers.pareto_postprocess.RampUpParetoSolverPostpro(problem: RCALBPLProblem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs)[source]

Bases: OrtoolsCpSatSolver

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:

static 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(from_solution: RCALBPLSolution, **kwargs: Any) → None[source]

Init cp model and reset stored variables if any.

problem: RCALBPLProblem
retrieve_solution(cpsolvercb: CpSolverSolutionCallback) → RCALBPLSolution[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_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:

solution: RCALBPLSolution

Module contents

class discrete_optimization.alb.rcalbp_l.solvers.BackwardSequentialRCALBPLSolver(problem: RCALBPLProblem, future_chunk_size: int = 5, phase2_chunk_size: int = 10, time_limit_phase1: int = 120, time_limit_phase2: int = 30, use_sgs_warm_start: bool = True, **kwargs: Any)[source]

Bases: SolverDO

Independent Chunk Backward Reasoning Solver with SGS Warm-Starting.

problem: RCALBPLProblem
solve(**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.alb.rcalbp_l.solvers.BackwardSequentialRCALBPLSolverSGS(problem: RCALBPLProblem, future_chunk_size: int = 5, phase2_chunk_size: int = 10, time_limit_phase1: int = 120, time_limit_phase2: int = 30, use_sgs_warm_start: bool = True, **kwargs: Any)[source]

Bases: BackwardSequentialRCALBPLSolver

Independent Chunk Backward Reasoning Solver with SGS Warm-Starting.

problem: RCALBPLProblem
class discrete_optimization.alb.rcalbp_l.solvers.BalancedBackwardSequentialRCALBPLSolver(problem: RCALBPLProblem, future_chunk_size: int = 5, phase2_chunk_size: int = 10, time_limit_phase1: int = 120, time_limit_phase2: int = 30, use_sgs_warm_start: bool = True, **kwargs: Any)[source]

Bases: BackwardSequentialRCALBPLSolver

Upgraded Backward Solver using the ‘Two-Period Extremes’ heuristic. Phase 1 isolates ONLY the first unstable period and the final steady-state period.

solve(**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.alb.rcalbp_l.solvers.CpSatRCALBPLSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: AllocationCpSolver[Tuple[int, int], int], SchedulingCpSolver[Tuple[int, int]], TasksCpSatSolver[Tuple[int, int]], WarmstartMixin

add_cycle_time_lower_bound(p: int, lower_bound: int)[source]

Ensures cycle time monotonicity across independent chunk boundaries.

constraint_only_one_station_allocation()[source]
create_cumulative_resource_constraint()[source]
create_cycle_time_variables()[source]
create_heuristic_target_reached_constraints(apply_heuristic: bool = True)[source]
create_main_unfolded_intervals()[source]
create_precedence_constraints()[source]
create_resource_dispatch()[source]
create_zone_blocking()[source]

Be careful on the fact that this constraint only is valid with capa==1 for now

fix_allocations(wks: dict)[source]

Hard-fixes the allocation variables to a known configuration. This transforms the complex ALBP problem into a scheduling problem.

fix_allocations_and_resources(wks: dict, raw: dict)[source]

Hard-fixes the allocation and resource variables to a known configuration. This transforms the complex ALBP problem into a purely independent scheduling problem.

get_task_start_or_end_variable(task: Task, start_or_end: StartOrEnd) → LinearExprT[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: Task, unary_resource: WorkStation) → cp.BoolExpr[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.

init_model(minimize_used_cycle_time: bool = False, add_heuristic_constraint: bool = True, **kwargs: Any) → None[source]

Init cp model and reset stored variables if any.

objective_value(minimize_used_cycle_time: bool = False)[source]
problem: RCALBPLProblem
retrieve_solution(cpsolvercb: CpSolverSolutionCallback) → RCALBPLSolution[source]

Parses the CP-SAT result back into a native RCALBPLSolution.

set_warm_start(solution: RCALBPLSolution) → None[source]

Injects an almost complete model state as a hint to the CP-SAT solver.

property subset_tasks_of_interest: Iterable[Tuple[int, int]]

Subset of tasks of interest for the allocation…

variables: dict
class discrete_optimization.alb.rcalbp_l.solvers.OptalRCALBPLSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: AllocationCpSolver[Tuple[int, int], int], SchedulingOptalSolver[Tuple[int, int]]

constraint_only_one_station_allocation()[source]
create_cumulative_resource_constraint()[source]
create_cycle_time_variables()[source]
create_heuristic_target_reached_constraints(apply_heuristic: bool = True)[source]
create_main_unfolded_intervals()[source]
create_precedence_constraints()[source]
create_resource_dispatch()[source]
create_zone_blocking()[source]
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.

get_task_unary_resource_is_present_variable(task: Task, unary_resource: WorkStation) → cp.BoolExpr[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.

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

Init cp model and reset stored variables if any.

objective_value()[source]
problem: RCALBPLProblem
retrieve_solution(solution: cp.Solution) → RCALBPLSolution[source]

Parses the OptalCP result back into a native RCALBPLSolution, translating absolute unfolded times back to relative workstation times.

variables: dict
class discrete_optimization.alb.rcalbp_l.solvers.OptalRCALBPLSolverV2(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: AllocationCpSolver[Tuple[int, int], int], SchedulingOptalSolver[Tuple[int, int]]

create_cumulative_resource_constraint()[source]
create_cycle_time_variables()[source]
create_heuristic_target_reached_constraints(apply_heuristic: bool = True)[source]
create_main_unfolded_intervals()[source]
create_precedence_constraints()[source]
create_resource_dispatch()[source]
create_zone_blocking()[source]
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.

get_task_unary_resource_is_present_variable(task: Task, unary_resource: WorkStation) → cp.BoolExpr[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.

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

Init cp model and reset stored variables if any.

objective_value()[source]
problem: RCALBPLProblem
retrieve_solution(solution: cp.Solution) → RCALBPLSolution[source]

Parses the OptalCP result back into a native RCALBPLSolution, translating absolute unfolded times back to relative workstation times.

variables: dict