Skip to main content

TimedAgent

Struct TimedAgent 

Source
pub struct TimedAgent<R> { /* private fields */ }
Expand description

One CCBBA agent with temporal constraints, scheduling its bundle on a route.

§Examples

use task_allocation::ccbba::{Constraints, Optimism, TimedAgent};
use task_allocation::route::{Route, rewards};
use task_allocation::sim::{Network, Simulation};
use task_allocation::{AgentId, TaskId};

/// An agent on a line at unit speed; both tasks are at position 10 and take 5.
struct Line(u64);

impl Route for Line {
    type Place = u64;
    fn origin(&self) -> u64 { self.0 }
    fn place(&self, _task: TaskId) -> u64 { 10 }
    fn travel(&self, from: &u64, to: &u64) -> Option<u64> { Some(from.abs_diff(*to)) }
    fn duration(&self, _task: TaskId) -> u64 { 5 }
    fn reward(&self, _task: TaskId, finish: u64) -> Option<u64> {
        rewards::deadline(10, finish, 100)
    }
}

// Task 1 needs task 0, and must start 3 to 8 after it.
let mut constraints = Constraints::new(2);
constraints
    .add_timed_activity(
        &[TaskId(0), TaskId(1)],
        &[&[0, 1], &[0, 0]],
        &[&[Some(0), Some(-3)], &[Some(8), Some(0)]],
    )
    .unwrap();
let optimism = Optimism { timeout: 5, solo_attempts: 2, any_attempts: 4 };

let agents = [Line(0), Line(12)]
    .into_iter()
    .enumerate()
    .map(|(id, line)| TimedAgent::new(AgentId(id), 2, 2, 1, line, constraints.clone(), optimism))
    .collect();
let mut simulation = Simulation::new(agents, Network::default());

simulation.run_until_settled(100).expect("settles");
let starts: Vec<_> = (0..2).map(|task| simulation.agents()[0].start(TaskId(task)).unwrap()).collect();
assert!(starts[1] >= starts[0] + 3 && starts[1] <= starts[0] + 8);

Implementations§

Source§

impl<R: Route> TimedAgent<R>

Source

pub fn new( id: AgentId, agents: usize, tasks: usize, capacity: usize, route: R, constraints: Constraints, optimism: Optimism, ) -> Self

Agent id of a team of agents, scheduling tasks 0..tasks on route under constraints, and holding at most capacity of them.

§Panics

Panics when id is not below agents, or when constraints cover a different number of tasks.

Source

pub fn build_bundle(&mut self) -> usize

One round: gives up tasks whose constraints fail, timing included, runs the bundle phase within the partners’ windows, and records the starts of the tasks it holds. Returns the number of tasks added.

Source

pub fn message(&mut self) -> TimedMessage

The message this agent broadcasts now.

Source

pub fn receive(&mut self, message: &TimedMessage) -> bool

The consensus phase for one message: CBBA’s, adopting the sender’s start for every task whose claim it takes. Returns whether anything changed.

Source

pub fn can_bid(&self) -> bool

Whether the next round would change anything: what Agent::can_bid checks, or the starts of the tasks this agent holds would move.

Source§

impl<R> TimedAgent<R>

Source

pub const fn id(&self) -> AgentId

This agent’s identifier.

Source

pub const fn route(&self) -> &R

This agent’s route.

Source

pub const fn constraints(&self) -> &Constraints

The constraints this agent bids under.

Source

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

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

Source

pub fn winner(&self, task: TaskId) -> Option<AgentId>

The winner this agent believes in for task; None when it knows of no bid.

§Panics

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

Source

pub fn start(&self, task: TaskId) -> Option<u64>

The start of task’s winning bid, as this agent knows it.

§Panics

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

Trait Implementations§

Source§

impl<R: Clone> Clone for TimedAgent<R>

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<R: Debug> Debug for TimedAgent<R>

Source§

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

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

impl<R: Route> Participant for TimedAgent<R>

Source§

fn act(&mut self, _now: u64, outbox: &mut Vec<TimedMessage>)

Runs a round and broadcasts the full state, starts included.

Source§

fn receive( &mut self, _now: u64, message: &TimedMessage, _outbox: &mut Vec<TimedMessage>, ) -> bool

Runs the consensus phase for message.

Source§

fn message_bytes(message: &TimedMessage) -> u64

CBBA’s message, then every task’s start, each a tag and a time.

Source§

fn is_settled(team: &[Self], in_flight: &[&TimedMessage]) -> bool

CCBBA’s settled check, plus agreement on every start, among agents and in flight.

Source§

type Message = TimedMessage

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<R> !Freeze for TimedAgent<R>

§

impl<R> !RefUnwindSafe for TimedAgent<R>

§

impl<R> !Sync for TimedAgent<R>

§

impl<R> Forget for TimedAgent<R>

§

impl<R> Move for TimedAgent<R>

§

impl<R> Send for TimedAgent<R>
where Agent<BestInsertion<Coordinated<R>>>: Send,

§

impl<R> Unpin for TimedAgent<R>
where Agent<BestInsertion<Coordinated<R>>>: Unpin,

§

impl<R> UnsafeUnpin for TimedAgent<R>
where Agent<BestInsertion<Coordinated<R>>>: UnsafeUnpin,

§

impl<R> UnwindSafe for TimedAgent<R>
where Agent<BestInsertion<Coordinated<R>>>: 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.