discrete_optimization.rcpsp_multiskill.solvers package
Submodules
discrete_optimization.rcpsp_multiskill.solvers.cp_mspsp_instlib module
- class discrete_optimization.rcpsp_multiskill.solvers.cp_mspsp_instlib.CpMspspMznMultiskillRcpspSolver(problem: MultiskillRcpspProblem, cp_solver_name: CpSolverName = CpSolverName.CHUFFED, params_objective_function: ParamsObjectiveFunction | None = None, silent_solve_error: bool = False, **kwargs)[source]
Bases:
MinizincCpSolver
- init_model(**args)[source]
Instantiate a CP model instance
Afterwards, self.instance should not be None anymore.
- problem: MultiskillRcpspProblem
- retrieve_solution(_output_item: str | None = None, **kwargs: Any) MultiskillRcpspSolution [source]
Return a d-o solution from the variables computed by minizinc.
- Parameters:
_output_item – string representing the minizinc solver output passed by minizinc to the solution constructor
**kwargs – keyword arguments passed by minzinc to the solution contructor containing the objective value (key “objective”), and the computed variables as defined in minizinc model.
Returns:
- discrete_optimization.rcpsp_multiskill.solvers.cp_mspsp_instlib.create_usefull_res_data(rcpsp_problem: MultiskillRcpspProblem)[source]
discrete_optimization.rcpsp_multiskill.solvers.cp_mzn module
- class discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.CpMultiskillRcpspSolver(problem: MultiskillRcpspProblem, cp_solver_name: CpSolverName = CpSolverName.CHUFFED, params_objective_function: ParamsObjectiveFunction | None = None, silent_solve_error: bool = False, **kwargs)[source]
Bases:
MinizincCpSolver
- init_model(**args)[source]
Instantiate a CP model instance
Afterwards, self.instance should not be None anymore.
- problem: MultiskillRcpspProblem
- retrieve_solution(_output_item: str | None = None, **kwargs: Any) MultiskillRcpspSolution [source]
Return a d-o solution from the variables computed by minizinc.
- Parameters:
_output_item – string representing the minizinc solver output passed by minizinc to the solution constructor
**kwargs – keyword arguments passed by minzinc to the solution contructor containing the objective value (key “objective”), and the computed variables as defined in minizinc model.
Returns:
- class discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.CpPartialPreemptiveMultiskillRcpspSolver(problem: MultiskillRcpspProblem, cp_solver_name: CpSolverName = CpSolverName.CHUFFED, params_objective_function: ParamsObjectiveFunction | None = None, silent_solve_error: bool = False, **kwargs)[source]
- class discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.CpPreemptiveMultiskillRcpspSolver(problem: MultiskillRcpspProblem, cp_solver_name: CpSolverName = CpSolverName.CHUFFED, params_objective_function: ParamsObjectiveFunction | None = None, silent_solve_error: bool = False, **kwargs)[source]
Bases:
MinizincCpSolver
- constraint_duration_string_preemptive_i(task, duration, part_id=1, sign: SignEnum = SignEnum.EQUAL) str [source]
- constraint_start_time_string_preemptive_i(task, start_time, part_id=1, sign: SignEnum = SignEnum.EQUAL) str [source]
- init_model(**args)[source]
Instantiate a CP model instance
Afterwards, self.instance should not be None anymore.
- problem: MultiskillRcpspProblem
- retrieve_solution(_output_item: str | None = None, **kwargs: Any) PreemptiveMultiskillRcpspSolution [source]
Return a d-o solution from the variables computed by minizinc.
- Parameters:
_output_item – string representing the minizinc solver output passed by minizinc to the solution constructor
**kwargs – keyword arguments passed by minzinc to the solution contructor containing the objective value (key “objective”), and the computed variables as defined in minizinc model.
Returns:
- class discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.PrecomputeEmployeesForTasks(ms_rcpsp_problem: MultiskillRcpspProblem, cp_solver_name: CpSolverName = CpSolverName.CHUFFED)[source]
Bases:
object
- retrieve_solutions(result, parameters_cp: ParametersCp)[source]
- solve(parameters_cp: ParametersCp | None = None, time_limit: float | None = 100.0, nr_solutions: int = 100, all_solutions: bool = False, **args)[source]
Solve the CP problem with minizinc
- Parameters:
parameters_cp – parameters specific to CP solvers
time_limit – the solve process stops after this time limit (in seconds). If None, no time limit is applied.
nr_solutions – of not all_solutions, the solve stops after finding nr_solutions
all_solutions – if True, do not stop when reaching nr_solutions
**args – passed to init_model()
Returns:
- class discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.SearchStrategyMultiskillRcpsp(value)[source]
Bases:
Enum
An enumeration.
- NONE = 'none'
- PRIORITY_SEARCH_START_UNIT_USED = 'priority_smallest'
- START_THEN_USED_UNIT = 'durThenStartThenMode'
- class discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.SolutionPrecomputeEmployeesForTasks(unit_used, worker_type_used, mode_dict, overskill_unit, overskill_type)[source]
Bases:
object
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.add_constraints_string(child_instance, list_of_strings)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.add_fake_task_cp_data(rcpsp_problem: MultiskillRcpspProblem, ignore_fake_task: bool = True, max_time_to_consider: int | None = None)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.add_hard_special_constraints(partial_solution: PartialSolution, cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.add_soft_special_constraints(partial_solution: PartialSolution, cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.define_second_part_objective(weights, name_penalty, equal=False)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.hard_end_window(end_times_window: dict[Hashable, tuple[int, int]], cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.hard_start_after_nunit(list_start_after_nunit: list[tuple[Hashable, Hashable, int]], cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.hard_start_at_end(list_start_at_end: list[tuple[Hashable, Hashable]], cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.hard_start_at_end_plus_offset(list_start_at_end_plus_offset, cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.hard_start_times(dict_start_times: dict[Hashable, int], cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.hard_start_together(list_start_together: list[tuple[Hashable, Hashable]], cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.hard_start_window(start_times_window: dict[Hashable, tuple[int, int]], cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.soft_end_window(end_times_window: dict[Hashable, tuple[int, int]], cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.soft_start_after_nunit(list_start_after_nunit: list[tuple[Hashable, Hashable, int]], cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.soft_start_at_end(list_start_at_end: list[tuple[Hashable, Hashable]], cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.soft_start_at_end_plus_offset(list_start_at_end_plus_offset: list[tuple[Hashable, Hashable, int]], cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.soft_start_times(dict_start_times: dict[Hashable, int], cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.soft_start_together(list_start_together: list[tuple[Hashable, Hashable]], cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.soft_start_window(start_times_window: dict[Hashable, tuple[int, int]], cp_solver: CpMultiskillRcpspSolver | CpPreemptiveMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.stick_to_solution(solution: RcpspSolution, cp_solver: CpMultiskillRcpspSolver)[source]
- discrete_optimization.rcpsp_multiskill.solvers.cp_mzn.stick_to_solution_preemptive(solution: PreemptiveRcpspSolution, cp_solver: CpPreemptiveMultiskillRcpspSolver)[source]
discrete_optimization.rcpsp_multiskill.solvers.cpsat module
- class discrete_optimization.rcpsp_multiskill.solvers.cpsat.CpSatMultiskillRcpspSolver(problem: Problem, **kwargs: Any)[source]
Bases:
OrtoolsCpSatSolver
- add_lexico_constraint(obj: str, value: float) Iterable[Constraint] [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:
- hyperparameters: list[Hyperparameter] = [CategoricalHyperparameter(name='redundant_skill_cumulative', default=True, depends_on=None, name_in_kwargs='redundant_skill_cumulative'), CategoricalHyperparameter(name='redundant_worker_cumulative', default=True, depends_on=None, name_in_kwargs='redundant_worker_cumulative')]
Hyperparameters available for this solver.
- These hyperparameters are to be feed to **kwargs found in
__init__()
init_model() (when available)
solve()
- 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(**args: Any) None [source]
Instantiate a CP model instance
Afterwards, self.instance should not be None anymore.
- problem: MultiskillRcpspProblem
- 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.
discrete_optimization.rcpsp_multiskill.solvers.ga module
- class discrete_optimization.rcpsp_multiskill.solvers.ga.GaMultiskillRcpspSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
SolverDO
- problem: RcpspProblem
- solve(parameters_ga: ParametersAltGa | None = None, **args)[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.rcpsp_multiskill.solvers.lns_lp module
- class discrete_optimization.rcpsp_multiskill.solvers.lns_lp.InitialMultiskillRcpspSolution(problem: MultiskillRcpspProblem, params_objective_function: ParamsObjectiveFunction | None = None, initial_method: InitialRcpspMethod = InitialRcpspMethod.PILE)[source]
Bases:
InitialSolution
- get_starting_solution() ResultStorage [source]
discrete_optimization.rcpsp_multiskill.solvers.lns_post_process module
- class discrete_optimization.rcpsp_multiskill.solvers.lns_post_process.MultiskillRcpspPostProcessSolution(problem: MultiskillRcpspProblem, params_objective_function: ParamsObjectiveFunction | None = None)[source]
Bases:
PostProcessSolution
- build_other_solution(result_storage: ResultStorage) ResultStorage [source]
- class discrete_optimization.rcpsp_multiskill.solvers.lns_post_process.PreemptiveMultiskillRcpspPostProcessSolution(problem: MultiskillRcpspProblem, params_objective_function: ParamsObjectiveFunction | None = None)[source]
Bases:
PostProcessSolution
- build_other_solution(result_storage: ResultStorage) ResultStorage [source]
- discrete_optimization.rcpsp_multiskill.solvers.lns_post_process.compute_schedule_per_employees(solution: PreemptiveMultiskillRcpspSolution | MultiskillRcpspSolution, problem: MultiskillRcpspProblem, predecessors_dict)[source]
- discrete_optimization.rcpsp_multiskill.solvers.lns_post_process.sgs_variant(solution: MultiskillRcpspSolution, problem: MultiskillRcpspProblem, predecessors_dict)[source]
- discrete_optimization.rcpsp_multiskill.solvers.lns_post_process.sgs_variant_preemptive(solution: PreemptiveMultiskillRcpspSolution, problem: MultiskillRcpspProblem, predecessors_dict)[source]
- discrete_optimization.rcpsp_multiskill.solvers.lns_post_process.shift_left_method(solution: PreemptiveMultiskillRcpspSolution | MultiskillRcpspSolution, problem: MultiskillRcpspProblem, predecessors_dict)[source]
discrete_optimization.rcpsp_multiskill.solvers.lp module
- class discrete_optimization.rcpsp_multiskill.solvers.lp.MathOptMultiskillRcpspSolver(problem: MultiskillRcpspProblem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs)[source]
Bases:
OrtoolsMathOptMilpSolver
- convert_to_variable_values(solution: MultiskillRcpspSolution) dict[Variable, int] [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.
Override it in subclasses to have a proper warm start.
- init_model(**args)[source]
Initialize internal model used to solve.
Can initialize a ortools, milp, gurobi, … model.
- problem: MultiskillRcpspProblem
- retrieve_current_solution(get_var_value_for_current_solution: Callable[[Any], float], get_obj_value_for_current_solution: Callable[[], float]) MultiskillRcpspSolution [source]
Retrieve current solution from internal gurobi solution.
This converts internal gurobi solution into a discrete-optimization Solution. This method can be called after the solve in retrieve_solutions() or during solve within a gurobi/pymilp/cplex callback. The difference will be the get_var_value_for_current_solution and get_obj_value_for_current_solution callables passed.
- Parameters:
get_var_value_for_current_solution – function extracting the value of the given variable for the current solution will be different when inside a callback or after the solve is finished
get_obj_value_for_current_solution – function extracting the value of the objective for the current solution.
- Returns:
the converted solution at d-o format
- solve(parameters_milp: ParametersMilp | None = None, time_limit: float | None = 30.0, **args) ResultStorage [source]
Solve with OR-Tools MathOpt API
- Parameters:
callbacks – list of callbacks used to hook into the various stage of the solve
parameters_milp – parameters passed to the MILP solver
mathopt_solver_type – underlying solver type to use. Passed as solver_type to mathopt.solve()
time_limit – the solve process stops after this time limit (in seconds). If None, no time limit is applied.
mathopt_enable_output – turn on mathopt logging
mathopt_model_parameters – passed to mathopt.solve() as model_params
mathopt_additional_solve_parameters – passed to mathopt.solve() as params, except that parameters defined by above time_limit and parameters_milp will be overriden by them.
store_mathopt_res – whether to store the mathopt.SolveResult generated by mathopt.solve()
extract_solutions_from_mathopt_res – whether to extract solutions from the mathopt.SolveResult generated by mathopt.solve(). If False, the solutions are rather extracted on the fly inside a callback at each mip solution improvement. By default, this is False except for HiGHS solver type, as its OR-Tools wrapper does not yet integrate callbacks.
**kwargs – passed to init_model() if model not yet existing
Returns:
discrete_optimization.rcpsp_multiskill.solvers.multimode_transposition module
- class discrete_optimization.rcpsp_multiskill.solvers.multimode_transposition.MultimodeTranspositionMultiskillRcpspSolver(problem: MultiskillRcpspProblem, multimode_problem: RcpspProblem | PreemptiveRcpspProblem | None = None, worker_type_to_worker: dict[str, set[str | int]] | None = None, params_objective_function: ParamsObjectiveFunction | None = None, solver_multimode_rcpsp: SolverDO | None = None, **kwargs)[source]
Bases:
SolverDO
- problem: MultiskillRcpspProblem
- solve(**kwargs) 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.rcpsp_multiskill.solvers.multimode_transposition.rebuild_multiskill_solution(multiskill_rcpsp_problem: MultiskillRcpspProblem, multimode_rcpsp_problem: RcpspProblem | PreemptiveRcpspProblem, worker_type_to_worker: dict[str, set[str | int]], solution_rcpsp: RcpspSolution | PreemptiveRcpspSolution)[source]
- discrete_optimization.rcpsp_multiskill.solvers.multimode_transposition.rebuild_multiskill_solution_cp_based(multiskill_rcpsp_problem: MultiskillRcpspProblem, multimode_rcpsp_problem: RcpspProblem | PreemptiveRcpspProblem, worker_type_to_worker: dict[str, set[str | int]], solution_rcpsp: RcpspSolution | PreemptiveRcpspSolution)[source]
discrete_optimization.rcpsp_multiskill.solvers.rcpsp_based module
- class discrete_optimization.rcpsp_multiskill.solvers.rcpsp_based.RcpspBasedMultiskillRcpspSolver(problem: MultiskillRcpspProblem | VariantMultiskillRcpspProblem, method, params_objective_function: ParamsObjectiveFunction | None = None, **args)[source]
Bases:
SolverDO
- solve(**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