discrete_optimization.generic_tasks_tools.solvers.cpsat package

Submodules

discrete_optimization.generic_tasks_tools.solvers.cpsat.allocation module

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

Bases: AllocationIntegerModellingCpSatSolver[Task, UnaryResource]

Base class for allocation cp-sat solvers using a binary or integer modelling.

add_allocation_changes_constraints(ref: AllocationSolution[Task, UnaryResource]) list[Any][source]

Add and return constraints so that change variables reflect diff to ref.

add_constraint_on_task_unary_resource_allocation(task: Task, unary_resource: UnaryResource, used: bool) list[Any][source]

Add constraint on allocation of given unary resource for the given task

Parameters:
  • task

  • unary_resource

  • used – if True, we enforce the allocation of unary_resource to task, else we prevent it

Returns:

resulting constraints

allocation_modelling: AllocationModelling
abstractmethod get_binary_allocation_variable(task: Task, unary_resource: UnaryResource) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]

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

Only to be called when allocation_modelling == AllocationModelling.BINARY.

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.

abstractmethod get_integer_allocation_variable(task: Task) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]

Return an integer variable/expression storing the index of the allocated unary_resource.

Assumes that exactly one unary resource is allocated to a task. Only to be called when allocation_modelling == AllocationModelling.INTEGER.

Parameters:

task

Returns:

get_task_allocation_variable(task: Task) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]

Return an integer variable/expression storing the index of the allocated unary_resource.

Assumes that exactly one unary resource is allocated to a task.

get_task_unary_resource_is_present_variable(task: Task, unary_resource: UnaryResource) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]

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

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.

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

Bases: OrtoolsCpSatSolver, AllocationCpSolver[Task, UnaryResource]

Base class for allocation cp-sat solvers using a binary modelling.

I.e. using 0-1 variables to model allocation status of each couple (task, unary_resource) This is a more general modelisation thant the integer one as it allows allocation of multiple resources.

add_allocation_changes_constraints(ref: AllocationSolution[Task, UnaryResource]) list[Any][source]

Add and return constraints so that change variables reflect diff to ref.

add_at_most_one_unary_resource_per_task_constraints()[source]

Add constraints to cp model so that no more than one unary resource is allocated per task.

Calling method avoid recreating the constraint if already done (e.g. when calling create_done_variables())

add_constraint_nb_unary_resource_usages(sign: SignEnum, target: int, tasks: Iterable[Task] | None = None, unary_resources: Iterable[UnaryResource] | None = None) list[Any][source]
add_constraint_on_nb_allocation_changes(ref: AllocationSolution[Task, UnaryResource], nb_changes: int, sign: SignEnum = SignEnum.LEQ) list[Any][source]

Add contraint on maximal number of allocation changes from the given reference.

Parameters:
  • ref

  • nb_changes – maximal number of changes

Returns:

resulting constraints

add_constraint_on_task_unary_resource_allocation(task: Task, unary_resource: UnaryResource, used: bool) list[Any][source]

Add constraint on allocation of given unary resource for the given task

Parameters:
  • task

  • unary_resource

  • used – if True, we enforce the allocation of unary_resource to task, else we prevent it

Returns:

resulting constraints

add_constraint_on_total_nb_usages(sign: SignEnum, target: int) list[Any][source]
add_constraint_on_unary_resource_nb_usages(unary_resource: UnaryResource, sign: SignEnum, target: int) list[Any][source]
allocation_changes_variables: dict[tuple[Task, UnaryResource], IntVar]

Variables tracking allocation changes from a given reference.

allocation_changes_variables_created = False

Flag telling whether ‘allocation changes variables’ have been created

at_most_one_unary_resource_per_task = False

Flag telling if the problem accept at most one unary_resource per task.

Default to False, ie several resources allowed per task.

at_most_one_unary_resource_per_task_constraints_added = False

Flag telling whether constraints ensuring at most one unary resource per task have been created

create_allocation_changes_variables()[source]

Create variables necessary for constraint on nb of changes.

create_done_variables()[source]
create_used_variables()[source]
done_variables: dict[Task, IntVar]

Variables tracking whether a task has at least one unary resource allocated.

