discrete_optimization.generic_tools.hub_solver.optal package
Submodules
discrete_optimization.generic_tools.hub_solver.optal.optalcp_tools module
- class discrete_optimization.generic_tools.hub_solver.optal.optalcp_tools.OptalCpSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]
Bases:
CpSolver,BoundsProviderMixin- add_bound_constraint(var: Any, sign: SignEnum, value: int) list[Any][source]
Add constraint of bound type on an integer variable (or expression) of the underlying cp model.
var must compare to value according to value.
- Parameters:
var
sign
value
Returns:
- cp_model: cp.Model | None = None
- current_bound: int | float | None = None
- current_obj: int | float | None = None
- early_stopping_exception: Exception | None = None
- hyperparameters = [CategoricalHyperparameter(name='searchType', default='Auto', depends_on=None, name_in_kwargs='searchType')]
Hyperparameters available for this solver.
- These hyperparameters are to be feed to **kwargs found in
__init__()
init_model() (when available)
solve()
- abstractmethod 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:
- solve(callbacks: list[Callback] | None = None, time_limit: int | None = 60, parameters_cp: ParametersCp | None = None, do_not_retrieve_solutions: bool = False, **args: Any) ResultStorage[source]
Solve the cp model
- Parameters:
callbacks
time_limit
parameters_cp
do_not_retrieve_solutions – if True, do no try to retrieve solutions. Useful when using preview version of optalcp.
**args
Returns:
- status_solver: StatusSolver = None
- use_warm_start: bool = False
- warm_start_solution: cp.Solution | None = None
- class discrete_optimization.generic_tools.hub_solver.optal.optalcp_tools.OptalSolutionCallback(do_solver: OptalCpSolver, optal_solver: cp.Solver, callback: Callback, do_not_retrieve_solutions: bool = False)[source]
Bases:
object- current_solve_result: cp.SolveResult | None
- discrete_optimization.generic_tools.hub_solver.optal.optalcp_tools.run_async_synchronously(coroutine: Awaitable[T]) T[source]
Runs a coroutine synchronously, blocking until it completes.
This helper handles two cases: 1. No event loop is running (standard script): Uses asyncio.run() 2. An event loop is running (e.g., Jupyter): Runs the coroutine in a
separate thread to avoid blocking the existing loop/raising runtime errors.