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: STrait Implementations§
Source§impl<S: Clone> Clone for BestInsertion<S>
impl<S: Clone> Clone for BestInsertion<S>
impl<S: Copy> Copy for BestInsertion<S>
Source§impl<S: Debug> Debug for BestInsertion<S>
impl<S: Debug> Debug for BestInsertion<S>
Source§impl<S: Default> Default for BestInsertion<S>
impl<S: Default> Default for BestInsertion<S>
impl<S: Eq> Eq for BestInsertion<S>
Source§impl<S: Hash> Hash for BestInsertion<S>
impl<S: Hash> Hash for BestInsertion<S>
Source§impl<S: PartialEq> PartialEq for BestInsertion<S>
impl<S: PartialEq> PartialEq for BestInsertion<S>
impl<S: PartialEq> StructuralPartialEq for BestInsertion<S>
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> 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