1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use std::cmp::*;
#[cfg(feature = "serde_support")]
use serde::{Serialize, Deserialize};
#[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> {
self.diff.partial_cmp(&other.diff)
}
}
impl Ord for ProbIndex{
fn cmp(&self, other: &Self) -> Ordering {
self.partial_cmp(other).unwrap()
}
}
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
}
}