Skip to main content

Crate task_allocation

Crate task_allocation 

Source
Expand description

§Task allocation

Decentralized multi-agent task allocation: agents decide among themselves who does which task, exchanging bids whenever they can communicate, without a central authority.

§Building blocks

  • Valuation: what a task is worth to one agent, given the tasks it already holds. Implement it directly, or score whole paths with PathScore and wrap them in BestInsertion. check_diminishing tests that gains diminish, which the consensus algorithms’ guarantees rely on.
  • Bundle: the tasks one agent holds, in the order it took them on and in execution order, built greedily from marginal gains.
  • Assignment: one bundle per agent, the result of every allocation algorithm.
  • route: a ready-made path score for agents that travel between task sites, with service windows and rewards that depend on the finish time.
  • cbba: the consensus-based bundle algorithm. Each cbba::Agent builds its bundle, broadcasts its view of every task’s winner, and merges what it hears, until the team agrees on a conflict-free assignment. Bid warping extends it to gains that do not diminish.
  • ccbba: CBBA for coupled tasks that need or exclude each other, optionally with timing limits between their starts on timed routes.
  • acbba: asynchronous CBBA, experimental. Agents bid and resolve conflicts on their own schedule, one task per message, and only pass on what is new; it does not settle reliably yet.
  • bwtc: the task consensus of bid-warped CBBA, experimental. Agents announce what changed, withdrawals included, with a timestamp per bidder and task, so a withdrawn bid cannot come back; for networks that deliver every message.
  • sim: a deterministic simulated network with delays, losses and partitions, to run teams on, counting the messages and bytes they spend and how many were useful.
  • auction: auction baselines with a central auctioneer: sequential single-item auctions, and combinatorial auctions with exact winner determination.
  • centralized: reference allocations with full knowledge of every valuation: the sequential greedy assignment and the exhaustive optimum for small instances.

Agents and tasks are dense indices, AgentId and TaskId. Scores are u64, so every agent compares bids exactly the same way; ties go to the smaller identifier.

The crate is no_std and needs alloc.

§Example

use task_allocation::{AgentId, TaskId, Valuation, centralized::sequential_greedy};

/// A rover on a line: a task at `position` is worth 100 minus the distance from the
/// rover's last task, and each rover takes at most two tasks.
struct Rover {
    start: u64,
}

const TASKS: [u64; 3] = [10, 40, 90];

impl Valuation<TaskId> for Rover {
    fn marginal_score(&self, path: &[TaskId], task: &TaskId) -> Option<u64> {
        let from = path.last().map_or(self.start, |last| TASKS[last.index()]);

        100_u64.checked_sub(from.abs_diff(TASKS[task.index()]))
    }
}

let rovers = [Rover { start: 0 }, Rover { start: 100 }];
let assignment = sequential_greedy(&rovers, TASKS.len(), 2);

assert!(assignment.is_conflict_free());
assert_eq!(assignment.holder(TaskId(0)), Some(AgentId(0)));
assert_eq!(assignment.holder(TaskId(2)), Some(AgentId(1)));

Repository: https://github.com/sunsided/task-allocation

Modules§

acbba
Asynchronous CBBA (ACBBA): agents build bundles and resolve conflicts on their own schedule, exchanging one task at a time, and only pass on what is new.
auction
Auction baselines: sequential single-item auctions and combinatorial auctions.
bwtc
The task consensus of bid-warped CBBA (BW-TC): agents bid as in CBBA, but exchange only what changed, and announce every bid they withdraw.
cbba
The consensus-based bundle algorithm (CBBA).
ccbba
Coupled-constraint CBBA (CCBBA): CBBA for tasks that need, or exclude, each other.
centralized
Centralized reference allocations, computed with full knowledge of every agent’s valuation.
route
Timed routes: a ready-made path score for agents that travel between task sites.
sim
A deterministic simulated network for running teams of agents: seeded delays, losses, topologies and partitions.

Structs§

AgentId
Identifies an agent by its index in the team, starting at zero.
Assignment
Which agent holds which tasks: one Bundle per agent, indexed by AgentId.
BestInsertion
A Valuation that tries every insertion position of a PathScore and keeps the best.
Bundle
The tasks an agent holds, in bundle order and in path order.
Insertion
Where a task goes in an agent’s path, and what it adds there.
TaskId
Identifies a task by its index in the task set, starting at zero.
Violation
A counterexample to diminishing marginal gains: adding added to path raised the gain of task.

Traits§

PathScore
The value of a whole path: the tasks an agent holds, in execution order.
Valuation
An agent’s valuation of tasks, used to place bids.

Functions§

check_diminishing
Checks that valuation has diminishing marginal gains over tasks, for agents that hold at most capacity tasks.