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