1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! Common shapes of time-dependent rewards, for [`Route::reward`](super::Route::reward).
//!
//! Each takes the full reward, the finish time and the shape's parameters, and returns what
//! the task is worth at that finish time. [`deadline`] and [`linear_decay`] return `None`
//! when it is too late; wrap [`halving`] in `Some`. None of them grows with later finish
//! times.
/// The full `reward` up to and including `deadline`, and `None` after it.
///
/// ```
/// use task_allocation::route::rewards::deadline;
///
/// assert_eq!(deadline(10, 60, 60), Some(10));
/// assert_eq!(deadline(10, 61, 60), None);
/// ```
pub const
/// The full `reward` up to `from`, falling linearly to zero at `until`, and `None` after
/// `until`. Rounds down. When `until` is not after `from`, this is a [`deadline`] at `from`.
///
/// ```
/// use task_allocation::route::rewards::linear_decay;
///
/// assert_eq!(linear_decay(100, 10, 10, 110), Some(100));
/// assert_eq!(linear_decay(100, 60, 10, 110), Some(50));
/// assert_eq!(linear_decay(100, 110, 10, 110), Some(0));
/// assert_eq!(linear_decay(100, 111, 10, 110), None);
/// ```
/// The full `reward` at time zero, halving every `half_life`, with linear steps in between,
/// and never `None`. Rounds down. A `half_life` of zero gives the full reward at time zero
/// and zero after.
///
/// This is the integer counterpart of CBBA's classic time-discounted reward `λ^t · reward`.
///
/// ```
/// use task_allocation::route::rewards::halving;
///
/// assert_eq!(halving(100, 0, 10), 100);
/// assert_eq!(halving(100, 10, 10), 50);
/// assert_eq!(halving(100, 15, 10), 37);
/// assert_eq!(halving(100, 20, 10), 25);
/// ```