Skip to main content

task_allocation/cbba/
cadence.rs

1//! When an agent broadcasts: every round, or only after its winner tables change.
2//!
3//! CBBA as published has every agent broadcast its state every round. Most of those
4//! messages repeat what the neighbors already know: once a team is close to agreement, few
5//! entries change per round. [`Cadence::OnChange`] skips a round's broadcast when the
6//! agent's winners and bids are the same as in its last message, following the trigger of
7//! Sao, Ho, Bhore and Sujit, "Event Driven CBBA with Reduced Communication" (ICUAS 2025,
8//! <https://arxiv.org/abs/2509.06481>), which analyzes it for synchronous rounds.
9//!
10//! The trigger looks at winners and bids only, not at the clocks: every message advances
11//! its sender's clock, so two neighbors that answered each other's clock changes would
12//! never fall silent.
13//!
14//! A skipped broadcast is never repeated by itself. A lost message, or a neighbor that was
15//! out of reach when the tables last changed, then stays uninformed until something changes
16//! again; `refresh` sends the unchanged state at least every that many rounds, so that a
17//! team on a lossy or partitioned network still settles.
18
19use super::Agent;
20use crate::id::TaskId;
21use crate::valuation::Valuation;
22
23/// When an agent broadcasts its state.
24#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
25pub enum Cadence {
26    /// Every round, as CBBA is published.
27    #[default]
28    EveryRound,
29
30    /// Only in rounds where the agent's winners or bids differ from its last message, and,
31    /// with `refresh`, at least every that many rounds.
32    OnChange {
33        /// The most rounds between two broadcasts, after which the unchanged state is sent
34        /// anyway; `None` sets no limit, which only suits networks that lose no messages
35        /// and do not partition. One broadcasts every round.
36        refresh: Option<u64>,
37    },
38}
39
40impl<V: Valuation<TaskId>> Agent<V> {
41    /// This agent, broadcasting as `cadence` says.
42    ///
43    /// # Panics
44    ///
45    /// Panics when `cadence` refreshes after zero rounds.
46    #[must_use]
47    pub const fn with_cadence(mut self, cadence: Cadence) -> Self {
48        assert!(
49            !matches!(cadence, Cadence::OnChange { refresh: Some(0) }),
50            "the refresh interval must be positive"
51        );
52        self.cadence = cadence;
53        self
54    }
55
56    /// Whether this round calls for a broadcast under the agent's [`Cadence`]. Call it once
57    /// per round, after the bundle phase; a round without a broadcast counts towards the
58    /// refresh interval.
59    pub fn broadcast_due(&mut self) -> bool {
60        let Cadence::OnChange { refresh } = self.cadence else {
61            return true;
62        };
63
64        let due = self.claims != self.sent
65            || refresh.is_some_and(|rounds| self.silent_rounds + 1 >= rounds);
66        if !due {
67            self.silent_rounds += 1;
68        }
69
70        due
71    }
72}