Skip to main content

Agent

Struct Agent 

Source
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>

Source

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.

Source

pub const fn with_rules(self, rules: Rules) -> Self

This agent, following the decision table rules.

Source

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.

Source

pub const fn with_epsilon(self, epsilon: u64) -> Self

This agent, counting times closer than epsilon ticks as equal.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn can_bid(&self) -> bool

Whether the bundle phase would add a task now.

Source

pub fn receive(&mut self, now: u64, message: &Message) -> Vec<Message>

Resolves message, arriving at time now, and returns what to rebroadcast.

Messages from this agent itself and about unknown tasks are ignored.

Source§

impl<V> Agent<V>

Source

pub const fn id(&self) -> AgentId

This agent’s identifier.

Source

pub const fn valuation(&self) -> &V

This agent’s valuation.

Source

pub const fn bundle(&self) -> &Bundle<TaskId>

The tasks this agent holds, with the bid it placed on each.

Source

pub fn claim(&self, task: TaskId) -> Claim

This agent’s entry for task.

§Panics

Panics when task is not one of this agent’s tasks.

Source

pub fn is_consistent(&self) -> bool

Whether this agent’s bundle holds exactly the tasks it believes it wins.

Trait Implementations§

Source§

impl<V: Clone> Clone for Agent<V>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V: Debug> Debug for Agent<V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<V: Valuation<TaskId>> Participant for Agent<V>

Source§

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

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

The sender, the task, and the claim: winner, bid and time.

Source§

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.

Source§

type Message = Message

What the agent broadcasts.
Source§

fn id(&self) -> AgentId

The agent’s identifier.
Source§

fn bundle(&self) -> &Bundle<TaskId>

The tasks the agent holds now.

Auto Trait Implementations§

§

impl<V> Forget for Agent<V>

§

impl<V> Freeze for Agent<V>
where V: Freeze,

§

impl<V> Move for Agent<V>

§

impl<V> RefUnwindSafe for Agent<V>
where V: RefUnwindSafe,

§

impl<V> Send for Agent<V>
where V: Send,

§

impl<V> Sync for Agent<V>
where V: Sync,

§

impl<V> Unpin for Agent<V>
where V: Unpin,

§

impl<V> UnsafeUnpin for Agent<V>
where V: UnsafeUnpin,

§

impl<V> UnwindSafe for Agent<V>
where V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.