done_variables_created = False

Flag telling whether ‘done variables’ have been created

get_default_tasks_n_unary_resources(tasks: Iterable[Task] | None = None, unary_resources: Iterable[UnaryResource] | None = None) tuple[Iterable[Task], Iterable[UnaryResource]][source]
get_nb_tasks_done_variable() Any[source]

Construct and get the variable tracking number of tasks with at least a resource allocated.

Returns:

objective variable to minimize

get_nb_unary_resources_used_variable() Any[source]

Construct and get the variable tracking number of tasks with at least a resource allocated.

Returns:

objective variable to minimize

abstractmethod get_task_unary_resource_is_present_variable(task: Task, unary_resource: UnaryResource) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]

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

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.

init_model(**kwargs: Any) None[source]

Init cp model and reset stored variables if any.

property subset_tasks_of_interest: Iterable[Task]

Subset of tasks of interest used for the objective.

By default, all tasks.

property subset_unaryresources_allowed: Iterable[UnaryResource]

Unary resources allowed to solve the problem.

By default, all unary resources.

used_variables: dict[UnaryResource, IntVar]

Variables tracking whether a unary resource has been used at least once.

used_variables_created = False

Flag telling whether ‘used variables’ have been created

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

Bases: AllocationCpSatSolver[Task, UnaryResource]

Base class for allocation cp-sat solvers using an integer modelling.

I.e. using integer variables to model allocation of a task. This assumes that at most one unary_resource can be allocated to a task.

add_allocation_changes_constraints(ref: AllocationSolution[Task, UnaryResource]) list[Any][source]

Add and return constraints so that change variables reflect diff to ref.

add_constraint_on_task_unary_resource_allocation(task: Task, unary_resource: UnaryResource, used: bool) list[Any][source]

Add constraint on allocation of given unary resource for the given task

Parameters:
  • task

  • unary_resource

  • used – if True, we enforce the allocation of unary_resource to task, else we prevent it

Returns:

resulting constraints

create_is_present_variables() None[source]
abstractmethod get_task_allocation_variable(task: Task) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]

Return an integer variable/expression storing the index of the allocated unary_resource.

Assumes that exactly one unary resource is allocated to a task.

get_task_unary_resource_is_present_variable(task: Task, unary_resource: UnaryResource) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]

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

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.

init_model(**kwargs: Any) None[source]

Init cp model and reset stored variables if any.

is_present_variables: dict[tuple[Task, UnaryResource], IntVar]
is_present_variables_created = False
class discrete_optimization.generic_tasks_tools.solvers.cpsat.allocation.AllocationModelling(*values)[source]

Bases: Enum

BINARY = 'binary'
INTEGER = 'integer'

discrete_optimization.generic_tasks_tools.solvers.cpsat.auto module

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

Bases: GenericSchedulingCpSatSolver[Task, UnaryResource, CumulativeResource, NonRenewableResource], WarmstartMixin

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.

all_used_variables: dict[NonRenewableResource | UnaryResource | CumulativeResource, IntVar]

Variables tracking whether a (unary, cumulative, or non-renewable) resource has been used at least once.

all_used_variables_created = False

Flag telling whether ‘all_used_variables’ have been created

allocation_intervals: dict[Task, dict[UnaryResource, IntervalVar]]
allocation_is_present: dict[Task, dict[UnaryResource, LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64]]
check_resources_lists()[source]
abstractmethod convert_task_variables_to_solution(temp_sol: TemporarySolution[Task, UnaryResource]) GenericSchedulingSolution[Task, UnaryResource, CumulativeResource, NonRenewableResource][source]

Convert solution from autosolver format into do format.

To be used in self.retrieve_solution().

Parameters:

temp_sol

Returns:

duplicate_start_var_per_mode = False
duration_variables: dict[Task, LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64]
exactly_one_unary_resource_per_task = False
get_aggregated_resources_consumptions_variable() Any[source]

Get cpsat variable aggregating consumptions of each resource.

get_nb_resources_used_variable() Any[source]

Get cpsat variable tracking number of resources used at least in one task.

If necessary, intermediate variables tracking is a specific resource is used are created.

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

