maple_runtime/types/
coupling.rs1use serde::{Deserialize, Serialize};
4use super::ids::{CouplingId, ResonatorId};
5use super::temporal::TemporalAnchor;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct Coupling {
12 pub id: CouplingId,
13 pub source: ResonatorId,
14 pub target: ResonatorId,
15
16 pub strength: f64,
22
23 pub persistence: CouplingPersistence,
25
26 pub scope: CouplingScope,
28
29 pub symmetry: SymmetryType,
31
32 pub attention_allocated: u64,
38
39 pub meaning_convergence: f64,
45
46 pub interaction_count: u64,
48
49 pub created_at: TemporalAnchor,
51
52 pub last_resonance: TemporalAnchor,
54}
55
56impl Coupling {
57 pub fn is_healthy(&self) -> bool {
59 self.meaning_convergence > 0.3 && self.strength > 0.1
60 }
61
62 pub fn should_strengthen(&self) -> bool {
64 self.meaning_convergence > 0.7 && self.strength < 0.8
65 }
66
67 pub fn should_weaken(&self) -> bool {
69 self.meaning_convergence < 0.2 && self.strength > 0.2
70 }
71}
72
73#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
75pub enum CouplingPersistence {
76 Transient,
78
79 Session,
81
82 Persistent,
84
85 Timed(u64),
87}
88
89#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
91pub enum CouplingScope {
92 Full,
94
95 StateOnly,
97
98 IntentOnly,
100
101 ObservationalOnly,
103}
104
105#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
107pub enum SymmetryType {
108 Symmetric,
110
111 Asymmetric { primary: ResonatorId },
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize)]
117pub struct CouplingParams {
118 pub source: ResonatorId,
119 pub target: ResonatorId,
120
121 pub initial_strength: f64,
123
124 pub initial_attention_cost: u64,
126
127 pub persistence: CouplingPersistence,
129
130 pub scope: CouplingScope,
132
133 pub symmetry: SymmetryType,
135}
136
137impl CouplingParams {
138 pub fn validate(&self) -> Result<(), CouplingValidationError> {
140 if self.initial_strength > 0.3 {
142 return Err(CouplingValidationError::InitialStrengthTooHigh);
143 }
144
145 if self.initial_strength < 0.0 || self.initial_strength > 1.0 {
146 return Err(CouplingValidationError::InvalidStrength);
147 }
148
149 if self.initial_attention_cost == 0 {
150 return Err(CouplingValidationError::ZeroAttentionCost);
151 }
152
153 Ok(())
154 }
155}
156
157#[derive(Debug, Clone, Serialize, Deserialize)]
159pub struct CouplingAffinitySpec {
160 pub preferred_strength: f64,
162
163 pub preferred_persistence: CouplingPersistence,
165
166 pub preferred_scope: CouplingScope,
168
169 pub max_concurrent_couplings: Option<usize>,
171}
172
173impl Default for CouplingAffinitySpec {
174 fn default() -> Self {
175 Self {
176 preferred_strength: 0.3,
177 preferred_persistence: CouplingPersistence::Session,
178 preferred_scope: CouplingScope::Full,
179 max_concurrent_couplings: Some(100),
180 }
181 }
182}
183
184#[derive(Debug, Clone, thiserror::Error)]
186pub enum CouplingValidationError {
187 #[error("Initial coupling strength too high (max 0.3)")]
188 InitialStrengthTooHigh,
189
190 #[error("Invalid strength value (must be 0.0-1.0)")]
191 InvalidStrength,
192
193 #[error("Attention cost cannot be zero")]
194 ZeroAttentionCost,
195}
196
197#[derive(Debug, Clone, Serialize, Deserialize)]
199pub struct CouplingConfig {
200 pub max_initial_strength: f64,
202
203 pub max_strengthening_rate: f64,
205
206 pub enable_auto_adjustment: bool,
208
209 pub min_meaning_convergence: f64,
211}
212
213impl Default for CouplingConfig {
214 fn default() -> Self {
215 Self {
216 max_initial_strength: 0.3,
217 max_strengthening_rate: 0.1,
218 enable_auto_adjustment: true,
219 min_meaning_convergence: 0.1,
220 }
221 }
222}