pub struct DecayConstraintState {
pub node_id: String,
pub satisfied: DecayCounter,
pub violations: DecayCounter,
pub half_life: f64,
}Expand description
A time-decaying constraint state.
Fields§
§node_id: String§satisfied: DecayCounterSatisfied constraints (decay counter)
violations: DecayCounterViolations (decay counter)
half_life: f64Half-life in seconds
Implementations§
Source§impl DecayConstraintState
impl DecayConstraintState
Sourcepub fn new(node_id: &str, half_life_secs: f64) -> Self
pub fn new(node_id: &str, half_life_secs: f64) -> Self
Examples found in repository?
examples/experiments.rs (line 79)
72fn experiment_3_decay() {
73 println!("=== Experiment 3: Time-Decay Constraint CRDT ===\n");
74
75 let ns = 1_000_000_000u64;
76
77 // Simulate a fleet node over 1 hour
78 let half_life = 300.0; // 5 minutes
79 let mut state = decay::DecayConstraintState::new("forgemaster", half_life);
80
81 // Steady state: 100 satisfied per minute, 2 violations per minute
82 for t in 0..60 {
83 let time = t as u64 * 60 * ns;
84 state.record_satisfied(100.0, time);
85 state.record_violations(2.0, time);
86 }
87
88 println!(" After 60 min steady state:");
89 println!(" Satisfaction rate at t=60: {:.1}%", state.satisfaction_rate(60 * 60 * ns) * 100.0);
90
91 // Burst of violations at minute 55
92 let mut state2 = decay::DecayConstraintState::new("oracle1", half_life);
93 for t in 0..55 {
94 let time = t as u64 * 60 * ns;
95 state2.record_satisfied(100.0, time);
96 state2.record_violations(2.0, time);
97 }
98 // Burst: 50 violations at minute 55
99 state2.record_violations(50.0, 55 * 60 * ns);
100 state2.record_satisfied(100.0, 55 * 60 * ns);
101 for t in 56..60 {
102 let time = t as u64 * 60 * ns;
103 state2.record_satisfied(100.0, time);
104 state2.record_violations(2.0, time);
105 }
106
107 println!("\n After burst (50 violations at min 55):");
108 println!(" Satisfaction rate at t=60: {:.1}%", state2.satisfaction_rate(60 * 60 * ns) * 100.0);
109 println!(" Violation weight at t=60: {:.1}", state2.violation_weight(60 * 60 * ns));
110
111 // Half-life comparison
112 println!("\n Half-life sensitivity:");
113 for &hl in &[30.0, 60.0, 300.0, 3600.0] {
114 let mut s = decay::DecayConstraintState::new("test", hl);
115 for t in 0..60 {
116 s.record_violations(5.0, t as u64 * 60 * ns);
117 }
118 let weight = s.violation_weight(60 * 60 * ns);
119 println!(" half_life={:>4.0}s: violation_weight={:.1}", hl, weight);
120 }
121 println!();
122}Sourcepub fn record_satisfied(&mut self, count: f64, time_ns: u64)
pub fn record_satisfied(&mut self, count: f64, time_ns: u64)
Record satisfied constraints.
Examples found in repository?
examples/experiments.rs (line 84)
72fn experiment_3_decay() {
73 println!("=== Experiment 3: Time-Decay Constraint CRDT ===\n");
74
75 let ns = 1_000_000_000u64;
76
77 // Simulate a fleet node over 1 hour
78 let half_life = 300.0; // 5 minutes
79 let mut state = decay::DecayConstraintState::new("forgemaster", half_life);
80
81 // Steady state: 100 satisfied per minute, 2 violations per minute
82 for t in 0..60 {
83 let time = t as u64 * 60 * ns;
84 state.record_satisfied(100.0, time);
85 state.record_violations(2.0, time);
86 }
87
88 println!(" After 60 min steady state:");
89 println!(" Satisfaction rate at t=60: {:.1}%", state.satisfaction_rate(60 * 60 * ns) * 100.0);
90
91 // Burst of violations at minute 55
92 let mut state2 = decay::DecayConstraintState::new("oracle1", half_life);
93 for t in 0..55 {
94 let time = t as u64 * 60 * ns;
95 state2.record_satisfied(100.0, time);
96 state2.record_violations(2.0, time);
97 }
98 // Burst: 50 violations at minute 55
99 state2.record_violations(50.0, 55 * 60 * ns);
100 state2.record_satisfied(100.0, 55 * 60 * ns);
101 for t in 56..60 {
102 let time = t as u64 * 60 * ns;
103 state2.record_satisfied(100.0, time);
104 state2.record_violations(2.0, time);
105 }
106
107 println!("\n After burst (50 violations at min 55):");
108 println!(" Satisfaction rate at t=60: {:.1}%", state2.satisfaction_rate(60 * 60 * ns) * 100.0);
109 println!(" Violation weight at t=60: {:.1}", state2.violation_weight(60 * 60 * ns));
110
111 // Half-life comparison
112 println!("\n Half-life sensitivity:");
113 for &hl in &[30.0, 60.0, 300.0, 3600.0] {
114 let mut s = decay::DecayConstraintState::new("test", hl);
115 for t in 0..60 {
116 s.record_violations(5.0, t as u64 * 60 * ns);
117 }
118 let weight = s.violation_weight(60 * 60 * ns);
119 println!(" half_life={:>4.0}s: violation_weight={:.1}", hl, weight);
120 }
121 println!();
122}Sourcepub fn record_violations(&mut self, count: f64, time_ns: u64)
pub fn record_violations(&mut self, count: f64, time_ns: u64)
Record violations.
Examples found in repository?
examples/experiments.rs (line 85)
72fn experiment_3_decay() {
73 println!("=== Experiment 3: Time-Decay Constraint CRDT ===\n");
74
75 let ns = 1_000_000_000u64;
76
77 // Simulate a fleet node over 1 hour
78 let half_life = 300.0; // 5 minutes
79 let mut state = decay::DecayConstraintState::new("forgemaster", half_life);
80
81 // Steady state: 100 satisfied per minute, 2 violations per minute
82 for t in 0..60 {
83 let time = t as u64 * 60 * ns;
84 state.record_satisfied(100.0, time);
85 state.record_violations(2.0, time);
86 }
87
88 println!(" After 60 min steady state:");
89 println!(" Satisfaction rate at t=60: {:.1}%", state.satisfaction_rate(60 * 60 * ns) * 100.0);
90
91 // Burst of violations at minute 55
92 let mut state2 = decay::DecayConstraintState::new("oracle1", half_life);
93 for t in 0..55 {
94 let time = t as u64 * 60 * ns;
95 state2.record_satisfied(100.0, time);
96 state2.record_violations(2.0, time);
97 }
98 // Burst: 50 violations at minute 55
99 state2.record_violations(50.0, 55 * 60 * ns);
100 state2.record_satisfied(100.0, 55 * 60 * ns);
101 for t in 56..60 {
102 let time = t as u64 * 60 * ns;
103 state2.record_satisfied(100.0, time);
104 state2.record_violations(2.0, time);
105 }
106
107 println!("\n After burst (50 violations at min 55):");
108 println!(" Satisfaction rate at t=60: {:.1}%", state2.satisfaction_rate(60 * 60 * ns) * 100.0);
109 println!(" Violation weight at t=60: {:.1}", state2.violation_weight(60 * 60 * ns));
110
111 // Half-life comparison
112 println!("\n Half-life sensitivity:");
113 for &hl in &[30.0, 60.0, 300.0, 3600.0] {
114 let mut s = decay::DecayConstraintState::new("test", hl);
115 for t in 0..60 {
116 s.record_violations(5.0, t as u64 * 60 * ns);
117 }
118 let weight = s.violation_weight(60 * 60 * ns);
119 println!(" half_life={:>4.0}s: violation_weight={:.1}", hl, weight);
120 }
121 println!();
122}Sourcepub fn satisfaction_rate(&mut self, time_ns: u64) -> f64
pub fn satisfaction_rate(&mut self, time_ns: u64) -> f64
Get satisfaction rate at a given time.
Examples found in repository?
examples/experiments.rs (line 89)
72fn experiment_3_decay() {
73 println!("=== Experiment 3: Time-Decay Constraint CRDT ===\n");
74
75 let ns = 1_000_000_000u64;
76
77 // Simulate a fleet node over 1 hour
78 let half_life = 300.0; // 5 minutes
79 let mut state = decay::DecayConstraintState::new("forgemaster", half_life);
80
81 // Steady state: 100 satisfied per minute, 2 violations per minute
82 for t in 0..60 {
83 let time = t as u64 * 60 * ns;
84 state.record_satisfied(100.0, time);
85 state.record_violations(2.0, time);
86 }
87
88 println!(" After 60 min steady state:");
89 println!(" Satisfaction rate at t=60: {:.1}%", state.satisfaction_rate(60 * 60 * ns) * 100.0);
90
91 // Burst of violations at minute 55
92 let mut state2 = decay::DecayConstraintState::new("oracle1", half_life);
93 for t in 0..55 {
94 let time = t as u64 * 60 * ns;
95 state2.record_satisfied(100.0, time);
96 state2.record_violations(2.0, time);
97 }
98 // Burst: 50 violations at minute 55
99 state2.record_violations(50.0, 55 * 60 * ns);
100 state2.record_satisfied(100.0, 55 * 60 * ns);
101 for t in 56..60 {
102 let time = t as u64 * 60 * ns;
103 state2.record_satisfied(100.0, time);
104 state2.record_violations(2.0, time);
105 }
106
107 println!("\n After burst (50 violations at min 55):");
108 println!(" Satisfaction rate at t=60: {:.1}%", state2.satisfaction_rate(60 * 60 * ns) * 100.0);
109 println!(" Violation weight at t=60: {:.1}", state2.violation_weight(60 * 60 * ns));
110
111 // Half-life comparison
112 println!("\n Half-life sensitivity:");
113 for &hl in &[30.0, 60.0, 300.0, 3600.0] {
114 let mut s = decay::DecayConstraintState::new("test", hl);
115 for t in 0..60 {
116 s.record_violations(5.0, t as u64 * 60 * ns);
117 }
118 let weight = s.violation_weight(60 * 60 * ns);
119 println!(" half_life={:>4.0}s: violation_weight={:.1}", hl, weight);
120 }
121 println!();
122}Sourcepub fn violation_weight(&mut self, time_ns: u64) -> f64
pub fn violation_weight(&mut self, time_ns: u64) -> f64
Current violation “weight” (how much recent violations matter).
Examples found in repository?
examples/experiments.rs (line 109)
72fn experiment_3_decay() {
73 println!("=== Experiment 3: Time-Decay Constraint CRDT ===\n");
74
75 let ns = 1_000_000_000u64;
76
77 // Simulate a fleet node over 1 hour
78 let half_life = 300.0; // 5 minutes
79 let mut state = decay::DecayConstraintState::new("forgemaster", half_life);
80
81 // Steady state: 100 satisfied per minute, 2 violations per minute
82 for t in 0..60 {
83 let time = t as u64 * 60 * ns;
84 state.record_satisfied(100.0, time);
85 state.record_violations(2.0, time);
86 }
87
88 println!(" After 60 min steady state:");
89 println!(" Satisfaction rate at t=60: {:.1}%", state.satisfaction_rate(60 * 60 * ns) * 100.0);
90
91 // Burst of violations at minute 55
92 let mut state2 = decay::DecayConstraintState::new("oracle1", half_life);
93 for t in 0..55 {
94 let time = t as u64 * 60 * ns;
95 state2.record_satisfied(100.0, time);
96 state2.record_violations(2.0, time);
97 }
98 // Burst: 50 violations at minute 55
99 state2.record_violations(50.0, 55 * 60 * ns);
100 state2.record_satisfied(100.0, 55 * 60 * ns);
101 for t in 56..60 {
102 let time = t as u64 * 60 * ns;
103 state2.record_satisfied(100.0, time);
104 state2.record_violations(2.0, time);
105 }
106
107 println!("\n After burst (50 violations at min 55):");
108 println!(" Satisfaction rate at t=60: {:.1}%", state2.satisfaction_rate(60 * 60 * ns) * 100.0);
109 println!(" Violation weight at t=60: {:.1}", state2.violation_weight(60 * 60 * ns));
110
111 // Half-life comparison
112 println!("\n Half-life sensitivity:");
113 for &hl in &[30.0, 60.0, 300.0, 3600.0] {
114 let mut s = decay::DecayConstraintState::new("test", hl);
115 for t in 0..60 {
116 s.record_violations(5.0, t as u64 * 60 * ns);
117 }
118 let weight = s.violation_weight(60 * 60 * ns);
119 println!(" half_life={:>4.0}s: violation_weight={:.1}", hl, weight);
120 }
121 println!();
122}Trait Implementations§
Source§impl Clone for DecayConstraintState
impl Clone for DecayConstraintState
Source§fn clone(&self) -> DecayConstraintState
fn clone(&self) -> DecayConstraintState
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DecayConstraintState
impl Debug for DecayConstraintState
Source§impl<'de> Deserialize<'de> for DecayConstraintState
impl<'de> Deserialize<'de> for DecayConstraintState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Merge for DecayConstraintState
impl Merge for DecayConstraintState
Source§impl PartialEq for DecayConstraintState
impl PartialEq for DecayConstraintState
Auto Trait Implementations§
impl Freeze for DecayConstraintState
impl RefUnwindSafe for DecayConstraintState
impl Send for DecayConstraintState
impl Sync for DecayConstraintState
impl Unpin for DecayConstraintState
impl UnsafeUnpin for DecayConstraintState
impl UnwindSafe for DecayConstraintState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more