pub fn check_diminishing<Task, V>(
valuation: &V,
tasks: &[Task],
capacity: usize,
) -> Result<(), Violation<Task>>Expand description
Checks that valuation has diminishing marginal gains over tasks, for agents that hold
at most capacity tasks.
Gains matter only on paths shorter than capacity, where the agent can still take a
task, so only those are compared.
Paths are built the way allocation algorithms build them: each task goes where
Valuation::best_insertion puts it. The check explores every build order, so it is
meant for small task sets: about tasks.len()! / (tasks.len() - capacity)! paths.
§Errors
Returns the first Violation found: a path, a task added to it, and another task whose
gain went up (or became feasible) as a result.
§Examples
use task_allocation::{Valuation, check_diminishing};
/// Pays for each task, but more once the agent is already busy: not diminishing.
struct Eager;
impl Valuation<u64> for Eager {
fn marginal_score(&self, path: &[u64], task: &u64) -> Option<u64> {
Some(task + path.len() as u64)
}
}
let violation = check_diminishing(&Eager, &[1, 2], 2).unwrap_err();
assert_eq!((violation.before, violation.after), (Some(2), Some(3)));