pub trait Valuation<Task> {
// Required method
fn marginal_score(&self, bundle: &[Task], task: &Task) -> Option<u64>;
// Provided method
fn best_insertion(&self, path: &[Task], task: &Task) -> Option<Insertion> { ... }
}Expand description
An agent’s valuation of tasks, used to place bids.
§Contract
- Higher scores are better. A score is a marginal gain: how much the agent’s value grows
when it adds
tasktopath. Nonemeans the agent cannot take the task on top ofpath, for example because it would miss a deadline or exceed a capacity. An agent places no bid on such a task.best_insertionandmarginal_scoreagree: the insertion’s gain is the marginal score.- Valuations are deterministic: the same path and task always give the same score. Agents that disagree on scores cannot agree on winners.
§Examples
A rover that collects a fixed reward for each task it finishes before the task’s deadline, working through its path in order:
use task_allocation::Valuation;
struct Task { duration: u64, deadline: u64, reward: u64 }
struct Rover;
impl Valuation<Task> for Rover {
fn marginal_score(&self, path: &[Task], task: &Task) -> Option<u64> {
let busy_until: u64 = path.iter().map(|held| held.duration).sum();
(busy_until + task.duration <= task.deadline).then_some(task.reward)
}
}
let late = Task { duration: 50, deadline: 60, reward: 4 };
let early = Task { duration: 20, deadline: 40, reward: 9 };
assert_eq!(Rover.marginal_score(&[], &early), Some(9));
assert_eq!(Rover.marginal_score(&[late], &early), None);Required Methods§
Provided Methods§
Sourcefn best_insertion(&self, path: &[Task], task: &Task) -> Option<Insertion>
fn best_insertion(&self, path: &[Task], task: &Task) -> Option<Insertion>
Where task goes in path, and what it adds there; None when the agent cannot
take it.
The default appends the task to the end of the path and scores it with
marginal_score. Override it when the position matters,
or use BestInsertion.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".