pub struct Timed<R>(pub R);Expand description
A PathScore from a Route: the sum of the rewards along the path, or None when a
place is unreachable or a task finishes too late.
§Examples
use task_allocation::route::{Route, Timed, rewards};
use task_allocation::{BestInsertion, PathScore, TaskId, Valuation};
/// A rover on a line, at one meter per second, with three sites.
struct Line;
const SITES: [u64; 3] = [10, 40, 90];
impl Route for Line {
type Place = u64;
fn origin(&self) -> u64 { 0 }
fn place(&self, task: TaskId) -> u64 { SITES[task.index()] }
fn travel(&self, from: &u64, to: &u64) -> Option<u64> { Some(from.abs_diff(*to)) }
fn duration(&self, _task: TaskId) -> u64 { 5 }
/// Each site is worth 100 if done within 60 seconds.
fn reward(&self, _task: TaskId, finish: u64) -> Option<u64> {
rewards::deadline(100, finish, 60)
}
}
let route = Timed(Line);
let visits = route.schedule(&[TaskId(0), TaskId(1)]).unwrap();
assert_eq!((visits[1].arrival, visits[1].finish), (45, 50));
// The third site is too far to make the deadline.
assert_eq!(route.path_score(&[TaskId(2)]), None);
// Visiting the second site after the first still makes its deadline.
let valuation = BestInsertion(Timed(Line));
assert_eq!(valuation.marginal_score(&[TaskId(0)], &TaskId(1)), Some(100));Tuple Fields§
§0: RImplementations§
Trait Implementations§
impl<R: Copy> Copy for Timed<R>
impl<R: Eq> Eq for Timed<R>
impl<R: PartialEq> StructuralPartialEq for Timed<R>
Auto Trait Implementations§
impl<R> Forget for Timed<R>
impl<R> Freeze for Timed<R>where
R: Freeze,
impl<R> Move for Timed<R>
impl<R> RefUnwindSafe for Timed<R>where
R: RefUnwindSafe,
impl<R> Send for Timed<R>where
R: Send,
impl<R> Sync for Timed<R>where
R: Sync,
impl<R> Unpin for Timed<R>where
R: Unpin,
impl<R> UnsafeUnpin for Timed<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for Timed<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more