Get the interval variable corresponding to given task and mode.

get_task_mode_is_present_variable(task: Task, mode: int) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]

Retrieve the 0-1 variable/expression telling if the mode is used for the task.

Parameters:
  • task

  • mode

Returns:

get_task_start_or_end_lower_bound(task: Task, start_or_end: StartOrEnd) int[source]

Get a lower bound on start or end of a given task.

Default implementation: calls self.problem.get_task_start_or_end_lower_bound()

Parameters:
  • task

  • start_or_end

Returns:

get_task_start_or_end_upper_bound(task: Task, start_or_end: StartOrEnd) int[source]

Get an upper bound on start or end of a given task.

Default implementation: takes best of - self.problem.get_task_start_or_end_upper_bound() - self.get_makespan_upper_bound()

Parameters:
  • task

  • start_or_end

Returns:

get_task_start_or_end_variable(task: Task, start_or_end: StartOrEnd) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]

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

Parameters:
  • task

  • start_or_end

Returns:

get_task_unary_resource_interval(task: Task, unary_resource: UnaryResource) IntervalVar[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) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]

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

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.

include_constraint_on_cumulative_resource(resource: CumulativeResource) bool[source]

Whether the cp model should take into account the constraint on the given cumulative resource.

Some problems define “redundant” cumulative resources that are computed from others. If you want to avoid adding redundant constraints in your model, please override this method.

Parameters:

resource

Returns:

init_model(**kwargs: Any) None[source]

Init cp model and reset stored variables if any.

modes_intervals: dict[Task, dict[int, IntervalVar]]
modes_is_present: dict[Task, dict[int, LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64]]
modes_start_variables: dict[Task, dict[int, LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64]]
property needs_duration_variables: bool

Whether the task duration variables are needed by the model.

Default implementation, returns True only if the problem is an allocation one (at least one unary resource). If additional custom constraints require them, override it.

property needs_task_interval: bool

Whether the task interval variables are needed by the model.

By default, these variables are only constraints on durations variables and need not to be stored. If additional custom constraints require them, override this property.

objective = 'makespan'
objective_resource_weights: dict[CumulativeResource | UnaryResource | NonRenewableResource, int] | None = None

Weights to be used by the objective when summing used resources or resources consumption.

This is the case if objective is set to Objective.NB_RESOURCES_USED or Objective.RESOURCES_CONSUMPTION. Default to 1 for resources not mentioned.

Hypothesis: cumulative, unary, and non-renewable resources have different values. (It could happen that non-renewable resources and renewable lists intersect which whould be a problem for weights definition).

resource_consumption_variables: dict[NonRenewableResource | UnaryResource | CumulativeResource, LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64]

Variables tracking total consumption of each (unary, cumulative, or non-renewable) resource.

resource_consumption_variables_created = False

Flag telling whether ‘resource_consumption_variables’ have been created

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.

retrieve_tasks_variables(cpsolvercb: CpSolverSolutionCallback) TemporarySolution[Task, UnaryResource][source]

Construct each task variable 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).

This method is called in self.retrieve_solution() before self.convert_task_variables_to_solution(). Override it if you need additional information to be stored (either in res.metadata or res.task_variables[task].info).

Parameters:

cpsolvercb – the ortools callback called when the cpsat solver finds a new solution.

Returns:

the task variables for the intermediate solution

set_warm_start(solution: Solution) None[source]

Make the solver warm start from the given solution.

start_or_end_variables: dict[tuple[Task, StartOrEnd], LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64]
task_interval_variables

alias of dict[Task, IntervalVar]

class discrete_optimization.generic_tasks_tools.solvers.cpsat.auto.Objective(*values)[source]

Bases: Enum

Objective to be used by the solver.

CUSTOM = 'custom_objective'
MAKESPAN = 'makespan'

Global makespan of the schedule, to minimize.

NB_RESOURCES_USED = 'nb_resources_used'

Weighted sum of resources used, to minimize.

Include non-renewable, cumulative, and unary resources. The weigths are to be defined in solver.objective_resource_weights.

NB_TASKS_DONE = 'nb_tasks_done'

