pub struct Agent<V> { /* private fields */ }Expand description
One ACBBA agent: its valuation, its bundle, and its view of every task’s winner.
§Examples
use task_allocation::acbba::Agent;
use task_allocation::sim::{Network, Simulation};
use task_allocation::{AgentId, TaskId, Valuation};
/// Values task `t` at `10 + t` for agent 0 and `20 - t` for agent 1, minus 2 per task held.
struct Skewed(u64);
impl Valuation<TaskId> for Skewed {
fn marginal_score(&self, path: &[TaskId], task: &TaskId) -> Option<u64> {
let task = task.index() as u64;
let base = if self.0 == 0 { 10 + task } else { 20 - task };
base.checked_sub(2 * path.len() as u64)
}
}
let agents = (0..2).map(|id| Agent::new(AgentId(id), 4, 2, Skewed(id as u64))).collect();
let network = Network { seed: 1, max_delay: 3, ..Network::default() };
let mut simulation = Simulation::new(agents, network);
simulation.run_until_settled(200).expect("goes quiet in agreement");
assert!(simulation.assignment().is_conflict_free());Implementations§
Source§impl<V: Valuation<TaskId>> Agent<V>
impl<V: Valuation<TaskId>> Agent<V>
Sourcepub fn new(id: AgentId, tasks: usize, capacity: usize, valuation: V) -> Self
pub fn new(id: AgentId, tasks: usize, capacity: usize, valuation: V) -> Self
Agent id, bidding on tasks 0..tasks and holding at most capacity of them.
Times count as equal only when identical (epsilon of one tick), and the agent never
re-announces on its own.
Sourcepub const fn with_rules(self, rules: Rules) -> Self
pub const fn with_rules(self, rules: Rules) -> Self
This agent, following the decision table rules.
Sourcepub const fn with_printed_ties(self) -> Self
pub const fn with_printed_ties(self) -> Self
This agent, leaving ties between two other winners as the published tables do, in rows 9 and 27, instead of giving them to the smaller winner. With integer scores, two neighbors that disagree about such a tie can answer each other forever.
Sourcepub const fn with_epsilon(self, epsilon: u64) -> Self
pub const fn with_epsilon(self, epsilon: u64) -> Self
This agent, counting times closer than epsilon ticks as equal.
Sourcepub fn announce_every(self, period: u64) -> Self
pub fn announce_every(self, period: u64) -> Self
This agent, re-announcing its entry for every task every period ticks, with its own
winning bids confirmed at the current time. This is not part of the published
algorithm.
It makes up for lost messages, and it lets the true winner of a task override a stale claim that looks newer: under the table’s time rules, a lower but newer bid beats a higher but older one, so a bid an agent made and later released can outlive the release on a distant agent, even without losses.
§Panics
Panics when period is zero.
Sourcepub fn build_bundle(&mut self, now: u64) -> Vec<Message>
pub fn build_bundle(&mut self, now: u64) -> Vec<Message>
The bundle phase at time now: adds the most valuable tasks this agent can win until
its bundle is full or nothing is left to win, and returns the announcements of the
new bids.
Each call counts as a round for quiet_rounds.
Sourcepub const fn quiet_rounds(&self) -> u64
pub const fn quiet_rounds(&self) -> u64
How many bundle phases in a row this agent’s winners and bids stayed the same; bid times alone do not count as a change.
Sourcepub const fn is_locally_settled(&self, span: u64) -> bool
pub const fn is_locally_settled(&self, span: u64) -> bool
This agent’s own guess that the team has settled: its winners and bids stayed the
same for at least span bundle phases, the separation time of the 2011 paper
(pp. 8–9). A heuristic that can be wrong both ways; see
cbba::Agent::is_locally_settled.
Trait Implementations§
Source§impl<V: Valuation<TaskId>> Participant for Agent<V>
impl<V: Valuation<TaskId>> Participant for Agent<V>
Source§fn act(&mut self, now: u64, outbox: &mut Vec<Message>)
fn act(&mut self, now: u64, outbox: &mut Vec<Message>)
Runs the bundle phase and announces the new bids, plus the whole view when a
re-announcement is due. Of everything queued this round about one task, only the
last message goes out. Under Rules::Gnc2010, a queued claim that names this
agent for a task it no longer holds is dropped, reading section IV.A of the paper:
the outgoing messages “accurately represent the state of the current bundle build”.
Source§fn receive(
&mut self,
now: u64,
message: &Message,
outbox: &mut Vec<Message>,
) -> bool
fn receive( &mut self, now: u64, message: &Message, outbox: &mut Vec<Message>, ) -> bool
Resolves message and rebroadcasts right away. A change of the task’s winner or
bid counts as a change, as does a released task; a moved bid time alone does not.
Source§fn message_bytes(_message: &Message) -> u64
fn message_bytes(_message: &Message) -> u64
The sender, the task, and the claim: winner, bid and time.
Source§fn is_settled(team: &[Self], in_flight: &[&Message]) -> bool
fn is_settled(team: &[Self], in_flight: &[&Message]) -> bool
Every agent believes in the same winner and bid for every task, every bundle matches, no bundle phase would add a task, and every message in flight names the agreed winner and bid. Such messages can only move bid times, never winners, so the assignment is final even while re-announcements keep the network busy. A lost message can leave a quiet network split, so quiet alone is not enough.