Skip to main content

Valuation

Trait Valuation 

Source
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 task to path.
  • None means the agent cannot take the task on top of path, for example because it would miss a deadline or exceed a capacity. An agent places no bid on such a task.
  • best_insertion and marginal_score agree: 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§

Source

fn marginal_score(&self, bundle: &[Task], task: &Task) -> Option<u64>

The score of adding task to the agent’s current bundle; higher is better, and None means the agent cannot take the task.

bundle is the agent’s path: the tasks it holds, in execution order.

Provided Methods§

Source

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".

Implementations on Foreign Types§

Source§

impl<Task, V: Valuation<Task> + ?Sized> Valuation<Task> for &V

Source§

fn marginal_score(&self, bundle: &[Task], task: &Task) -> Option<u64>

Source§

fn best_insertion(&self, path: &[Task], task: &Task) -> Option<Insertion>

Implementors§

Source§

impl<Task: Clone, S: PathScore<Task>> Valuation<Task> for BestInsertion<S>