Number of tasks with at least one resource allocated, to maximize.

NB_UNARY_RESOURCES_USED = 'nb_unary_resources_used'

Number of allocated unary resources, to minimize.

RESOURCES_CONSUMPTION = 'resources_consumption'

Weighted sum of resources consumptions, to minimize.

Include non-renewable, cumulative, and unary resources. The weigths are to be defined in solver.objective_resource_weights.

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

Bases: GenericSchedulingAutoCpSatSolver[Task, UnaryResource, CumulativeResource, NonRenewableResource], SinglemodeSchedulingCpSatSolver[Task]

Subclass of GenericSchedulingAutoCpSatSolver for single mode problems.

Give access to task intervals without dealing with modes.

get_task_interval(task: Task) IntervalVar[source]

Task interval with fixed duration, single mode.

problem: SinglemodeProblem[Task]
class discrete_optimization.generic_tasks_tools.solvers.cpsat.auto.TaskVariable(start: int, end: int, mode: int, allocated: list[UnaryResource] = <factory>, info: dict[str, ~typing.Any]=<factory>)[source]

Bases: Generic[UnaryResource]

Task characteristics found by a cpsat solution.

allocated: list[UnaryResource]
end: int
info: dict[str, Any]
mode: int
start: int
class discrete_optimization.generic_tasks_tools.solvers.cpsat.auto.TemporarySolution(task_variables: dict[~discrete_optimization.generic_tasks_tools.base.Task, ~discrete_optimization.generic_tasks_tools.solvers.cpsat.auto.TaskVariable[~discrete_optimization.generic_tasks_tools.allocation.UnaryResource]], metadata: dict[str, ~typing.Any] = <factory>)[source]

Bases: Generic[Task, UnaryResource]

Temporary format for a cpsat solution.

metadata: dict[str, Any]
task_variables: dict[Task, TaskVariable[UnaryResource]]

discrete_optimization.generic_tasks_tools.solvers.cpsat.calendar_resource module

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

Bases: SchedulingCpSatSolver[Task], Generic[Task, Resource]

create_calendar_resources_constraint(resource: Resource)[source]

Add the constraint for renewable resources with an availability calendar to the cpsat model.

Constraint ensuring that the total demand on the given resource stay below its capacity.

abstractmethod get_resource_consumption_intervals(resource: Resource) list[tuple[IntervalVar, int]][source]

Get all intervals where a given resource is consumed by a task, and related consumption value.

Parameters:

resource

Returns: list of tuples (interval_var, consumption_value)

problem: CalendarResourceProblem[Task, Resource]

discrete_optimization.generic_tasks_tools.solvers.cpsat.cumulative_resource module

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

Bases: CalendarResourceCpSatSolver[Task, CumulativeResource | OtherCalendarResource], MultimodeSchedulingCpSatSolver[Task], Generic[Task, CumulativeResource, OtherCalendarResource]

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

get_resource_consumption_intervals(resource: CumulativeResource | OtherCalendarResource) list[tuple[IntervalVar, int]][source]

Get all intervals where a given resource is consumed by a task, and related consumption value.

Parameters:

resource

Returns: list of tuples (interval_var, consumption_value)

problem: CumulativeResourceProblem[Task, CumulativeResource, OtherCalendarResource]

discrete_optimization.generic_tasks_tools.solvers.cpsat.generic_scheduling module

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

Bases: CumulativeResourceSchedulingCpSatSolver[Task, CumulativeResource, UnaryResource], NonRenewableCpSatSolver[Task, NonRenewableResource], AllocationCpSatSolver[Task, UnaryResource], PrecedenceSchedulingCpSatSolver[Task], Generic[Task, UnaryResource, CumulativeResource, NonRenewableResource]

Mixin for cpsat solver dealing with sheduling + 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

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

get_resource_consumption_intervals(resource: CumulativeResource | UnaryResource) list[tuple[IntervalVar, int]][source]

Get all intervals where a given resource is consumed by a task, and related consumption value.

Parameters:

resource

Returns: list of tuples (interval_var, consumption_value)

