discrete_optimization.rcpsp.solvers.preemptive package
Submodules
discrete_optimization.rcpsp.solvers.preemptive.cpsat module
- class discrete_optimization.rcpsp.solvers.preemptive.cpsat.CpSatCalendarPreemptiveSolver(problem: PreemptiveRcpspProblem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs)[source]
Bases:
OrtoolsCpSatSolver- constraint_duration_of_task(task_index: int, mode: int, duration_per_interval: dict[int, list[tuple[int, int]]])[source]
- constraint_duration_of_tasks()[source]
Tricky constraint : should take into account the partial preemption possibility, which makes duration variable based on calendars
- problem: PreemptiveRcpspProblem
- 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.
- class discrete_optimization.rcpsp.solvers.preemptive.cpsat.CpSatPreemptiveRcpspSolver(problem: PreemptiveRcpspProblem, 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:
- 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: PreemptiveRcpspProblem
- retrieve_solution(cpsolvercb: CpSolverSolutionCallback) PreemptiveRcpspSolution[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.solvers.preemptive.cpsat.compute_binary_calendar_per_tasks(problem: PreemptiveRcpspProblem) tuple[tuple, dict[tuple, ndarray], dict[tuple[int, int], tuple]][source]
- discrete_optimization.rcpsp.solvers.preemptive.cpsat.compute_duration_function_time_cluster(orig_duration: int, resource_calendar: ndarray, cumulative_resource_calendar: ndarray)[source]
- discrete_optimization.rcpsp.solvers.preemptive.cpsat.transform_calendar_preemptive_solution_to_preemptive(solution: PreemptiveRcpspSolution, problem: PreemptiveRcpspProblem, resource_calendar_dict: dict[tuple, ndarray] = None, task_mode_to_calendar: dict[tuple, ndarray] = None) PreemptiveRcpspSolution[source]
discrete_optimization.rcpsp.solvers.preemptive.optal module
- class discrete_optimization.rcpsp.solvers.preemptive.optal.OptalCalendarPreemptiveRcpspSolver(problem: PreemptiveRcpspProblem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs)[source]
Bases:
OptalCpSolver- init_model(**kwargs: Any) None[source]
Instantiate a CP model instance
Afterwards, self.instance should not be None anymore.
- problem: PreemptiveRcpspProblem
- retrieve_solution(result: cp.SolveResult) PreemptiveRcpspSolution[source]
Return a d-o solution from the variables computed by minizinc.
- Parameters:
result – output of the cp.solve
Returns:
- class discrete_optimization.rcpsp.solvers.preemptive.optal.OptalPreemptiveRcpspSolver(problem: PreemptiveRcpspProblem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs)[source]
Bases:
OptalCpSolver- 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:
- 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.
- problem: PreemptiveRcpspProblem
- retrieve_solution(result: cp.SolveResult) PreemptiveRcpspSolution[source]
Return a d-o solution from the variables computed by minizinc.
- Parameters:
result – output of the cp.solve
Returns:
- discrete_optimization.rcpsp.solvers.preemptive.optal.compute_binary_calendar_per_tasks(problem: PreemptiveRcpspProblem) tuple[dict[tuple, ndarray], dict[tuple[int, int], tuple]][source]