pub const LAMAN_NEIGHBOR_THRESHOLD: usize = 12;
pub const PYTHAGOREAN_INFO_BITS: f64 = 5.584962500721156;
pub const RICCI_CONVERGENCE_MULTIPLIER: f64 = 1.692;
pub const SWARM_UNIFORMITY_THRESHOLD: usize = 500;
pub const COORDINATION_ENTRY_WINDOW: f64 = 1.7;
pub fn is_rigidly_connected(agents: usize, avg_neighbors: usize) -> bool {
if agents < 2 { return true; }
avg_neighbors >= LAMAN_NEIGHBOR_THRESHOLD
}
pub fn info_capacity_exact() -> f64 {
PYTHAGOREAN_INFO_BITS
}
pub fn convergence_time(avg_latency_ms: f64) -> f64 {
avg_latency_ms * RICCI_CONVERGENCE_MULTIPLIER
}
pub fn should_use_uniform_rules(agent_count: usize) -> bool {
agent_count >= SWARM_UNIFORMITY_THRESHOLD
}
pub fn can_enter_coordination(elapsed_ms: f64, avg_latency_ms: f64) -> bool {
if avg_latency_ms <= 0.0 { return false; }
(elapsed_ms / avg_latency_ms) <= COORDINATION_ENTRY_WINDOW
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_laman_threshold() {
assert_eq!(LAMAN_NEIGHBOR_THRESHOLD, 12);
assert!(is_rigidly_connected(100, 12));
assert!(is_rigidly_connected(100, 15));
assert!(!is_rigidly_connected(100, 11));
}
#[test]
fn test_pythagorean_bits() {
let expected = (48f64).log2();
assert!((PYTHAGOREAN_INFO_BITS - expected).abs() < 1e-10);
assert!((info_capacity_exact() - 5.6).abs() < 0.1);
}
#[test]
fn test_convergence_time() {
let t = convergence_time(100.0);
assert!((t - 169.2).abs() < 0.01);
assert!((t / 100.0 - RICCI_CONVERGENCE_MULTIPLIER).abs() < 1e-10);
}
#[test]
fn test_swarm_threshold() {
assert!(!should_use_uniform_rules(499));
assert!(should_use_uniform_rules(500));
assert!(should_use_uniform_rules(10000));
}
#[test]
fn test_coordination_window() {
assert!(can_enter_coordination(100.0, 100.0)); assert!(can_enter_coordination(169.0, 100.0)); assert!(!can_enter_coordination(171.0, 100.0)); }
#[test]
fn test_ricci_multiplier_matches_dcs() {
assert!((RICCI_CONVERGENCE_MULTIPLIER - 1.692).abs() < 0.001);
assert!((RICCI_CONVERGENCE_MULTIPLIER - 1.7).abs() < 0.01);
}
#[test]
fn test_single_agent_is_rigid() {
assert!(is_rigidly_connected(1, 0));
}
#[test]
fn test_zero_latency_no_coordination() {
assert!(!can_enter_coordination(100.0, 0.0));
}
}