abstractmethod get_task_unary_resource_interval(task: Task, unary_resource: UnaryResource) IntervalVar[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.

problem: GenericSchedulingProblem[Task, UnaryResource, CumulativeResource, NonRenewableResource]

discrete_optimization.generic_tasks_tools.solvers.cpsat.multimode module

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

Bases: OrtoolsCpSatSolver, MultimodeCpSolver[Task]

add_constraint_on_task_mode(task: Task, mode: int) list[Any][source]

Add constraint on task mode

The mode of task is fixed to mode.

Parameters:
  • task

  • mode

Returns:

resulting constraints

abstractmethod get_task_mode_is_present_variable(task: Task, mode: int) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]

Retrieve the 0-1 variable/expression telling if the mode is used for the task.

Parameters:
  • task

  • mode

Returns:

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

Bases: MultimodeCpSatSolver[Task]

Cpsat solver mixin for single mode problems.

get_task_mode_is_present_variable(task: Task, mode: int) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]

Retrieve the 0-1 variable/expression telling if the mode is used for the task.

Parameters:
  • task

  • mode

Returns:

problem: SinglemodeProblem[Task]

discrete_optimization.generic_tasks_tools.solvers.cpsat.multimode_scheduling module

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

Bases: SchedulingCpSatSolver[Task], MultimodeCpSatSolver[Task], Generic[Task]

Base class for cpsat solvers dealing with scheduling problems whose tasks durations depend only on mode.

abstractmethod get_task_mode_interval(task: Task, mode: int) IntervalVar[source]

Get the interval variable corresponding to given task and mode.

problem: MultimodeSchedulingProblem[Task]
class discrete_optimization.generic_tasks_tools.solvers.cpsat.multimode_scheduling.SinglemodeSchedulingCpSatSolver(problem: Problem, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs: Any)[source]

Bases: MultimodeSchedulingCpSatSolver[Task], SinglemodeCpSatSolver[Task]

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

abstractmethod get_task_interval(task: Task) IntervalVar[source]

Get the interval variable corresponding to given task.

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

Get the interval variable corresponding to given task and mode.

problem: SinglemodeSchedulingProblem[Task]

discrete_optimization.generic_tasks_tools.solvers.cpsat.non_renewable_resource module

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

Bases: MultimodeCpSatSolver[Task], Generic[Task, NonRenewableResource]

Base class for cpsat solvers dealing with problem with non-renewable resources.

create_non_renewable_resources_constraint(resource: NonRenewableResource)[source]

Add the constraint for a non-renewable resource to the cpsat model.

Constraint ensuring that the total demand on the given resource stay below its capacity.

problem: NonRenewableResourceProblem

discrete_optimization.generic_tasks_tools.solvers.cpsat.precedence_scheduling module

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

Bases: SchedulingCpSatSolver[Task]

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

create_precedence_constraints()[source]

Add precedence constraints to cp model.

problem: PrecedenceSchedulingProblem[Task]

discrete_optimization.generic_tasks_tools.solvers.cpsat.scheduling module

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

Bases: OrtoolsCpSatSolver, SchedulingCpSolver[Task]

Base class for most ortools/cpsat solvers handling scheduling problems.

Allows to have common code.

add_constraint_chaining_tasks(task1: Task, task2: Task) list[Any][source]

Add constraint chaining task1 with task2

task2 start == task1 end

Parameters:
  • task1

  • task2

Returns:

resulting constraints

add_constraint_on_task(task: Task, start_or_end: StartOrEnd, sign: SignEnum, time: int) list[Any][source]

Add constraint on given task start or end

task start or end must compare to time according to sign

Parameters:
  • task

  • start_or_end

  • sign

  • time

Returns:

resulting constraints

constraints_on_makespan: list[Any] | None = None

Constraints on partial makespan so that it can be considered as the objective.

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_start_or_end_variable(task: Task, start_or_end: StartOrEnd) LinearExpr | IntVar | int | int8 | uint8 | int32 | uint32 | int64 | uint64[source]

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

Parameters:
  • task

  • start_or_end

Returns:

init_model(**kwargs: Any) None[source]

Init cp model and reset stored variables if any.

remove_constraints_on_objective() None[source]

Module contents