# Scheduling Constraints¶

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

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. The current domain of the expression. 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. The current upper bound of the variable. 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. The current lower bound of the expression. 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. The size of the expression’s domain. 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. 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. The current value of the expression. 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 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. String representation of the expressions solution. str

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

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.