pub struct Agent<V> { /* private fields */ }Expand description
One CCBBA agent: a CBBA agent whose bids respect coupled constraints.
§Examples
use task_allocation::ccbba::{Agent, Constraints, Optimism};
use task_allocation::sim::{Network, Simulation};
use task_allocation::{AgentId, TaskId, Valuation};
/// A strike (task 0) and the sensing it needs (task 1), each worth something to one agent.
struct Fixed([u64; 2]);
impl Valuation<TaskId> for Fixed {
fn marginal_score(&self, path: &[TaskId], task: &TaskId) -> Option<u64> {
path.is_empty().then_some(self.0[task.index()])
}
}
let mut constraints = Constraints::new(2);
constraints.add_activity(&[TaskId(0), TaskId(1)], &[&[0, 1], &[1, 0]]).unwrap();
let optimism = Optimism { timeout: 5, solo_attempts: 2, any_attempts: 4 };
let agents = [Fixed([9, 0]), Fixed([0, 3])]
.into_iter()
.enumerate()
.map(|(id, valuation)| Agent::new(AgentId(id), 2, 2, 1, valuation, constraints.clone(), optimism))
.collect();
let mut simulation = Simulation::new(agents, Network::default());
simulation.run_until_settled(100).expect("settles");
let assignment = simulation.assignment();
assert_eq!(assignment.holder(TaskId(0)), Some(AgentId(0)));
assert_eq!(assignment.holder(TaskId(1)), Some(AgentId(1)));
assert!(constraints.is_satisfied_by(&assignment));Implementations§
Source§impl<V: Valuation<TaskId>> Agent<V>
impl<V: Valuation<TaskId>> Agent<V>
Sourcepub fn new(
id: AgentId,
agents: usize,
tasks: usize,
capacity: usize,
valuation: V,
constraints: Constraints,
optimism: Optimism,
) -> Self
pub fn new( id: AgentId, agents: usize, tasks: usize, capacity: usize, valuation: V, constraints: Constraints, optimism: Optimism, ) -> Self
Agent id of a team of agents, bidding on tasks 0..tasks 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.
Sourcepub fn build_bundle(&mut self) -> usize
pub fn build_bundle(&mut self) -> usize
One round: gives up the tasks whose constraints fail, then runs the bundle phase. Returns the number of tasks the bundle phase added.
Sourcepub fn message(&mut self) -> Message
pub fn message(&mut self) -> Message
The message this agent broadcasts now; see cbba::Agent::message.
Sourcepub fn receive(&mut self, message: &Message) -> bool
pub fn receive(&mut self, message: &Message) -> bool
The consensus phase for one message; see cbba::Agent::receive.
Source§impl<V> Agent<V>
impl<V> Agent<V>
Sourcepub const fn constraints(&self) -> &Constraints
pub const fn constraints(&self) -> &Constraints
The constraints this agent bids under.
Sourcepub const fn bundle(&self) -> &Bundle<TaskId>
pub const fn bundle(&self) -> &Bundle<TaskId>
The tasks this agent holds, with the bid it placed on each.
Sourcepub fn winner(&self, task: TaskId) -> Option<AgentId>
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.
Sourcepub fn winning_bid(&self, task: TaskId) -> u64
pub fn winning_bid(&self, task: TaskId) -> u64
The winning bid this agent believes in for task; zero when it knows of no bid.
§Panics
Panics when task is not one of this agent’s tasks.
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>)
Gives up failing tasks, runs the bundle phase, and broadcasts the full state.
Source§fn receive(&mut self, _now: u64, message: &Message, _outbox: &mut Vec<Message>)
fn receive(&mut self, _now: u64, message: &Message, _outbox: &mut Vec<Message>)
Runs CBBA’s consensus phase for message.
Source§fn is_settled(team: &[Self], in_flight: &[&Message]) -> bool
fn is_settled(team: &[Self], in_flight: &[&Message]) -> bool
CBBA’s settled check, plus: no agent would give up a task. Then every held task’s dependencies have winners and no excluded task outbids it.