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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use crate::curve::AggregateExt;
use crate::iterators::server::constrained_demand::ConstrainedServerDemandIterator;
use crate::iterators::{CurveIterator, ReclassifyIterator};
use crate::task::Task;
use crate::time::TimeUnit;
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone)]
pub struct AggregatedServerDemand;
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone)]
pub struct ConstrainedServerDemand;
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone)]
pub struct HigherPriorityServerDemand;
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone)]
pub struct HigherPriorityServerExecution;
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone)]
pub struct UnconstrainedServerExecution;
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone)]
pub struct ActualServerExecution;
#[derive(Debug, Clone)]
pub struct Server<'a> {
pub tasks: &'a [Task],
pub properties: ServerProperties,
}
#[derive(Debug, Clone, Copy)]
pub struct ServerProperties {
pub capacity: TimeUnit,
pub interval: TimeUnit,
pub server_type: ServerKind,
}
#[derive(Debug, Clone, Copy)]
pub enum ServerKind {
Deferrable,
Periodic,
}
impl<'a> Server<'a> {
#[must_use]
pub const fn new(
tasks: &'a [Task],
capacity: TimeUnit,
interval: TimeUnit,
server_type: ServerKind,
) -> Self {
Server {
tasks,
properties: ServerProperties {
capacity,
interval,
server_type,
},
}
}
#[must_use]
pub const fn as_tasks(&self) -> &'a [Task] {
self.tasks
}
#[must_use]
pub fn aggregated_demand_curve_iter(
&self,
) -> impl CurveIterator<CurveKind = AggregatedServerDemand> + Clone + '_ {
self.tasks
.iter()
.map(|task| task.into_iter())
.aggregate::<ReclassifyIterator<_, _>>()
}
#[must_use]
pub fn constraint_demand_curve_iter(
&self,
) -> impl CurveIterator<CurveKind = ConstrainedServerDemand> + Clone + '_ {
ConstrainedServerDemandIterator::new(self.properties, self.aggregated_demand_curve_iter())
}
}