pub struct Constraints { /* private fields */ }Expand description
Assignment constraints between tasks: which tasks need others, and which exclude each other.
Tasks are grouped into activities. Within an activity, a dependency matrix D says how
each pair of tasks relates, as in Table I of Whitten, Choi, Johnson and How (2011). Entry
D[q][u], with q and u positions in the activity’s task list, is:
1: taskudepends on taskq;umay only be assigned ifqis;0: no constraint;-1:qanduare mutually exclusive; at most one of them may be assigned.
Two tasks that depend on each other must be assigned together or not at all. The diagonal is zero. Tasks outside every activity are unconstrained. The paper’s codes above one (“either of these tasks”) are not supported.
§Examples
use task_allocation::TaskId;
use task_allocation::ccbba::Constraints;
// A strike (task 0) needs a sensor (task 1), and the sensor is useless without it.
// Task 2 excludes both.
let mut constraints = Constraints::new(3);
constraints
.add_activity(
&[TaskId(0), TaskId(1), TaskId(2)],
&[&[0, 1, -1], &[1, 0, -1], &[-1, -1, 0]],
)
.unwrap();
assert_eq!(constraints.requirements(TaskId(0)).collect::<Vec<_>>(), [TaskId(1)]);
assert!(constraints.excludes(TaskId(2), TaskId(0)));Implementations§
Source§impl Constraints
impl Constraints
Sourcepub fn add_activity(
&mut self,
tasks: &[TaskId],
dependency: &[&[i8]],
) -> Result<(), ConstraintError>
pub fn add_activity( &mut self, tasks: &[TaskId], dependency: &[&[i8]], ) -> Result<(), ConstraintError>
Adds an activity: tasks, related by dependency as described on Constraints,
without timing limits.
§Errors
Returns a ConstraintError when a task is unknown or already in an activity, when
the matrix is not square with one row per task, when its diagonal is not zero, or when
an entry is not -1, 0 or 1. Nothing is added then.
Sourcepub fn add_timed_activity(
&mut self,
tasks: &[TaskId],
dependency: &[&[i8]],
timing: &[&[Option<i64>]],
) -> Result<(), ConstraintError>
pub fn add_timed_activity( &mut self, tasks: &[TaskId], dependency: &[&[i8]], timing: &[&[Option<i64>]], ) -> Result<(), ConstraintError>
Adds an activity whose dependent tasks must also start within limits of each other.
timing[q][u] is the most task q may start after task u starts, in the time unit
of the agents’ routes; negative values make q start before u; None sets no
limit. Together, u imposes on q the window start(u) - timing[u][q] to
start(u) + timing[q][u]. This is the matrix T of Whitten, Choi, Johnson and How.
§Errors
As add_activity, plus when the timing matrix is not
square with one row per task, has a diagonal other than zero or None, or limits two
tasks that do not depend on each other.
§Examples
The paper’s strike activity: the strike (task 0) and the sensing (task 1) start within 20 seconds of each other, and the damage assessment (task 2) starts at least 180 seconds after the strike and the sensing. Task 3, gathering intelligence instead, excludes all three.
use task_allocation::TaskId;
use task_allocation::ccbba::Constraints;
let mut constraints = Constraints::new(4);
constraints
.add_timed_activity(
&[TaskId(0), TaskId(1), TaskId(2), TaskId(3)],
&[&[0, 1, 1, -1], &[1, 0, 1, -1], &[0, 0, 0, -1], &[-1, -1, -1, 0]],
&[
&[Some(0), Some(20), Some(-180), None],
&[Some(20), Some(0), Some(-180), None],
&[None, None, Some(0), None],
&[None, None, None, Some(0)],
],
)
.unwrap();
// A strike starting at 100 lets the sensing start from 80 to 120, and the damage
// assessment from 280 on.
assert_eq!(constraints.window(TaskId(1), TaskId(0), 100), (Some(80), Some(120)));
assert_eq!(constraints.window(TaskId(2), TaskId(0), 100), (Some(280), None));Sourcepub fn set_opening(&mut self, task: TaskId, opening: u64)
pub fn set_opening(&mut self, task: TaskId, opening: u64)
Sets the opening of task’s time window, the earliest it may start. A
TimedAgent never starts the task earlier. Agents that conflict
over two mutually dependent tasks compare how far into their windows they start, and
the earlier one gives way.
§Panics
Panics when task is not part of the task set.
Sourcepub fn opening(&self, task: TaskId) -> u64
pub fn opening(&self, task: TaskId) -> u64
The opening of task’s time window; zero unless set.
§Panics
Panics when task is not part of the task set.
Sourcepub fn window(
&self,
task: TaskId,
other: TaskId,
start: u64,
) -> (Option<i128>, Option<i128>)
pub fn window( &self, task: TaskId, other: TaskId, start: u64, ) -> (Option<i128>, Option<i128>)
The window other, starting at start, imposes on task: the earliest and the
latest start, each None when unbounded. Only a task that depends on other gets a
window; otherwise both are None. Bounds are not clamped at zero.
Sourcepub fn starts_agree(
&self,
task: TaskId,
start: u64,
other: TaskId,
other_start: u64,
) -> bool
pub fn starts_agree( &self, task: TaskId, start: u64, other: TaskId, other_start: u64, ) -> bool
Whether starts at start for task and other_start for other respect the
timing limits between them, in both directions.
Sourcepub fn depends_on(&self, task: TaskId, other: TaskId) -> bool
pub fn depends_on(&self, task: TaskId, other: TaskId) -> bool
Whether task depends on other.
Sourcepub fn requirements(&self, task: TaskId) -> impl Iterator<Item = TaskId> + '_
pub fn requirements(&self, task: TaskId) -> impl Iterator<Item = TaskId> + '_
The tasks task depends on: it may only be assigned if all of them are.
Sourcepub fn exclusions(&self, task: TaskId) -> impl Iterator<Item = TaskId> + '_
pub fn exclusions(&self, task: TaskId) -> impl Iterator<Item = TaskId> + '_
The tasks mutually exclusive with task.
Sourcepub fn is_mutual(&self, task: TaskId) -> bool
pub fn is_mutual(&self, task: TaskId) -> bool
Whether task depends on a task that also depends on it. Agents may bid on such a task
optimistically, before its partners have winners.
Sourcepub fn is_satisfied_by(&self, assignment: &Assignment) -> bool
pub fn is_satisfied_by(&self, assignment: &Assignment) -> bool
Whether assignment meets every constraint: each assigned task’s requirements are
assigned too, and no two mutually exclusive tasks are both assigned.