discrete_optimization.generic_tasks_tools.solvers.cp.optal package

Submodules

discrete_optimization.generic_tasks_tools.solvers.cp.optal.alternative_subproblems module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.alternative_subproblems.AlternativeSubproblemOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: AlternativeSubproblemCpSolver[Task], MultimodeSchedulingOptalSolver[Task], Generic[Task]

discrete_optimization.generic_tasks_tools.solvers.cp.optal.auto module

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

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

Generic optal 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.

allocation_intervals: dict[Task, dict[UnaryResource, cp.IntervalVar]]
get_duration_variable(task: Task, task_interval_will_exist: bool | None = None) → Any[source]

Get duration variable for given task

Parameters:
  • task

  • task_interval_will_exist – if you know that the task interval will also be created, set this to True to avoid redundant constraints. Ignored if the duration variable has already been created.

Returns:

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_is_present_variable(task: Task) → Any[source]

Get the boolean variable whether the (optional) task is present.

Default implementation returns True for mandatory task. To be overriden when optional tasks to get an actual boolean variable.

get_task_mode_interval(task: Task, mode: int) → cp.IntervalVar[source]

Get the interval variable corresponding to given task and mode.

Needs to be created if avoid_interval_optional_for_cumulative_resources is False. Not necessary else.

The interval should be optional with the is_present variable being false whenever the task is optional and absent.

get_task_mode_is_present_variable(task: Task, mode: int) → Any[source]

Retrieve the boolean variable/expression telling if the mode is used for the task.

The variable value should be 0 / False when the task is optional and absent.

Parameters:
  • task

  • mode

Returns:

