Skip to main content

winner_determination

Function winner_determination 

Source
pub fn winner_determination(bids: &[BundleBid], agents: usize) -> Assignment
Expand description

The winning bids: at most one per agent, no task in two of them, with the highest total value; returned as the assignment of agents agents they make up.

Agents without a winning bid get an empty bundle. Bids of agents outside 0..agents are ignored. Of equally valuable selections, the first found wins, preferring each agent’s bids in the order given.

This is exact winner determination by depth-first branch and bound over agents, pruned with each remaining agent’s best bid. It is NP-hard in general: plan for at most a few dozen bids.

§Examples

use task_allocation::{AgentId, Bundle, Insertion, TaskId, auction::{BundleBid, winner_determination}};

/// A bid of `agent` on `tasks`, worth `value` in all.
fn bid(agent: usize, tasks: &[usize], value: u64) -> BundleBid {
    let mut bundle = Bundle::new();
    for (position, &task) in tasks.iter().enumerate() {
        let gain = if position == 0 { value } else { 0 };
        bundle.insert(TaskId(task), Insertion { position, gain });
    }
    BundleBid { agent: AgentId(agent), bundle }
}

let bids = [bid(0, &[0, 1], 10), bid(1, &[0], 6), bid(2, &[1], 6)];
let assignment = winner_determination(&bids, 3);

// Agents 1 and 2 together beat agent 0's pair.
assert_eq!(assignment.value(), 12);
assert_eq!(assignment.holder(TaskId(1)), Some(AgentId(2)));