discrete_optimization.generic_tasks_tools.solvers.cp.cpsat package

Submodules

discrete_optimization.generic_tasks_tools.solvers.cp.cpsat.auto module

class discrete_optimization.generic_tasks_tools.solvers.cp.cpsat.auto.GenericSchedulingAutoCpSatSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: GenericSchedulingAutoCpSolver[Task, UnaryResource, Skill, NonSkillCumulativeResource, NonRenewableResource, ExclusionResource], TasksCpSatSolver[Task], Generic[Task, UnaryResource, Skill, NonSkillCumulativeResource, NonRenewableResource, ExclusionResource]

Generic cpsat solver for scheduling problems (with or without allocation).

The needed variables are automatically created, with common constraints (precedence, resource capacity). The objective is set by default to global makespan but can be changed by modifying solver.default_objective value.

This solver class needs still to be derived to create a solution from the proper class. You will need at least to implement the conversion from the task variables to the actual solution object.

If custom constraints are needed, override init_model(). If a custom objective is needed, set solver.default_objective to Objective.CUSTOM so that no objective is set by default and override init_model() to define your objective.

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.generic_tasks_tools.solvers.cp.cpsat.auto.SinglemodeGenericSchedulingAutoCpSatSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: SinglemodeGenericSchedulingAutoCpSolver[Task, UnaryResource, Skill, NonSkillCumulativeResource, NonRenewableResource, ExclusionResource], GenericSchedulingAutoCpSatSolver[Task, UnaryResource, Skill, NonSkillCumulativeResource, NonRenewableResource, ExclusionResource]

Subclass of GenericSchedulingAutoCpSatSolver for single mode problems.

Give access to task intervals without dealing with modes.

discrete_optimization.generic_tasks_tools.solvers.cp.cpsat.auto_impl module

class discrete_optimization.generic_tasks_tools.solvers.cp.cpsat.auto_impl.GenericSchedulingAutoCpSatImplSolver(problem: GenericSchedulingImplProblem, params_objective_function: ParamsObjectiveFunction | None = None, custom_objective_factory: Callable[[GenericSchedulingAutoCpImplSolver], Any] | None = None, **kwargs: Any)[source]

Bases: GenericSchedulingAutoCpImplSolver, GenericSchedulingAutoCpSatSolver[Hashable, Hashable, Hashable, Hashable, Hashable, Hashable]

Generic implementation of cpsat solver for scheduling problems (with or without allocation).

It implements abstract class GenericSchedulingAutoCpSatSolver.

discrete_optimization.generic_tasks_tools.solvers.cp.cpsat.base module

class discrete_optimization.generic_tasks_tools.solvers.cp.cpsat.base.TasksCpSatSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: OrtoolsCpSatSolver, TasksCpSolver[Task]

add_cumulative(intervals: Iterable[Any], demands: Iterable[Any], capacity: Any) → list[Any][source]

Add cumulative constraint

Enforces that:

for all t:
self.sum(demands[i]

if (start(intervals[i]) <= t < end(intervals[i])) and (intervals[i] is present)) <= capacity

Parameters:
  • intervals

  • demands

  • capacity

Returns:

add_no_overlap(intervals: Iterable[Any]) → list[Any][source]

Add constraint so that no intervals overlap.

Parameters:

intervals

Returns:

create_interval_var(start: Any, duration: Any, name: str, end: Any | None = None, presence: Any = True) → Any[source]

Create an interval variable in the underlying cp model.

The interval can be - fixed or not - with fixed duration or not - optional (with associated presence bool var)

Parameters:
  • start

  • duration

  • end

  • presence – should be a boolean variable if the interval is optional

  • name

Returns:

the created interval variable

Module contents