get_task_start_or_end_variable(task: Task, start_or_end: StartOrEnd) → Any[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_interval(task: Task, unary_resource: UnaryResource) → Any[source]

Get the interval variable corresponding to given task conditioned to allocation of the given unary resource.

The method may return an error (no variable existing) if self.problem.is_compatible_task_unary_resource(task=task, unary_resource=unary_resource) is false.

get_task_unary_resource_is_present_variable(task: Task, unary_resource: UnaryResource) → Any[source]

Return a 0-1 variable/expression telling if the unary_resource is used for the task.

The value will be 0 if the (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.

modes_intervals: dict[Task, dict[int, cp.IntervalVar]]
retrieve_solution(result: cp.Solution) → Solution[source]

Construct a d-o solution from OptalCP solver solution.

Parameters:

solution – OptalCP solution

Returns:

d-o solution

retrieve_tasks_variables_optal(solution: cp.Solution) → RawSolution[Task, UnaryResource, Skill][source]

Construct each task variable from the optal internal solution.

We cannot use the generic retrieve_tasks_variables() as the way to retrieve the value of a given expression or variable may vary. Often we need to go back to the interval variable it is derived from.

This method will be called in self.retrieve_solution() before self.convert_task_variables_to_solution().

Parameters:

solution

Returns:

the task variables for the intermediate solution

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

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

Subclass of GenericSchedulingAutoOptalSolver for single mode problems.

Give access to task intervals without dealing with modes.

discrete_optimization.generic_tasks_tools.solvers.cp.optal.auto_impl module

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

Bases: GenericSchedulingAutoCpImplSolver, GenericSchedulingAutoOptalSolver[Hashable, Hashable, Hashable, Hashable, Hashable, Hashable]

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

It implements abstract class GenericSchedulingAutoCpmpySolver.

discrete_optimization.generic_tasks_tools.solvers.cp.optal.base module

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

Bases: OptalCpSolver, 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

enforce_only_if_tasks_present(expr: Any, tasks: Iterable[Task])[source]

Enforce given constraints only if all given tasks are present.

Parameters:
  • expr

  • tasks

Returns:

discrete_optimization.generic_tasks_tools.solvers.cp.optal.calendar_preemptive module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.calendar_preemptive.CalendarPreemptiveOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: CalendarPreemptiveCpSolver[Task, CumulativeResource, OtherCalendarResource], MultimodeSchedulingOptalSolver[Task], Generic[Task, CumulativeResource, OtherCalendarResource]

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.calendar_preemptive.ModelingCalendarPreemptive(*values)[source]

Bases: Enum

ELEMENT = 1
INDICATOR = 0

discrete_optimization.generic_tasks_tools.solvers.cp.optal.calendar_resource module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.calendar_resource.CalendarResourceOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: CalendarResourceCpSolver[Task, Resource], SchedulingOptalSolver[Task], Generic[Task, Resource]

discrete_optimization.generic_tasks_tools.solvers.cp.optal.calendar_resource_generic module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.calendar_resource_generic.CalendarResourceGenericOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: CalendarResourceGenericCpSolver[Task, NonSkillCumulativeResource, OtherCalendarResource, UnaryResource], CalendarPreemptiveOptalSolver[Task, NonSkillCumulativeResource, OtherCalendarResource], ResourceBlockingOptalSolver[Task, NonSkillCumulativeResource, UnaryResource], ResourceUsageByUnaryResourceOptalSolver[Task, NonSkillCumulativeResource, OtherCalendarResource, UnaryResource], SchedulingOptalSolver[Task], Generic[Task, NonSkillCumulativeResource, OtherCalendarResource, UnaryResource]

discrete_optimization.generic_tasks_tools.solvers.cp.optal.cumulative_resource module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.cumulative_resource.CumulativeResourceSchedulingOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: CumulativeResourceSchedulingCpSolver[Task, CumulativeResource, OtherCalendarResource], CalendarResourceOptalSolver[Task, CumulativeResource | OtherCalendarResource], MultimodeSchedulingOptalSolver[Task], Generic[Task, CumulativeResource, OtherCalendarResource]

Base class for solvers dealing with scheduling problems handling cumulative resources.

discrete_optimization.generic_tasks_tools.solvers.cp.optal.entity module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.entity.EntityIntervalsOptalMixin(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: EntityIntervalsMixin[Task], MultimodeSchedulingOptalSolver[Task], Generic[Task]

Optal mixin for creating interval variables for any SchedulingEntity.

create_composite_entity_interval(entity: CompositeEntity[Task])[source]

Create interval for CompositeEntity (composition of entities).

create_constant_duration_interval(entity: ConstantDurationEntity[Task])[source]

Create interval for ConstantDurationEntity (fixed offset from another entity).

create_group_entity_interval(entity: GroupEntity[Task])[source]

Create interval for GroupEntity (span of its tasks).

create_modulo_entity_interval(entity: ModuloTaskEntity[Task])[source]

Create interval for ModuloTaskEntity (task start modulo value).

create_modulo_two_entity_interval(entity: ModuloTwoEntity[Task])[source]

Create interval for ModuloTwoEntity (entity start modulo another entity).

create_multiply_entity_interval(entity: MultiplyTaskEntity[Task])[source]

Create interval for MultiplyTaskEntity (task time * factor).

create_task_entity_interval(entity: TaskEntity[Task] | TaskModeEntity[Task])[source]

Create interval for TaskEntity or TaskModeEntity.

create_variable_batch_entity_interval(entity: VariableBatchEntity[Task])[source]

Create interval for VariableBatchEntity (batch with variable membership).

The batch interval spans from the earliest start to latest end of tasks assigned to this batch. Assignment is determined by task_to_batch_vars.

get_entity_is_active_variable(entity: SchedulingEntity) → Any | int[source]

Get presence/active variable for an entity.

Parameters:

entity – The scheduling entity

Returns:

IntVar (BoolVar) if entity is optional, or int 1 if always active

discrete_optimization.generic_tasks_tools.solvers.cp.optal.entity_constraints module

Optal solver for entity-based constraints.

This module provides a mixin for handling entity constraints (precedence, time lags, time windows) on any SchedulingEntity, not just tasks.

It provides complete entity interval creation logic that can be reused by resource_blocking.py and other modules.

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.entity_constraints.EntityConstraintsOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: EntityConstraintsCpSolver[Task], EntityIntervalsOptalMixin[Task]

Optal solver mixin for entity-based constraints.

Adds: - Precedence constraints between any SchedulingEntities - Time lag constraints (8 types: start/end × start/end × min/max) - Time window constraints on entity start/end times

create_entity_precedence_constraints() → None[source]

Add constraints for entity precedence.

For each entity1 → entity2 precedence:

end(entity1) <= start(entity2)

Only enforced when both entities are active.

create_entity_time_lag_constraints() → None[source]

Add constraints for entity time lags.

For each time lag type (start/end × start/end × min/max):

MIN: time1 + offset <= time2 MAX: time1 + offset >= time2

Only enforced when both entities are active.

create_entity_time_window_constraints() → None[source]

Add constraints for entity time windows.

For each entity with time window bounds:

lower_bound <= entity_time <= upper_bound

Only enforced when entity is active.

discrete_optimization.generic_tasks_tools.solvers.cp.optal.exclusions module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.exclusions.ExclusionOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: ExclusionCpSolver[Task, ExclusionResource], MultimodeSchedulingOptalSolver[Task], Generic[Task, ExclusionResource]

discrete_optimization.generic_tasks_tools.solvers.cp.optal.generic_scheduling module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.generic_scheduling.GenericSchedulingOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: GenericSchedulingCpSolver[Task, UnaryResource, Skill, NonSkillCumulativeResource, NonRenewableResource, OtherCalendarResource, ExclusionResource], RoutingOptalSolver[Task], ExclusionOptalSolver[Task, ExclusionResource], AlternativeSubproblemOptalSolver[Task], NoOverlapOptalSolver[Task], TimelagOptalSolver[Task], PrecedenceSchedulingOptalSolver[Task], SkillSchedulingOptalSolver[Task, UnaryResource, Skill, NonSkillCumulativeResource, OtherCalendarResource], Generic[Task, UnaryResource, Skill, NonSkillCumulativeResource, NonRenewableResource, OtherCalendarResource, ExclusionResource]

Mixin for optal solver dealing with scheduling + allocation problems.

Has access to helping methods to create constraints for - precedence - renewable resource with calendar (unary resource to allocate, or cumulative resource) - non-renewable resource capacity - skills brought to tasks by allocated unary resources - resource blocking (gaps and spans) - entity constraints (precedence, time lags, time windows on any SchedulingEntity) - batching (variable task-to-batch assignment)

For a more all-in-one version actually creating variables, constraints and objectives, see GenericSchedulingAutoOptalSolver.

get_task_unary_resource_is_present_variable(task: Task, unary_resource: UnaryResource) → Any[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.

discrete_optimization.generic_tasks_tools.solvers.cp.optal.multimode_scheduling module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.multimode_scheduling.MultimodeSchedulingOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: MultimodeSchedulingCpSolver[Task], SchedulingOptalSolver[Task], Generic[Task]

Mixin for optal solvers dealing with scheduling problems whose tasks durations depend only on mode.

get_task_mode_is_present_variable(task: Task, mode: int) → Any[source]

Retrieve the boolean variable/expression telling if the mode is used for the task.

The variable value should be 0 / False when the task is optional and absent.

Parameters:
  • task

  • mode

Returns:

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.multimode_scheduling.SinglemodeSchedulingOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: MultimodeSchedulingOptalSolver[Task], SinglemodeSchedulingCpSolver[Task]

Base class for solvers dealing with single mode scheduling problems with fixed tasks durations.

get_task_mode_interval(task: Task, mode: int) → cp.IntervalVar[source]

Get the interval variable corresponding to given task and mode.

Needs to be created if avoid_interval_optional_for_cumulative_resources is False. Not necessary else.

The interval should be optional with the is_present variable being false whenever the task is optional and absent.

discrete_optimization.generic_tasks_tools.solvers.cp.optal.no_overlap module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.no_overlap.NoOverlapOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: NoOverlapCpSolver[Task], SchedulingOptalSolver[Task]

Mixin for optal solvers dealing with scheduling problems with no overlap constraints between set of tasks

discrete_optimization.generic_tasks_tools.solvers.cp.optal.precedence_scheduling module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.precedence_scheduling.PrecedenceSchedulingOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: PrecedenceSchedulingCpSolver[Task], SchedulingOptalSolver[Task]

Mixin for optal solvers dealing with scheduling problems with precedence constraints.

discrete_optimization.generic_tasks_tools.solvers.cp.optal.resource_blocking module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.resource_blocking.ResourceBlockingOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: ResourceBlockingCpSolver[Task, CumulativeResource, OtherCalendarResource], EntityIntervalsOptalMixin[Task], CumulativeResourceSchedulingOptalSolver[Task, CumulativeResource, OtherCalendarResource], Generic[Task, CumulativeResource, OtherCalendarResource]

discrete_optimization.generic_tasks_tools.solvers.cp.optal.resource_usage_by_unary module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.resource_usage_by_unary.ResourceUsageByUnaryResourceOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: ResourceUsageByUnaryResourceCpSolver[Task, CumulativeResource, OtherCalendarResource, UnaryResource], CumulativeResourceSchedulingOptalSolver[Task, CumulativeResource, OtherCalendarResource], Generic[Task, CumulativeResource, OtherCalendarResource, UnaryResource]

discrete_optimization.generic_tasks_tools.solvers.cp.optal.routing module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.routing.RoutingOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: RoutingCpSolver[Task], EntityConstraintsOptalSolver[Task], Generic[Task]

discrete_optimization.generic_tasks_tools.solvers.cp.optal.scheduling module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.scheduling.SchedulingOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: TasksOptalSolver[Task], SchedulingCpSolver[Task]

Mixin for optal solvers handling scheduling problems.

get_duration_variable(task: Task) → Any[source]
get_global_makespan_variable() → Any[source]

Construct and get the variable tracking the global makespan.

Default implementation uses get_subtasks_makespan_variable on last tasks. Beware: a further call to get_subtasks_makespan_variable with another subset of tasks can change the constraints on this variable and thus make it obsolete.

Returns:

objective variable to minimize

get_subtasks_makespan_variable(subtasks: Iterable[Task]) → Any[source]

Construct and get the variable tracking the makespan on a subset of tasks.

Beware: a further call to get_subtasks_makespan_variable with another subset of tasks can change the constraints on this variable and thus make it obsolete.

Parameters:

subtasks

Returns:

objective variable to minimize

get_subtasks_sum_end_time_variable(subtasks: Iterable[Task]) → Any[source]

Construct and get the variable tracking the sum of end times on a subset of tasks.

Parameters:

subtasks

Returns:

objective variable to minimize

get_subtasks_sum_start_time_variable(subtasks: Iterable[Task]) → Any[source]

Construct and get the variable tracking the sum of start times on a subset of tasks.

Parameters:

subtasks

Returns:

objective variable to minimize

abstractmethod 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_start_or_end_variable(task: Task, start_or_end: StartOrEnd) → Any[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:

discrete_optimization.generic_tasks_tools.solvers.cp.optal.skill module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.skill.SkillSchedulingOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: SkillSchedulingCpSolver[Task, UnaryResource, Skill, NonSkillCumulativeResource, OtherCalendarResource], CalendarResourceGenericOptalSolver[Task, Skill | NonSkillCumulativeResource, OtherCalendarResource, UnaryResource], Generic[Task, UnaryResource, Skill, NonSkillCumulativeResource, OtherCalendarResource]

discrete_optimization.generic_tasks_tools.solvers.cp.optal.timelag module

class discrete_optimization.generic_tasks_tools.solvers.cp.optal.timelag.TimelagOptalSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: TimelagCpSolver[Task], SchedulingOptalSolver[Task]

discrete_optimization.generic_tasks_tools.solvers.cp.optal.utils module

discrete_optimization.generic_tasks_tools.solvers.cp.optal.utils.get_interval_start_or_end_variable(itv: cp.IntervalVar, start_or_end: StartOrEnd) → LinearExpr[source]

Retrieve the variable storing the start or end time of given interval.

Parameters:
  • itv

  • start_or_end

Returns:

Module contents