u_schedule/dispatching/
context.rs1use std::collections::HashMap;
4
5#[derive(Debug, Clone, Default)]
12pub struct SchedulingContext {
13 pub current_time_ms: i64,
15 pub remaining_work: HashMap<String, i64>,
17 pub next_queue_length: HashMap<String, usize>,
19 pub resource_utilization: HashMap<String, f64>,
21 pub arrival_times: HashMap<String, i64>,
23 pub average_processing_time: Option<f64>,
25}
26
27impl SchedulingContext {
28 pub fn at_time(current_time_ms: i64) -> Self {
30 Self {
31 current_time_ms,
32 ..Default::default()
33 }
34 }
35
36 pub fn with_remaining_work(mut self, task_id: impl Into<String>, ms: i64) -> Self {
38 self.remaining_work.insert(task_id.into(), ms);
39 self
40 }
41
42 pub fn with_next_queue(mut self, task_id: impl Into<String>, length: usize) -> Self {
44 self.next_queue_length.insert(task_id.into(), length);
45 self
46 }
47
48 pub fn with_utilization(mut self, resource_id: impl Into<String>, load: f64) -> Self {
50 self.resource_utilization.insert(resource_id.into(), load);
51 self
52 }
53
54 pub fn with_arrival_time(mut self, task_id: impl Into<String>, time_ms: i64) -> Self {
56 self.arrival_times.insert(task_id.into(), time_ms);
57 self
58 }
59
60 pub fn with_average_processing_time(mut self, avg_ms: f64) -> Self {
62 self.average_processing_time = Some(avg_ms);
63 self
64 }
65}