Scheduling Constraints

The following is a list of scheduling specific constructs that are available.

class Numberjack.Task(arg1=None, arg2=None, arg3=None)

The Task class allows for simplified modeling of tasks in scheduling applications. It encapsulates the earliest start time, latest end time (makespan), and duration. The following tables shows example calls to the constructor which results in different kinds of matrices.

Task()  # creates a Task with an earliest start time of 0, latest end
        # time of 1, and duration 1
Task(ub)  # creates a Task with an earliest start time of 0, latest end
          # time of 'ub', and duration 1
Task(ub, dur)  # creates a Task with an earliest start time of 0,
               # latest end time of 'ub', and duration 'dur'
Task(lb, ub, dur)  # creates a Task with an earliest start time of 0,
                   # latest end time of 'ub', and duration 'dur'

When the model is solved, Numberjack.Expression.get_value() returns the start time of the task.

__lt__(pred)

Creates a precedence expression on the task. Can be used to specify precedence between two tasks or that a task has finished before a certain time.

Parameters:pred – if pred is an int then constrains that the task is finished by pred, if pred is another Task instance, then creates a top-level Precedence constraint.
domain(solver=None)

Returns a string representing the current domain of the expression.

Parameters:solver (NBJ_STD_Solver) – If specified, the solver for which this expression has been loaded. If not specified, the solver that has most recenlty loaded the expression will be used.
get_domain(solver=None)

Creates a new Domain instance representing the current domain of the expression.

Parameters:solver (NBJ_STD_Solver) – If specified, the solver from which the domain will be sourced, if None then the most recently loaded solver is used.
Returns:The current domain of the expression.
Return type:Domain
get_max(solver=None)

Current upper bound of variable.

Parameters:solver (NBJ_STD_Solver) – If specified, the solver from which the upper bound will be sourced, if None then the most recently loaded solver is used.
Returns:The current upper bound of the variable.
Return type:The same as the original domain, either int, float, or str.
get_min(solver=None)

Current lower bound of the expression.

Parameters:solver (NBJ_STD_Solver) – If specified, the solver from which the lower bound will be sourced, if None then the most recently loaded solver is used.
Returns:The current lower bound of the expression.
Return type:The same as the original domain, either int, float, or str.
get_size(solver=None)

The current size of the expression’s domain.

Parameters:solver (NBJ_STD_Solver) – If specified, the solver from which the domain size will be sourced, if None then the most recently loaded solver is used.
Returns:The size of the expression’s domain.
Return type:int
get_solver()

Returns the solver with which this expression was last loaded.

Returns:The last loaded solver, or None if it has not been loaded anywhere.
Return type:NBJ_STD_Solver
get_value(solver=None)

The current value of the expression. Should be used to retrieve the assigned value of a variable and the value of expressions like the objective function.

In the case of variables, it may not be passed in to the solver if it is not involved in a non-trivial constraint. For example, x <= 1, x will not get added (by this constraint alone) if it has a upper bound which is less or equal to 1. The variable’s lower bound will be returned as the value in this case.

Parameters:solver (NBJ_STD_Solver) – If specified, the solver from which the value will be sourced, if None then the most recently loaded solver is used.
Returns:The current value of the expression.
Return type:The same as the original domain, either int, float, or str.
initial()

Returns a string representing the initial domain of the expression. For example:

var1 = Variable(0, 10)
print var1.initial()
>>> x0 in {0..10}
Returns:A String representation of original expression definition
Return type:str
name()

The name of the variable or the operator if this is an expression.

solution(solver=None)

Deprecated since version 1.1: Instead you should use get_value(), this function is equivalent to calling str() on that.

Returns a string containing the solution value of the expression. For a native representation of the solution value, use get_value()

Parameters:solver (NBJ_STD_Solver) – If specified, the solver from which the solution will be sourced, if None then the most recently loaded solver is used.
Returns:String representation of the expressions solution.
Return type:str
class Numberjack.Precedence(task_i, task_j, dur)

Precedence constraint enforces a certain gap between the start time of two tasks. Equivalent to task_i + duration <= task_j.

Parameters:
  • task_i (Task) – the first task.
  • task_j (Task) – the second task.
  • dur (int) – the gap to maintain between the two tasks.
class Numberjack.NoOverlap(task_i, task_j, dur_i=None, dur_j=None)

Binary disjunctive constraint enforces that two tasks do not overlap. Equivalent to (task_i + duration_i <= task_j) | (task_j + duration_j <= task_i) .

Parameters:
  • task_i (Task) – the first task.
  • task_j (Task) – the second task.
  • dur_i (int) – the duration of the first task, if None then task_i.duration will be used.
  • dur_j (int) – the duration of the second task, if None then task_j.duration will be used.
class Numberjack.UnaryResource(arg=[], distance=0)

Unary resource constraint ensures that only one of the specified list of tasks are running at each time point. An optional distance between tasks can be specified also.

Parameters:
  • arg – a list of Task instances.
  • distance (int) – optional distance between tasks.
add(new_task)

Add an additional task to the existing list of tasks obeying this unary resource.

Parameters:new_task (Task) – the additional task to include.

Previous topic

Global Constraints Reference

Next topic

Model and Solve

This Page