melvin_ob/scheduling/atomic_decision.rs
1use crate::fatal;
2
3/// Represents the different atomic decisions that can be made regarding states.
4#[derive(Debug, Clone, Copy)]
5pub enum AtomicDecision {
6 /// Decision to stay in the charge state.
7 StayInCharge,
8 /// Decision to stay in the acquisition state.
9 StayInAcquisition,
10 /// Decision to switch to the charge state.
11 SwitchToCharge,
12 /// Decision to switch to the acquisition state.
13 SwitchToAcquisition,
14}
15
16impl AtomicDecision {
17 /// Creates a decision to stay in the current state based on the provided state value.
18 ///
19 /// # Arguments
20 /// - `state`: The current state as a `usize`.
21 /// - `0` indicates the charge state.
22 /// - `1` indicates the acquisition state.
23 ///
24 /// # Returns
25 /// - An [`AtomicDecision`] variant corresponding to staying in the current state.
26 ///
27 /// # Panics
28 /// - If `state` is not `0` or `1`.
29 pub fn stay(state: usize) -> Self {
30 if state == 0 {
31 AtomicDecision::StayInCharge
32 } else if state == 1 {
33 AtomicDecision::StayInAcquisition
34 } else {
35 fatal!("Invalid state for stay decision")
36 }
37 }
38
39 /// Creates a decision to switch to a new state based on the provided state value.
40 ///
41 /// # Arguments
42 /// - `to_state`: The target state as a `usize`.
43 /// - `0` indicates the charge state.
44 /// - `1` indicates the acquisition state.
45 ///
46 /// # Returns
47 /// - An `AtomicDecision` variant corresponding to switching to the target state.
48 ///
49 /// # Panics
50 /// - If `to_state` is not `0` or `1`.
51 pub fn switch(to_state: usize) -> Self {
52 if to_state == 0 {
53 AtomicDecision::SwitchToCharge
54 } else if to_state == 1 {
55 AtomicDecision::SwitchToAcquisition
56 } else {
57 fatal!("Invalid state for stay decision")
58 }
59 }
60}