pub fn sequential_greedy<V>(
agents: &[V],
tasks: usize,
capacity: usize,
) -> AssignmentExpand description
The sequential greedy assignment of tasks 0..tasks to agents, each holding at most
capacity tasks.
Each round considers every agent with room left and every unassigned task, and gives the task with the highest marginal gain to its agent, at its best insertion. Ties go to the smaller agent, then to the smaller task. Tasks with gain zero are never assigned. The result is conflict-free.
Each round asks every agent about every unassigned task:
O(tasks² × agents) calls to Valuation::best_insertion overall.
§Examples
use task_allocation::{AgentId, TaskId, Valuation, centralized::sequential_greedy};
/// Values every task at `reward`, for at most one task.
struct Single { reward: [u64; 2] }
impl Valuation<TaskId> for Single {
fn marginal_score(&self, path: &[TaskId], task: &TaskId) -> Option<u64> {
path.is_empty().then_some(self.reward[task.index()])
}
}
let agents = [Single { reward: [5, 4] }, Single { reward: [6, 1] }];
let assignment = sequential_greedy(&agents, 2, 1);
assert_eq!(assignment.holder(TaskId(0)), Some(AgentId(1)));
assert_eq!(assignment.holder(TaskId(1)), Some(AgentId(0)));
assert_eq!(assignment.value(), 10);