Merge commit 'd803bfe2b1fe7f5e219e50ac20d6801a0a58ac75' as 'vendor/ruvector'
This commit is contained in:
231
vendor/ruvector/examples/mincut/time_crystal/README.md
vendored
Normal file
231
vendor/ruvector/examples/mincut/time_crystal/README.md
vendored
Normal file
@@ -0,0 +1,231 @@
|
||||
# Time Crystal Coordination Patterns
|
||||
|
||||
## What Are Time Crystals?
|
||||
|
||||
Time crystals are a fascinating state of matter first proposed by Nobel laureate Frank Wilczek in 2012 and experimentally realized in 2016. Unlike regular crystals that have repeating patterns in *space* (like the atomic structure of diamond), time crystals have repeating patterns in *time*.
|
||||
|
||||
### Key Properties of Time Crystals:
|
||||
|
||||
1. **Periodic Motion**: They oscillate between states perpetually
|
||||
2. **No Energy Required**: Motion continues without external energy input (in their ground state)
|
||||
3. **Broken Time-Translation Symmetry**: The system's state changes periodically even though the laws governing it don't change
|
||||
4. **Quantum Coherence**: The pattern is stable and resists perturbations
|
||||
|
||||
## Time Crystals in Swarm Coordination
|
||||
|
||||
This example translates time crystal physics into swarm coordination patterns. Instead of atoms oscillating, we have **network topologies** that transform periodically:
|
||||
|
||||
```
|
||||
Ring → Star → Mesh → Ring → Star → Mesh → ...
|
||||
```
|
||||
|
||||
### Why This Matters for Coordination:
|
||||
|
||||
1. **Self-Sustaining Patterns**: The swarm maintains rhythmic behavior without external control
|
||||
2. **Predictable Dynamics**: Other systems can rely on the periodic nature
|
||||
3. **Resilient Structure**: The pattern self-heals when perturbed
|
||||
4. **Efficient Resource Use**: No continuous energy input needed to maintain organization
|
||||
|
||||
## How This Example Works
|
||||
|
||||
### Phase Cycle
|
||||
|
||||
The example implements a 9-phase cycle:
|
||||
|
||||
| Phase | Topology | MinCut | Description |
|
||||
|-------|----------|--------|-------------|
|
||||
| Ring | Ring | 2 | Each agent connected to 2 neighbors |
|
||||
| StarFormation | Transition | ~2 | Transitioning from ring to star |
|
||||
| Star | Star | 1 | Central hub with spokes |
|
||||
| MeshFormation | Transition | ~6 | Increasing connectivity |
|
||||
| Mesh | Complete | 11 | All agents interconnected |
|
||||
| MeshDecay | Transition | ~6 | Reducing to star |
|
||||
| StarReformation | Transition | ~2 | Returning to star |
|
||||
| RingReformation | Transition | ~2 | Rebuilding ring |
|
||||
| RingStable | Ring | 2 | Stabilized ring structure |
|
||||
|
||||
### Minimum Cut as Structure Verification
|
||||
|
||||
The **minimum cut** (mincut) serves as a "structural fingerprint" for each phase:
|
||||
|
||||
- **Ring topology**: MinCut = 2 (break any two adjacent edges)
|
||||
- **Star topology**: MinCut = 1 (disconnect any spoke)
|
||||
- **Mesh topology**: MinCut = n-1 (disconnect any single node)
|
||||
|
||||
By continuously monitoring mincut values, we can:
|
||||
1. Verify the topology is correct
|
||||
2. Detect structural degradation ("melting")
|
||||
3. Trigger self-healing when patterns break
|
||||
|
||||
### Code Structure
|
||||
|
||||
```rust
|
||||
struct TimeCrystalSwarm {
|
||||
graph: DynamicGraph, // Current topology
|
||||
current_phase: Phase, // Where we are in the cycle
|
||||
tick: usize, // Time counter
|
||||
mincut_history: Vec<f64>, // Track pattern over time
|
||||
stability: f64, // Health metric (0-1)
|
||||
}
|
||||
|
||||
impl TimeCrystalSwarm {
|
||||
fn tick(&mut self) {
|
||||
// 1. Measure current mincut
|
||||
// 2. Verify it matches expected value
|
||||
// 3. Update stability score
|
||||
// 4. Detect melting if stability drops
|
||||
// 5. Advance to next phase
|
||||
// 6. Rebuild topology for new phase
|
||||
}
|
||||
|
||||
fn crystallize(&mut self, cycles: usize) {
|
||||
// Run multiple full cycles to establish pattern
|
||||
}
|
||||
|
||||
fn restabilize(&mut self) {
|
||||
// Self-healing when pattern breaks
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Running the Example
|
||||
|
||||
```bash
|
||||
# From the repository root
|
||||
cargo run --example mincut/time_crystal/main
|
||||
|
||||
# Or compile and run
|
||||
rustc examples/mincut/time_crystal/main.rs \
|
||||
--edition 2021 \
|
||||
--extern ruvector_mincut=target/debug/libruvector_mincut.rlib \
|
||||
-o time_crystal
|
||||
|
||||
./time_crystal
|
||||
```
|
||||
|
||||
### Expected Output
|
||||
|
||||
```
|
||||
❄️ Crystallizing time pattern over 3 cycles...
|
||||
|
||||
═══ Cycle 1 ═══
|
||||
Tick 1 | Phase: StarFormation | MinCut: 2.0 (expected 2.0) ✓
|
||||
Tick 2 | Phase: Star | MinCut: 1.0 (expected 1.0) ✓
|
||||
Tick 3 | Phase: MeshFormation | MinCut: 5.5 (expected 5.5) ✓
|
||||
...
|
||||
|
||||
Periodicity: ✓ VERIFIED | Stability: 98.2%
|
||||
|
||||
═══ Cycle 2 ═══
|
||||
...
|
||||
```
|
||||
|
||||
## Applications
|
||||
|
||||
### 1. Autonomous Agent Networks
|
||||
- Agents periodically switch between communication patterns
|
||||
- No central coordinator needed
|
||||
- Self-organizing task allocation
|
||||
|
||||
### 2. Load Balancing
|
||||
- Periodic topology changes distribute load
|
||||
- Ring phase: sequential processing
|
||||
- Star phase: centralized coordination
|
||||
- Mesh phase: parallel collaboration
|
||||
|
||||
### 3. Byzantine Fault Tolerance
|
||||
- Rotating topologies prevent single points of failure
|
||||
- Periodic restructuring limits attack windows
|
||||
- Mincut monitoring detects compromised nodes
|
||||
|
||||
### 4. Energy-Efficient Coordination
|
||||
- Topology changes require no continuous power
|
||||
- Nodes "coast" through phase transitions
|
||||
- Wake-sleep cycles synchronized to crystal period
|
||||
|
||||
## Key Concepts
|
||||
|
||||
### Crystallization
|
||||
The process of establishing the periodic pattern. Initial cycles may show instability as the system "learns" the rhythm.
|
||||
|
||||
### Melting
|
||||
Loss of periodicity due to:
|
||||
- Network failures
|
||||
- External interference
|
||||
- Resource exhaustion
|
||||
- Random perturbations
|
||||
|
||||
The system detects melting when `stability < 0.5` and triggers restabilization.
|
||||
|
||||
### Stability Score
|
||||
An exponential moving average of how well actual mincuts match expected values:
|
||||
|
||||
```rust
|
||||
stability = 0.9 * stability + 0.1 * (is_match ? 1.0 : 0.0)
|
||||
```
|
||||
|
||||
- 100%: Perfect crystal
|
||||
- 70-100%: Stable oscillations
|
||||
- 50-70%: Degraded but functional
|
||||
- <50%: Melting, needs restabilization
|
||||
|
||||
### Periodicity Verification
|
||||
Compares mincut values across cycles:
|
||||
|
||||
```rust
|
||||
for i in 0..PERIOD {
|
||||
current_value = mincut_history[n - i]
|
||||
previous_cycle = mincut_history[n - i - PERIOD]
|
||||
|
||||
if abs(current_value - previous_cycle) < threshold {
|
||||
periodic = true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Extensions
|
||||
|
||||
### 1. Multi-Crystal Coordination
|
||||
Run multiple time crystals with different periods that occasionally synchronize.
|
||||
|
||||
### 2. Adaptive Periods
|
||||
Adjust `CRYSTAL_PERIOD` based on network conditions.
|
||||
|
||||
### 3. Hierarchical Crystals
|
||||
Nest time crystals at different scales:
|
||||
- Fast oscillations: individual agent behavior
|
||||
- Medium oscillations: team coordination
|
||||
- Slow oscillations: system-wide reorganization
|
||||
|
||||
### 4. Phase-Locked Loops
|
||||
Synchronize multiple swarms by locking their phases.
|
||||
|
||||
## References
|
||||
|
||||
### Physics
|
||||
- Wilczek, F. (2012). "Quantum Time Crystals". Physical Review Letters.
|
||||
- Yao, N. Y., et al. (2017). "Discrete Time Crystals: Rigidity, Criticality, and Realizations". Physical Review Letters.
|
||||
|
||||
### Graph Theory
|
||||
- Stoer, M., Wagner, F. (1997). "A Simple Min-Cut Algorithm". Journal of the ACM.
|
||||
- Karger, D. R. (2000). "Minimum Cuts in Near-Linear Time". Journal of the ACM.
|
||||
|
||||
### Distributed Systems
|
||||
- Lynch, N. A. (1996). "Distributed Algorithms". Morgan Kaufmann.
|
||||
- Olfati-Saber, R., Murray, R. M. (2004). "Consensus Problems in Networks of Agents". IEEE Transactions on Automatic Control.
|
||||
|
||||
## License
|
||||
|
||||
MIT License - See repository root for details.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions welcome! Areas for improvement:
|
||||
- Additional topology patterns (tree, grid, hypercube)
|
||||
- Quantum-inspired coherence metrics
|
||||
- Real-world deployment examples
|
||||
- Performance optimizations for large swarms
|
||||
|
||||
---
|
||||
|
||||
**Note**: This is a conceptual demonstration. Real time crystals are quantum mechanical systems. This example uses classical graph theory to capture the *spirit* of periodic, autonomous organization.
|
||||
464
vendor/ruvector/examples/mincut/time_crystal/main.rs
vendored
Normal file
464
vendor/ruvector/examples/mincut/time_crystal/main.rs
vendored
Normal file
@@ -0,0 +1,464 @@
|
||||
//! Time Crystal Coordination Patterns
|
||||
//!
|
||||
//! This example demonstrates periodic, self-sustaining coordination patterns
|
||||
//! inspired by time crystals in physics. Unlike normal crystals that have
|
||||
//! repeating patterns in space, time crystals have repeating patterns in time.
|
||||
//!
|
||||
//! In this swarm coordination context, we create topologies that:
|
||||
//! 1. Oscillate periodically between Ring → Star → Mesh → Ring
|
||||
//! 2. Maintain stability without external energy input
|
||||
//! 3. Self-heal when perturbations cause "melting"
|
||||
//! 4. Verify structural integrity using minimum cut analysis
|
||||
|
||||
use ruvector_mincut::prelude::*;
|
||||
|
||||
/// Number of agents in the swarm
|
||||
const SWARM_SIZE: u64 = 12;
|
||||
|
||||
/// Time crystal period (number of ticks per full cycle)
|
||||
const CRYSTAL_PERIOD: usize = 9;
|
||||
|
||||
/// Phases of the time crystal
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum Phase {
|
||||
Ring,
|
||||
StarFormation,
|
||||
Star,
|
||||
MeshFormation,
|
||||
Mesh,
|
||||
MeshDecay,
|
||||
StarReformation,
|
||||
RingReformation,
|
||||
RingStable,
|
||||
}
|
||||
|
||||
impl Phase {
|
||||
/// Get the expected minimum cut value for this phase
|
||||
fn expected_mincut(&self, swarm_size: u64) -> f64 {
|
||||
match self {
|
||||
Phase::Ring | Phase::RingReformation | Phase::RingStable => {
|
||||
// Ring: each node has degree 2, mincut is 2
|
||||
2.0
|
||||
}
|
||||
Phase::StarFormation | Phase::StarReformation => {
|
||||
// Transitional: between previous and next topology
|
||||
2.0 // Conservative estimate during transition
|
||||
}
|
||||
Phase::Star => {
|
||||
// Star: hub node has degree (n-1), mincut is 1 (any edge from hub)
|
||||
1.0
|
||||
}
|
||||
Phase::MeshFormation | Phase::MeshDecay => {
|
||||
// Transitional: increasing connectivity
|
||||
(swarm_size - 1) as f64 / 2.0
|
||||
}
|
||||
Phase::Mesh => {
|
||||
// Complete mesh: mincut is (n-1) - the degree of any single node
|
||||
(swarm_size - 1) as f64
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Get human-readable description
|
||||
fn description(&self) -> &'static str {
|
||||
match self {
|
||||
Phase::Ring => "Ring topology - each agent connected to 2 neighbors",
|
||||
Phase::StarFormation => "Transition: Ring → Star",
|
||||
Phase::Star => "Star topology - central hub with spokes",
|
||||
Phase::MeshFormation => "Transition: Star → Mesh",
|
||||
Phase::Mesh => "Mesh topology - all agents interconnected",
|
||||
Phase::MeshDecay => "Transition: Mesh → Star",
|
||||
Phase::StarReformation => "Transition: Star → Ring",
|
||||
Phase::RingReformation => "Transition: rebuilding Ring",
|
||||
Phase::RingStable => "Ring stabilized - completing cycle",
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the next phase in the cycle
|
||||
fn next(&self) -> Phase {
|
||||
match self {
|
||||
Phase::Ring => Phase::StarFormation,
|
||||
Phase::StarFormation => Phase::Star,
|
||||
Phase::Star => Phase::MeshFormation,
|
||||
Phase::MeshFormation => Phase::Mesh,
|
||||
Phase::Mesh => Phase::MeshDecay,
|
||||
Phase::MeshDecay => Phase::StarReformation,
|
||||
Phase::StarReformation => Phase::RingReformation,
|
||||
Phase::RingReformation => Phase::RingStable,
|
||||
Phase::RingStable => Phase::Ring,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Time Crystal Swarm - periodic coordination pattern
|
||||
struct TimeCrystalSwarm {
|
||||
/// The coordination graph
|
||||
graph: DynamicGraph,
|
||||
/// Current phase in the crystal cycle
|
||||
current_phase: Phase,
|
||||
/// Tick counter
|
||||
tick: usize,
|
||||
/// History of mincut values
|
||||
mincut_history: Vec<f64>,
|
||||
/// History of phases
|
||||
phase_history: Vec<Phase>,
|
||||
/// Number of agents
|
||||
swarm_size: u64,
|
||||
/// Stability score (0.0 = melted, 1.0 = perfect crystal)
|
||||
stability: f64,
|
||||
}
|
||||
|
||||
impl TimeCrystalSwarm {
|
||||
/// Create a new time crystal swarm
|
||||
fn new(swarm_size: u64) -> Self {
|
||||
let graph = DynamicGraph::new();
|
||||
|
||||
// Initialize with ring topology
|
||||
Self::build_ring(&graph, swarm_size);
|
||||
|
||||
TimeCrystalSwarm {
|
||||
graph,
|
||||
current_phase: Phase::Ring,
|
||||
tick: 0,
|
||||
mincut_history: Vec::new(),
|
||||
phase_history: vec![Phase::Ring],
|
||||
swarm_size,
|
||||
stability: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a ring topology
|
||||
fn build_ring(graph: &DynamicGraph, n: u64) {
|
||||
graph.clear();
|
||||
|
||||
// Connect agents in a ring: 0-1-2-...-n-1-0
|
||||
for i in 0..n {
|
||||
let next = (i + 1) % n;
|
||||
let _ = graph.insert_edge(i, next, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a star topology
|
||||
fn build_star(graph: &DynamicGraph, n: u64) {
|
||||
graph.clear();
|
||||
|
||||
// Agent 0 is the hub, connected to all others
|
||||
for i in 1..n {
|
||||
let _ = graph.insert_edge(0, i, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a mesh topology (complete graph)
|
||||
fn build_mesh(graph: &DynamicGraph, n: u64) {
|
||||
graph.clear();
|
||||
|
||||
// Connect every agent to every other agent
|
||||
for i in 0..n {
|
||||
for j in (i + 1)..n {
|
||||
let _ = graph.insert_edge(i, j, 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Transition from one topology to another
|
||||
fn transition_topology(&mut self) {
|
||||
match self.current_phase {
|
||||
Phase::Ring => {
|
||||
// Stay in ring, prepare for transition
|
||||
}
|
||||
Phase::StarFormation => {
|
||||
// Build star topology
|
||||
Self::build_star(&self.graph, self.swarm_size);
|
||||
}
|
||||
Phase::Star => {
|
||||
// Stay in star
|
||||
}
|
||||
Phase::MeshFormation => {
|
||||
// Build mesh topology
|
||||
Self::build_mesh(&self.graph, self.swarm_size);
|
||||
}
|
||||
Phase::Mesh => {
|
||||
// Stay in mesh
|
||||
}
|
||||
Phase::MeshDecay => {
|
||||
// Transition back to star
|
||||
Self::build_star(&self.graph, self.swarm_size);
|
||||
}
|
||||
Phase::StarReformation => {
|
||||
// Stay in star before transitioning to ring
|
||||
}
|
||||
Phase::RingReformation => {
|
||||
// Build ring topology
|
||||
Self::build_ring(&self.graph, self.swarm_size);
|
||||
}
|
||||
Phase::RingStable => {
|
||||
// Stay in ring
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Advance one time step
|
||||
fn tick(&mut self) -> Result<()> {
|
||||
self.tick += 1;
|
||||
|
||||
// Compute current minimum cut
|
||||
let mincut_value = self.compute_mincut()?;
|
||||
self.mincut_history.push(mincut_value);
|
||||
|
||||
// Check stability
|
||||
let expected = self.current_phase.expected_mincut(self.swarm_size);
|
||||
let deviation = (mincut_value - expected).abs() / expected.max(1.0);
|
||||
|
||||
// Update stability score (exponential moving average)
|
||||
let stability_contribution = if deviation < 0.1 { 1.0 } else { 0.0 };
|
||||
self.stability = 0.9 * self.stability + 0.1 * stability_contribution;
|
||||
|
||||
// Detect melting (loss of periodicity)
|
||||
if self.stability < 0.5 {
|
||||
println!("⚠️ WARNING: Time crystal melting detected!");
|
||||
println!(" Stability: {:.2}%", self.stability * 100.0);
|
||||
self.restabilize()?;
|
||||
}
|
||||
|
||||
// Move to next phase
|
||||
self.current_phase = self.current_phase.next();
|
||||
self.phase_history.push(self.current_phase);
|
||||
|
||||
// Transition topology
|
||||
self.transition_topology();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Compute minimum cut of current topology
|
||||
fn compute_mincut(&self) -> Result<f64> {
|
||||
// Build a mincut analyzer
|
||||
let edges: Vec<(VertexId, VertexId, Weight)> = self
|
||||
.graph
|
||||
.edges()
|
||||
.iter()
|
||||
.map(|e| (e.source, e.target, e.weight))
|
||||
.collect();
|
||||
|
||||
if edges.is_empty() {
|
||||
return Ok(f64::INFINITY);
|
||||
}
|
||||
|
||||
let mincut = MinCutBuilder::new().exact().with_edges(edges).build()?;
|
||||
|
||||
let value = mincut.min_cut_value();
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
/// Restabilize the crystal after melting
|
||||
fn restabilize(&mut self) -> Result<()> {
|
||||
println!("🔧 Restabilizing time crystal...");
|
||||
|
||||
// Reset to known good state (ring)
|
||||
Self::build_ring(&self.graph, self.swarm_size);
|
||||
self.current_phase = Phase::Ring;
|
||||
self.stability = 1.0;
|
||||
|
||||
println!("✓ Crystal restabilized");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Verify crystal periodicity
|
||||
fn verify_periodicity(&self) -> bool {
|
||||
if self.mincut_history.len() < CRYSTAL_PERIOD * 2 {
|
||||
return true; // Not enough data yet
|
||||
}
|
||||
|
||||
// Check if pattern repeats
|
||||
let n = self.mincut_history.len();
|
||||
let mut matches = 0;
|
||||
let mut total = 0;
|
||||
|
||||
for i in 0..CRYSTAL_PERIOD.min(n / 2) {
|
||||
let current = self.mincut_history[n - 1 - i];
|
||||
let previous_cycle = self.mincut_history[n - 1 - i - CRYSTAL_PERIOD];
|
||||
|
||||
let deviation = (current - previous_cycle).abs();
|
||||
if deviation < 0.5 {
|
||||
matches += 1;
|
||||
}
|
||||
total += 1;
|
||||
}
|
||||
|
||||
matches as f64 / total as f64 > 0.7
|
||||
}
|
||||
|
||||
/// Crystallize - establish the periodic pattern
|
||||
fn crystallize(&mut self, cycles: usize) -> Result<()> {
|
||||
println!("❄️ Crystallizing time pattern over {} cycles...\n", cycles);
|
||||
|
||||
for cycle in 0..cycles {
|
||||
println!("═══ Cycle {} ═══", cycle + 1);
|
||||
|
||||
for _step in 0..CRYSTAL_PERIOD {
|
||||
self.tick()?;
|
||||
|
||||
let mincut = self.mincut_history.last().copied().unwrap_or(0.0);
|
||||
let expected = self.current_phase.expected_mincut(self.swarm_size);
|
||||
let status = if (mincut - expected).abs() < 0.5 {
|
||||
"✓"
|
||||
} else {
|
||||
"✗"
|
||||
};
|
||||
|
||||
println!(
|
||||
" Tick {:2} | Phase: {:18} | MinCut: {:5.1} (expected {:5.1}) {}",
|
||||
self.tick,
|
||||
format!("{:?}", self.current_phase),
|
||||
mincut,
|
||||
expected,
|
||||
status
|
||||
);
|
||||
}
|
||||
|
||||
// Check periodicity after each cycle
|
||||
if cycle > 0 {
|
||||
let periodic = self.verify_periodicity();
|
||||
println!(
|
||||
"\n Periodicity: {} | Stability: {:.1}%\n",
|
||||
if periodic {
|
||||
"✓ VERIFIED"
|
||||
} else {
|
||||
"✗ BROKEN"
|
||||
},
|
||||
self.stability * 100.0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get current statistics
|
||||
fn stats(&self) -> CrystalStats {
|
||||
CrystalStats {
|
||||
tick: self.tick,
|
||||
current_phase: self.current_phase,
|
||||
stability: self.stability,
|
||||
periodicity_verified: self.verify_periodicity(),
|
||||
avg_mincut: self.mincut_history.iter().sum::<f64>() / self.mincut_history.len() as f64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Statistics about the time crystal
|
||||
#[derive(Debug)]
|
||||
struct CrystalStats {
|
||||
tick: usize,
|
||||
current_phase: Phase,
|
||||
stability: f64,
|
||||
periodicity_verified: bool,
|
||||
avg_mincut: f64,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
println!("╔════════════════════════════════════════════════════════════╗");
|
||||
println!("║ TIME CRYSTAL COORDINATION PATTERNS ║");
|
||||
println!("║ ║");
|
||||
println!("║ Periodic, self-sustaining swarm topologies that ║");
|
||||
println!("║ oscillate without external energy, verified by ║");
|
||||
println!("║ minimum cut analysis at each phase ║");
|
||||
println!("╚════════════════════════════════════════════════════════════╝");
|
||||
println!();
|
||||
|
||||
println!("Swarm Configuration:");
|
||||
println!(" • Agents: {}", SWARM_SIZE);
|
||||
println!(" • Crystal Period: {} ticks", CRYSTAL_PERIOD);
|
||||
println!(" • Phase Sequence: Ring → Star → Mesh → Ring");
|
||||
println!();
|
||||
|
||||
// Create time crystal swarm
|
||||
let mut swarm = TimeCrystalSwarm::new(SWARM_SIZE);
|
||||
|
||||
// Demonstrate phase descriptions
|
||||
println!("Phase Descriptions:");
|
||||
for (i, phase) in [
|
||||
Phase::Ring,
|
||||
Phase::StarFormation,
|
||||
Phase::Star,
|
||||
Phase::MeshFormation,
|
||||
Phase::Mesh,
|
||||
Phase::MeshDecay,
|
||||
Phase::StarReformation,
|
||||
Phase::RingReformation,
|
||||
Phase::RingStable,
|
||||
]
|
||||
.iter()
|
||||
.enumerate()
|
||||
{
|
||||
println!(
|
||||
" {}. {:18} - {} (mincut: {})",
|
||||
i + 1,
|
||||
format!("{:?}", phase),
|
||||
phase.description(),
|
||||
phase.expected_mincut(SWARM_SIZE)
|
||||
);
|
||||
}
|
||||
println!();
|
||||
|
||||
// Crystallize the pattern over 3 full cycles
|
||||
swarm.crystallize(3)?;
|
||||
|
||||
// Display final statistics
|
||||
println!("\n╔════════════════════════════════════════════════════════════╗");
|
||||
println!("║ FINAL STATISTICS ║");
|
||||
println!("╚════════════════════════════════════════════════════════════╝");
|
||||
|
||||
let stats = swarm.stats();
|
||||
println!("\n Total Ticks: {}", stats.tick);
|
||||
println!(" Current Phase: {:?}", stats.current_phase);
|
||||
println!(" Stability: {:.1}%", stats.stability * 100.0);
|
||||
println!(
|
||||
" Periodicity: {}",
|
||||
if stats.periodicity_verified {
|
||||
"✓ VERIFIED"
|
||||
} else {
|
||||
"✗ BROKEN"
|
||||
}
|
||||
);
|
||||
println!(" Average MinCut: {:.2}", stats.avg_mincut);
|
||||
println!();
|
||||
|
||||
// Demonstrate phase transition visualization
|
||||
println!("Phase History (last {} ticks):", CRYSTAL_PERIOD);
|
||||
let history_len = swarm.phase_history.len();
|
||||
let start = history_len.saturating_sub(CRYSTAL_PERIOD);
|
||||
|
||||
for (i, (phase, mincut)) in swarm.phase_history[start..]
|
||||
.iter()
|
||||
.zip(swarm.mincut_history[start..].iter())
|
||||
.enumerate()
|
||||
{
|
||||
let expected = phase.expected_mincut(SWARM_SIZE);
|
||||
let bar_length = (*mincut / SWARM_SIZE as f64 * 40.0) as usize;
|
||||
let bar = "█".repeat(bar_length);
|
||||
|
||||
println!(
|
||||
" {:2}. {:18} {:5.1} {} {}",
|
||||
start + i + 1,
|
||||
format!("{:?}", phase),
|
||||
mincut,
|
||||
bar,
|
||||
if (*mincut - expected).abs() < 0.5 {
|
||||
"✓"
|
||||
} else {
|
||||
"✗"
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
println!("\n✓ Time crystal coordination complete!");
|
||||
println!("\nKey Insights:");
|
||||
println!(" • The swarm maintains periodic oscillations autonomously");
|
||||
println!(" • Each phase has a characteristic minimum cut signature");
|
||||
println!(" • Stability monitoring prevents degradation");
|
||||
println!(" • Pattern repeats without external energy input");
|
||||
println!();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user