Skip to main content

task_allocation/
lib.rs

1//! # Task allocation
2//!
3//! Decentralized multi-agent task allocation: agents decide among themselves who does
4//! which task, exchanging bids whenever they can communicate, without a central authority.
5//!
6//! ## Building blocks
7//!
8//! - [`Valuation`]: what a task is worth to one agent, given the tasks it already holds.
9//!   Implement it directly, or score whole paths with [`PathScore`] and wrap them in
10//!   [`BestInsertion`]. [`check_diminishing`] tests that gains diminish, which the
11//!   consensus algorithms' guarantees rely on.
12//! - [`Bundle`]: the tasks one agent holds, in the order it took them on and in execution
13//!   order, built greedily from marginal gains.
14//! - [`Assignment`]: one bundle per agent, the result of every allocation algorithm.
15//! - [`route`]: a ready-made path score for agents that travel between task sites, with
16//!   service windows and rewards that depend on the finish time.
17//! - [`cbba`]: the consensus-based bundle algorithm. Each [`cbba::Agent`] builds its bundle,
18//!   broadcasts its view of every task's winner, and merges what it hears, until the team
19//!   agrees on a conflict-free assignment.
20//! - [`ccbba`]: CBBA for coupled tasks that need or exclude each other, optionally with
21//!   timing limits between their starts on timed routes.
22//! - [`sim`]: a deterministic simulated network with delays, losses and partitions, to run
23//!   teams on.
24//! - [`auction`]: auction baselines with a central auctioneer: sequential single-item
25//!   auctions, and combinatorial auctions with exact winner determination.
26//! - [`centralized`]: reference allocations with full knowledge of every valuation: the
27//!   sequential greedy assignment and the exhaustive optimum for small instances.
28//!
29//! Agents and tasks are dense indices, [`AgentId`] and [`TaskId`]. Scores are `u64`, so
30//! every agent compares bids exactly the same way; ties go to the smaller identifier.
31//!
32//! The crate is `no_std` and needs `alloc`.
33//!
34//! ## Example
35//!
36//! ```
37//! use task_allocation::{AgentId, TaskId, Valuation, centralized::sequential_greedy};
38//!
39//! /// A rover on a line: a task at `position` is worth 100 minus the distance from the
40//! /// rover's last task, and each rover takes at most two tasks.
41//! struct Rover {
42//!     start: u64,
43//! }
44//!
45//! const TASKS: [u64; 3] = [10, 40, 90];
46//!
47//! impl Valuation<TaskId> for Rover {
48//!     fn marginal_score(&self, path: &[TaskId], task: &TaskId) -> Option<u64> {
49//!         let from = path.last().map_or(self.start, |last| TASKS[last.index()]);
50//!
51//!         100_u64.checked_sub(from.abs_diff(TASKS[task.index()]))
52//!     }
53//! }
54//!
55//! let rovers = [Rover { start: 0 }, Rover { start: 100 }];
56//! let assignment = sequential_greedy(&rovers, TASKS.len(), 2);
57//!
58//! assert!(assignment.is_conflict_free());
59//! assert_eq!(assignment.holder(TaskId(0)), Some(AgentId(0)));
60//! assert_eq!(assignment.holder(TaskId(2)), Some(AgentId(1)));
61//! ```
62//!
63//! Repository: <https://github.com/sunsided/task-allocation>
64
65#![no_std]
66#![forbid(unsafe_code)]
67
68extern crate alloc;
69
70mod assignment;
71pub mod auction;
72mod bundle;
73pub mod cbba;
74pub mod ccbba;
75pub mod centralized;
76mod id;
77pub mod route;
78pub mod sim;
79mod valuation;
80
81pub use assignment::Assignment;
82pub use bundle::Bundle;
83pub use id::{AgentId, TaskId};
84pub use valuation::{BestInsertion, Insertion, PathScore, Valuation, Violation, check_diminishing};
85
86/// Doctests for the code examples in README.md (not part of the API).
87#[cfg(doctest)]
88#[doc = include_str!("../README.md")]
89mod readme_doctests {}