use crate::core::{QduId, StableState};
use std::collections::HashMap;
use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub struct SimulationResult {
stable_outcomes: HashMap<QduId, StableState>,
}
impl SimulationResult {
pub(crate) fn new() -> Self {
Self {
stable_outcomes: HashMap::new(),
}
}
pub(crate) fn record_stable_state(&mut self, qdu_id: QduId, state: StableState) {
self.stable_outcomes.insert(qdu_id, state);
}
pub fn get_stable_state(&self, qdu_id: &QduId) -> Option<&StableState> {
self.stable_outcomes.get(qdu_id)
}
pub fn all_stable_outcomes(&self) -> &HashMap<QduId, StableState> {
&self.stable_outcomes
}
}
impl fmt::Display for SimulationResult {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "Simulation Results:")?;
if self.stable_outcomes.is_empty() {
writeln!(f, " No QDUs were stabilized.")?;
} else {
let mut sorted_outcomes: Vec<_> = self.stable_outcomes.iter().collect();
sorted_outcomes.sort_by_key(|(id, _)| *id);
writeln!(f, " Stable Outcomes:")?;
for (id, state) in sorted_outcomes {
writeln!(f, " {}: {}", id, state)?;
}
}
Ok(())
}
}