use super::ids::{CouplingId, ResonatorId};
use super::temporal::TemporalAnchor;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Coupling {
pub id: CouplingId,
pub source: ResonatorId,
pub target: ResonatorId,
pub strength: f64,
pub persistence: CouplingPersistence,
pub scope: CouplingScope,
pub symmetry: SymmetryType,
pub attention_allocated: u64,
pub meaning_convergence: f64,
pub interaction_count: u64,
pub created_at: TemporalAnchor,
pub last_resonance: TemporalAnchor,
}
impl Coupling {
pub fn is_healthy(&self) -> bool {
self.meaning_convergence > 0.3 && self.strength > 0.1
}
pub fn should_strengthen(&self) -> bool {
self.meaning_convergence > 0.7 && self.strength < 0.8
}
pub fn should_weaken(&self) -> bool {
self.meaning_convergence < 0.2 && self.strength > 0.2
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum CouplingPersistence {
Transient,
Session,
Persistent,
Timed(u64),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum CouplingScope {
Full,
StateOnly,
IntentOnly,
ObservationalOnly,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum SymmetryType {
Symmetric,
Asymmetric { primary: ResonatorId },
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CouplingParams {
pub source: ResonatorId,
pub target: ResonatorId,
pub initial_strength: f64,
pub initial_attention_cost: u64,
pub persistence: CouplingPersistence,
pub scope: CouplingScope,
pub symmetry: SymmetryType,
}
impl CouplingParams {
pub fn validate(&self) -> Result<(), CouplingValidationError> {
if self.initial_strength > 0.3 {
return Err(CouplingValidationError::InitialStrengthTooHigh);
}
if self.initial_strength < 0.0 || self.initial_strength > 1.0 {
return Err(CouplingValidationError::InvalidStrength);
}
if self.initial_attention_cost == 0 {
return Err(CouplingValidationError::ZeroAttentionCost);
}
Ok(())
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CouplingAffinitySpec {
pub preferred_strength: f64,
pub preferred_persistence: CouplingPersistence,
pub preferred_scope: CouplingScope,
pub max_concurrent_couplings: Option<usize>,
}
impl Default for CouplingAffinitySpec {
fn default() -> Self {
Self {
preferred_strength: 0.3,
preferred_persistence: CouplingPersistence::Session,
preferred_scope: CouplingScope::Full,
max_concurrent_couplings: Some(100),
}
}
}
#[derive(Debug, Clone, thiserror::Error)]
pub enum CouplingValidationError {
#[error("Initial coupling strength too high (max 0.3)")]
InitialStrengthTooHigh,
#[error("Invalid strength value (must be 0.0-1.0)")]
InvalidStrength,
#[error("Attention cost cannot be zero")]
ZeroAttentionCost,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CouplingConfig {
pub max_initial_strength: f64,
pub max_strengthening_rate: f64,
pub enable_auto_adjustment: bool,
pub min_meaning_convergence: f64,
}
impl Default for CouplingConfig {
fn default() -> Self {
Self {
max_initial_strength: 0.3,
max_strengthening_rate: 0.1,
enable_auto_adjustment: true,
min_meaning_convergence: 0.1,
}
}
}