use std::cmp::*;
#[cfg(feature = "serde_support")]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde_support", derive(Serialize, Deserialize))]
pub enum WangLandauErrors {
InvalidMinMaxTrialSteps,
InvalidLogFThreshold,
NotEnoughStatistics,
EstimatedStatistic(Vec<f64>),
InvalidBestof,
CheckRefineEvery0,
NotInitialized,
InitFailed,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde_support", derive(Serialize, Deserialize))]
pub enum WangLandauMode {
RefineOriginal,
Refine1T,
}
impl WangLandauMode {
pub fn is_mode_original(&self) -> bool {
matches!(self, WangLandauMode::RefineOriginal)
}
pub fn is_mode_1_t(&self) -> bool {
matches!(self, WangLandauMode::Refine1T)
}
}
pub(crate) struct ProbIndex {
pub(crate) index: usize,
diff: f64,
}
impl PartialEq for ProbIndex {
fn eq(&self, other: &Self) -> bool {
self.index == other.index && self.diff == other.diff
}
}
impl Eq for ProbIndex {}
impl PartialOrd for ProbIndex {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for ProbIndex {
fn cmp(&self, other: &Self) -> Ordering {
self.diff.total_cmp(&other.diff)
}
}
impl ProbIndex {
pub(crate) fn new(prob: f64, index: usize) -> Self {
debug_assert!(prob.is_finite());
Self {
index,
diff: (0.5 - prob).copysign(-1.0),
}
}
pub(crate) fn is_best_of(&self, threshold: f64) -> bool {
self.diff >= -threshold
}
}