Skip to main content

BestInsertion

Struct BestInsertion 

Source
pub struct BestInsertion<S>(pub S);
Expand description

A Valuation that tries every insertion position of a PathScore and keeps the best.

The marginal gain is the difference between the path’s value with and without the new task. A task that lowers the path’s value scores zero, which never wins a bid. Of equally good positions the earliest wins.

Each call scores path.len() + 1 candidate paths and allocates one scratch path.

§Examples

use task_allocation::{BestInsertion, Insertion, PathScore, Valuation};

/// Visits points on a line, starting at 0: 50 per point, minus the distance traveled.
struct Walker;

impl PathScore<i64> for Walker {
    fn path_score(&self, path: &[i64]) -> Option<u64> {
        let mut at: i64 = 0;
        let mut traveled = 0;

        for &point in path {
            traveled += at.abs_diff(point);
            at = point;
        }

        (50 * path.len() as u64).checked_sub(traveled)
    }
}

let walker = BestInsertion(Walker);

// Visiting 5 on the way to 10 adds no travel, so it gains the full 50.
assert_eq!(
    walker.best_insertion(&[10], &5),
    Some(Insertion { position: 0, gain: 50 })
);

Tuple Fields§

§0: S

Trait Implementations§

Source§

impl<S: Clone> Clone for BestInsertion<S>

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<S: Copy> Copy for BestInsertion<S>

Source§

impl<S: Debug> Debug for BestInsertion<S>

Source§

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

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

impl<S: Default> Default for BestInsertion<S>

Source§

fn default() -> Self

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

impl<S: Eq> Eq for BestInsertion<S>

Source§

impl<S: Hash> Hash for BestInsertion<S>

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<S: PartialEq> PartialEq for BestInsertion<S>

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<S: PartialEq> StructuralPartialEq for BestInsertion<S>

Source§

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

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. Read more
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. Read more

Auto Trait Implementations§

§

impl<S> Forget for BestInsertion<S>

§

impl<S> Freeze for BestInsertion<S>
where S: Freeze,

§

impl<S> Move for BestInsertion<S>

§

impl<S> RefUnwindSafe for BestInsertion<S>
where S: RefUnwindSafe,

§

impl<S> Send for BestInsertion<S>
where S: Send,

§

impl<S> Sync for BestInsertion<S>
where S: Sync,

§

impl<S> Unpin for BestInsertion<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for BestInsertion<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for BestInsertion<S>
where S: 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.