Skip to main content

aqt_sim/simulation/
threshold.rs

1//! This module contains the `Threshold` trait and its implementations, which determine when a
2//! `Simulation` should stop running.
3
4use crate::network::Network;
5
6
7/// Used to end a `Simulation`.
8pub trait Threshold {
9    /// Check whether to terminate the simulation and update any internal state of the
10    /// `Threshold.`.
11    fn check_termination(&mut self, rd: usize, network: &Network) -> bool;
12}
13
14
15/// To end a `Simulatoin` after a specified number of rounds has elapsed.
16pub struct TimedThreshold {
17    max_rds: usize,
18}
19
20impl TimedThreshold {
21    /// Create a new `TimedThreshold` with the given number of maximum rounds.
22    pub fn new(max_rds: usize) -> Self {
23        TimedThreshold { max_rds }
24    }
25}
26
27impl Threshold for TimedThreshold {
28    fn check_termination(&mut self, rd: usize, _network: &Network) -> bool {
29        rd >= self.max_rds
30    }
31}
32