Skip to main content

Timed

Struct Timed 

Source
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: R

Implementations§

Source§

impl<R: Route> Timed<R>

Source

pub fn schedule(&self, path: &[TaskId]) -> Option<Vec<Visit>>

The visits of path, in order; None when a place is unreachable or a task finishes too late. Times saturate at u64::MAX.

Trait Implementations§

Source§

impl<R: Clone> Clone for Timed<R>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R: Copy> Copy for Timed<R>

Source§

impl<R: Debug> Debug for Timed<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<R: Default> Default for Timed<R>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<R: Eq> Eq for Timed<R>

Source§

impl<R: Hash> Hash for Timed<R>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<R: PartialEq> PartialEq for Timed<R>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<R: Route> PathScore<TaskId> for Timed<R>

Source§

fn insertion_scores( &self, path: &[TaskId], task: &TaskId, each: &mut dyn FnMut(usize, Option<u64>), )

Walks each candidate path straight from path and task, without building it.

Source§

fn path_score(&self, path: &[TaskId]) -> Option<u64>

The value of executing path in order; None when the agent cannot execute it, for example because a task would miss its deadline. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.