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. [Bid warping](cbba::warp) extends it to gains
20//!   that do not diminish.
21//! - [`ccbba`]: CBBA for coupled tasks that need or exclude each other, optionally with
22//!   timing limits between their starts on timed routes.
23//! - [`acbba`]: asynchronous CBBA, experimental. Agents bid and resolve conflicts on their
24//!   own schedule, one task per message, and only pass on what is new; it does not settle
25//!   reliably yet.
26//! - [`bwtc`]: the task consensus of bid-warped CBBA, experimental. Agents announce what
27//!   changed, withdrawals included, with a timestamp per bidder and task, so a withdrawn
28//!   bid cannot come back; for networks that deliver every message.
29//! - [`sim`]: a deterministic simulated network with delays, losses and partitions, to run
30//!   teams on, counting the messages and bytes they spend and how many were useful.
31//! - [`auction`]: auction baselines with a central auctioneer: sequential single-item
32//!   auctions, and combinatorial auctions with exact winner determination.
33//! - [`centralized`]: reference allocations with full knowledge of every valuation: the
34//!   sequential greedy assignment and the exhaustive optimum for small instances.
35//!
36//! Agents and tasks are dense indices, [`AgentId`] and [`TaskId`]. Scores are `u64`, so
37//! every agent compares bids exactly the same way; ties go to the smaller identifier.
38//!
39//! The crate is `no_std` and needs `alloc`.
40//!
41//! ## Example
42//!
43//! ```
44//! use task_allocation::{AgentId, TaskId, Valuation, centralized::sequential_greedy};
45//!
46//! /// A rover on a line: a task at `position` is worth 100 minus the distance from the
47//! /// rover's last task, and each rover takes at most two tasks.
48//! struct Rover {
49//!     start: u64,
50//! }
51//!
52//! const TASKS: [u64; 3] = [10, 40, 90];
53//!
54//! impl Valuation<TaskId> for Rover {
55//!     fn marginal_score(&self, path: &[TaskId], task: &TaskId) -> Option<u64> {
56//!         let from = path.last().map_or(self.start, |last| TASKS[last.index()]);
57//!
58//!         100_u64.checked_sub(from.abs_diff(TASKS[task.index()]))
59//!     }
60//! }
61//!
62//! let rovers = [Rover { start: 0 }, Rover { start: 100 }];
63//! let assignment = sequential_greedy(&rovers, TASKS.len(), 2);
64//!
65//! assert!(assignment.is_conflict_free());
66//! assert_eq!(assignment.holder(TaskId(0)), Some(AgentId(0)));
67//! assert_eq!(assignment.holder(TaskId(2)), Some(AgentId(1)));
68//! ```
69//!
70//! Repository: <https://github.com/sunsided/task-allocation>
71
72#![no_std]
73#![forbid(unsafe_code)]
74
75extern crate alloc;
76
77pub mod acbba;
78mod assignment;
79pub mod auction;
80mod bundle;
81pub mod bwtc;
82pub mod cbba;
83pub mod ccbba;
84pub mod centralized;
85mod id;
86mod quiet;
87pub mod route;
88pub mod sim;
89mod valuation;
90
91pub use assignment::Assignment;
92pub use bundle::Bundle;
93pub use id::{AgentId, TaskId};
94pub use valuation::{BestInsertion, Insertion, PathScore, Valuation, Violation, check_diminishing};
95
96/// Doctests for the code examples in README.md (not part of the API).
97#[cfg(doctest)]
98#[doc = include_str!("../README.md")]
99mod readme_doctests {}