scirs2-linalg 0.4.0

Linear algebra module for SciRS2 (scirs2-linalg)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
//! Advanced distributed computing framework with machine learning capabilities

use crate::distributed::{
    load_balancer::AdaptiveLoadBalancer,
    fault_tolerance::FaultToleranceManager,
    monitoring::ResourceMonitor,
    capacity_planning::CapacityPlanner,
    topology::NetworkTopologyAnalyzer,
};
use std::collections::HashMap;
use std::time::{Duration, Instant};

/// Advanced MODE: Advanced Distributed Computing Enhancements
///
/// These enhancements provide sophisticated distributed computing capabilities
/// including adaptive load balancing, intelligent fault tolerance, and
/// advanced communication optimization.
pub struct AdvancedDistributedFramework<T>
where
    T: scirs2_core::numeric::Float + Send + Sync + 'static,
{
    /// Adaptive load balancer with machine learning
    adaptive_balancer: AdaptiveLoadBalancer,
    /// Fault tolerance manager
    fault_manager: FaultToleranceManager,
    /// Communication optimizer
    comm_optimizer: CommunicationOptimizer,
    /// Performance predictor
    performance_predictor: PerformancePredictor,
    /// Resource manager
    resource_manager: DistributedResourceManager,
    /// Network topology analyzer
    topology_analyzer: NetworkTopologyAnalyzer,
    _phantom: std::marker::PhantomData<T>,
}

/// Advanced communication optimizer
#[derive(Debug)]
pub struct CommunicationOptimizer {
    /// Network topology information
    topology: NetworkTopology,
    /// Bandwidth prediction model
    bandwidth_predictor: BandwidthPredictor,
    /// Message aggregation system
    message_aggregator: MessageAggregator,
    /// Compression optimizer
    compression_optimizer: CompressionOptimizer,
}

/// Network topology representation
#[derive(Debug, Clone)]
pub struct NetworkTopology {
    /// Nodes in the network
    nodes: HashMap<usize, NetworkNode>,
    /// Connections between nodes
    connections: HashMap<(usize, usize), ConnectionInfo>,
    /// Routing table
    routing_table: HashMap<(usize, usize), Vec<usize>>,
}

/// Information about a network node
#[derive(Debug, Clone)]
pub struct NetworkNode {
    node_id: usize,
    ip_address: std::net::IpAddr,
    port: u16,
    capabilities: NodeCapabilities,
    location: Option<GeographicLocation>,
}

/// Capabilities of a network node
#[derive(Debug, Clone)]
pub struct NodeCapabilities {
    max_bandwidth: u64,
    supported_protocols: Vec<CommunicationProtocol>,
    compression_support: Vec<crate::distributed::config::CompressionAlgorithm>,
    encryption_support: bool,
}

/// Communication protocols
#[derive(Debug, Clone, Copy)]
pub enum CommunicationProtocol {
    TCP,
    UDP,
    RDMA,
    InfiniBand,
    Custom,
}

/// Geographic location for topology-aware placement
#[derive(Debug, Clone)]
pub struct GeographicLocation {
    latitude: f64,
    longitude: f64,
    datacenter: Option<String>,
    region: Option<String>,
}

/// Connection information between nodes
#[derive(Debug, Clone)]
pub struct ConnectionInfo {
    bandwidth: u64,
    latency: f64,
    reliability: f64,
    cost: f64,
    protocol: CommunicationProtocol,
}

/// Bandwidth prediction model
#[derive(Debug)]
pub struct BandwidthPredictor {
    /// Historical bandwidth measurements
    bandwidth_history: HashMap<(usize, usize), Vec<BandwidthMeasurement>>,
    /// Prediction models per connection
    prediction_models: HashMap<(usize, usize), PredictionModel>,
    /// Current predictions
    current_predictions: HashMap<(usize, usize), BandwidthPrediction>,
}

/// Bandwidth measurement
#[derive(Debug, Clone)]
pub struct BandwidthMeasurement {
    timestamp: Instant,
    bandwidth: f64,
    message_size: usize,
    latency: f64,
    context: MeasurementContext,
}

/// Context for bandwidth measurements
#[derive(Debug, Clone)]
pub struct MeasurementContext {
    operation_type: String,
    concurrent_transfers: usize,
    network_load: f64,
    time_of_day: u8, // Hour of day (0-23)
}

/// Prediction model for bandwidth
#[derive(Debug)]
pub enum PredictionModel {
    LinearRegression(LinearRegressionModel),
    MovingAverage(MovingAverageModel),
    ExponentialSmoothing(ExponentialSmoothingModel),
    ARIMA(ARIMAModel),
}

/// Linear regression model
#[derive(Debug)]
pub struct LinearRegressionModel {
    coefficients: Vec<f64>,
    intercept: f64,
    r_squared: f64,
}

/// Moving average model
#[derive(Debug)]
pub struct MovingAverageModel {
    window_size: usize,
    weights: Vec<f64>,
}

/// Exponential smoothing model
#[derive(Debug)]
pub struct ExponentialSmoothingModel {
    alpha: f64,
    beta: f64,
    gamma: f64,
    seasonal_period: usize,
}

/// ARIMA model for time series prediction
#[derive(Debug)]
pub struct ARIMAModel {
    ar_coefficients: Vec<f64>,
    ma_coefficients: Vec<f64>,
    differencing_order: usize,
}

/// Bandwidth prediction
#[derive(Debug, Clone)]
pub struct BandwidthPrediction {
    predicted_bandwidth: f64,
    confidence_interval: (f64, f64),
    prediction_horizon: Duration,
    model_accuracy: f64,
}

/// Message aggregation system
#[derive(Debug)]
pub struct MessageAggregator {
    /// Pending messages for aggregation
    pending_messages: HashMap<MessageAggregationKey, Vec<PendingMessage>>,
    /// Aggregation strategies
    aggregation_strategies: HashMap<String, AggregationStrategy>,
    /// Timing configuration
    timing_config: AggregationTimingConfig,
}

/// Key for message aggregation
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct MessageAggregationKey {
    source_node: usize,
    destination_node: usize,
    message_type: String,
    priority: MessagePriority,
}

/// Priority levels for messages
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum MessagePriority {
    Low,
    Normal,
    High,
    Critical,
}

/// Pending message for aggregation
#[derive(Debug, Clone)]
pub struct PendingMessage {
    message_id: String,
    payload: Vec<u8>,
    timestamp: Instant,
    size: usize,
    metadata: MessageMetadata,
}

/// Metadata for messages
#[derive(Debug, Clone)]
pub struct MessageMetadata {
    operation_id: String,
    sequence_number: u64,
    checksum: u32,
    compression: Option<crate::distributed::config::CompressionAlgorithm>,
    encryption: bool,
}

/// Strategies for message aggregation
#[derive(Debug, Clone)]
pub enum AggregationStrategy {
    /// Combine messages by concatenation
    Concatenation,
    /// Combine messages by mathematical operation
    Mathematical(MathematicalAggregation),
    /// Custom aggregation function
    Custom(String),
}

/// Mathematical aggregation operations
#[derive(Debug, Clone, Copy)]
pub enum MathematicalAggregation {
    Sum,
    Average,
    Maximum,
    Minimum,
    Reduction,
}

/// Timing configuration for aggregation
#[derive(Debug, Clone)]
pub struct AggregationTimingConfig {
    /// Maximum wait time before sending
    max_wait_time: Duration,
    /// Maximum message size before sending
    max_message_size: usize,
    /// Maximum number of messages to aggregate
    max_message_count: usize,
    /// Adaptive timing based on network conditions
    adaptive_timing: bool,
}

/// Compression optimizer for communication
#[derive(Debug)]
pub struct CompressionOptimizer {
    /// Performance profiles for different algorithms
    algorithm_profiles: HashMap<crate::distributed::config::CompressionAlgorithm, CompressionProfile>,
    /// Selection model
    selection_model: CompressionSelectionModel,
    /// Adaptation parameters
    adaptation_config: CompressionAdaptationConfig,
}

/// Performance profile for compression algorithm
#[derive(Debug, Clone)]
pub struct CompressionProfile {
    algorithm: crate::distributed::config::CompressionAlgorithm,
    avg_compression_ratio: f64,
    avg_compression_speed: f64,
    avg_decompression_speed: f64,
    cpu_usage: f64,
    memory_usage: usize,
    optimal_data_sizes: Vec<(usize, usize)>, // (min_size, max_size)
}

/// Model for selecting compression algorithms
#[derive(Debug)]
pub struct CompressionSelectionModel {
    /// Decision tree for algorithm selection
    decision_factors: HashMap<String, DecisionFactor>,
    /// Cost function weights
    cost_weights: CostWeights,
    /// Historical performance data
    performance_history: Vec<CompressionPerformanceRecord>,
}

/// Factor for compression decision making
#[derive(Debug, Clone)]
pub struct DecisionFactor {
    factor_name: String,
    factor_type: FactorType,
    weight: f64,
    threshold_values: Vec<f64>,
}

/// Types of decision factors
#[derive(Debug, Clone)]
pub enum FactorType {
    DataSize,
    NetworkBandwidth,
    CPULoad,
    MemoryAvailable,
    LatencyRequirement,
    DataType,
}

/// Weights for cost function
#[derive(Debug, Clone)]
pub struct CostWeights {
    compression_time_weight: f64,
    decompression_time_weight: f64,
    bandwidth_saving_weight: f64,
    cpu_usage_weight: f64,
    memory_usage_weight: f64,
}

/// Performance record for compression
#[derive(Debug, Clone)]
pub struct CompressionPerformanceRecord {
    algorithm: crate::distributed::config::CompressionAlgorithm,
    data_size: usize,
    compression_ratio: f64,
    compression_time: f64,
    decompression_time: f64,
    cpu_usage: f64,
    context: CompressionContext,
}

/// Context for compression performance
#[derive(Debug, Clone)]
pub struct CompressionContext {
    data_type: String,
    network_conditions: NetworkConditions,
    system_load: SystemLoad,
}

/// Network conditions
#[derive(Debug, Clone)]
pub struct NetworkConditions {
    available_bandwidth: f64,
    current_latency: f64,
    packet_loss_rate: f64,
    congestion_level: f64,
}

/// System load information
#[derive(Debug, Clone)]
pub struct SystemLoad {
    cpu_utilization: f64,
    memory_utilization: f64,
    disk_io_load: f64,
    network_io_load: f64,
}

/// Configuration for compression adaptation
#[derive(Debug, Clone)]
pub struct CompressionAdaptationConfig {
    /// Enable adaptive compression
    adaptive: bool,
    /// Minimum performance improvement to change algorithm
    min_improvement_threshold: f64,
    /// Frequency of adaptation decisions
    adaptation_frequency: Duration,
    /// Learning rate for adaptation
    learning_rate: f64,
}

/// Performance predictor for distributed operations
#[derive(Debug)]
pub struct PerformancePredictor {
    /// Operation performance models
    operation_models: HashMap<String, OperationPerformanceModel>,
    /// System performance baseline
    system_baseline: SystemPerformanceBaseline,
    /// Prediction cache
    prediction_cache: HashMap<PredictionKey, PerformancePrediction>,
}

/// Model for predicting operation performance
#[derive(Debug)]
pub struct OperationPerformanceModel {
    operation_type: String,
    complexity_model: ComplexityModel,
    scaling_model: ScalingModel,
    resource_model: ResourceModel,
    historical_data: Vec<OperationPerformanceData>,
}

/// Complexity model for operations
#[derive(Debug, Clone)]
pub enum ComplexityModel {
    Linear(f64),
    Quadratic(f64, f64),
    Cubic(f64, f64, f64),
    Logarithmic(f64, f64),
    Exponential(f64, f64),
    Custom(String),
}

/// Scaling model for distributed operations
#[derive(Debug, Clone)]
pub struct ScalingModel {
    ideal_speedup: f64,
    communication_overhead: f64,
    load_balancing_efficiency: f64,
    amdahl_serial_fraction: f64,
}

/// Resource model for performance prediction
#[derive(Debug, Clone)]
pub struct ResourceModel {
    cpu_requirement: f64,
    memory_requirement: f64,
    network_requirement: f64,
    disk_requirement: f64,
    gpu_requirement: Option<f64>,
}

/// Historical performance data
#[derive(Debug, Clone)]
pub struct OperationPerformanceData {
    operation_id: String,
    problem_size: usize,
    num_nodes: usize,
    execution_time: f64,
    resource_usage: ResourceUsage,
    system_state: SystemState,
}

/// Resource usage during operation
#[derive(Debug, Clone)]
pub struct ResourceUsage {
    cpu_time: f64,
    memory_peak: usize,
    network_bytes: usize,
    disk_bytes: usize,
    gpu_time: Option<f64>,
}

/// System state during operation
#[derive(Debug, Clone)]
pub struct SystemState {
    load_average: f64,
    memory_available: usize,
    network_utilization: f64,
    disk_utilization: f64,
    temperature: Option<f64>,
}

/// System performance baseline
#[derive(Debug, Clone)]
pub struct SystemPerformanceBaseline {
    cpu_benchmark_score: f64,
    memory_bandwidth: f64,
    network_bandwidth: f64,
    disk_bandwidth: f64,
    gpu_benchmark_score: Option<f64>,
    last_updated: Instant,
}

/// Key for performance prediction cache
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct PredictionKey {
    operation_type: String,
    problem_size: usize,
    num_nodes: usize,
    system_hash: u64,
}

/// Performance prediction result
#[derive(Debug, Clone)]
pub struct PerformancePrediction {
    predicted_time: f64,
    confidence_interval: (f64, f64),
    resource_requirements: ResourceModel,
    bottleneck_analysis: BottleneckAnalysis,
    recommendation: PerformanceRecommendation,
}

/// Analysis of potential bottlenecks
#[derive(Debug, Clone)]
pub struct BottleneckAnalysis {
    primary_bottleneck: BottleneckType,
    bottleneck_severity: f64,
    mitigation_strategies: Vec<MitigationStrategy>,
}

/// Types of performance bottlenecks
#[derive(Debug, Clone, Copy)]
pub enum BottleneckType {
    CPU,
    Memory,
    Network,
    Disk,
    GPU,
    LoadImbalance,
    Communication,
}

/// Strategies for mitigating bottlenecks
#[derive(Debug, Clone)]
pub struct MitigationStrategy {
    strategy_type: MitigationStrategyType,
    expected_improvement: f64,
    implementation_cost: f64,
    description: String,
}

/// Types of mitigation strategies
#[derive(Debug, Clone, Copy)]
pub enum MitigationStrategyType {
    IncreaseNodes,
    OptimizeAlgorithm,
    ImproveLoadBalancing,
    ReduceCommunication,
    CacheOptimization,
    CompressionOptimization,
    NetworkOptimization,
}

/// Performance optimization recommendations
#[derive(Debug, Clone)]
pub struct PerformanceRecommendation {
    optimal_node_count: usize,
    recommended_blocksize: usize,
    suggested_distribution: crate::distributed::DistributionStrategy,
    compression_recommendation: Option<crate::distributed::config::CompressionAlgorithm>,
    priority_adjustments: Vec<PriorityAdjustment>,
}

/// Priority adjustment recommendation
#[derive(Debug, Clone)]
pub struct PriorityAdjustment {
    component: String,
    current_priority: f64,
    recommended_priority: f64,
    rationale: String,
}

/// Distributed resource manager
#[derive(Debug)]
pub struct DistributedResourceManager {
    /// Resource pools across nodes
    resource_pools: HashMap<usize, NodeResourcePool>,
    /// Resource allocation strategies
    allocation_strategies: HashMap<String, AllocationStrategy>,
    /// Resource monitoring
    resource_monitor: ResourceMonitor,
    /// Capacity planning
    capacity_planner: CapacityPlanner,
}

/// Resource pool for a node
#[derive(Debug, Clone)]
pub struct NodeResourcePool {
    node_id: usize,
    available_resources: AvailableResources,
    reserved_resources: ReservedResources,
    resource_limits: ResourceLimits,
    usage_history: Vec<ResourceUsageSnapshot>,
}

/// Available resources on a node
#[derive(Debug, Clone)]
pub struct AvailableResources {
    cpu_cores: f64,
    memory_bytes: usize,
    disk_bytes: usize,
    network_bandwidth: f64,
    gpu_devices: Vec<GpuResource>,
    special_resources: HashMap<String, f64>,
}

/// GPU resource information
#[derive(Debug, Clone)]
pub struct GpuResource {
    device_id: usize,
    memory_bytes: usize,
    compute_capability: String,
    utilization: f64,
    temperature: Option<f64>,
}

/// Reserved resources
#[derive(Debug, Clone)]
pub struct ReservedResources {
    cpu_cores: f64,
    memory_bytes: usize,
    disk_bytes: usize,
    network_bandwidth: f64,
    gpu_devices: Vec<usize>,
    reservations: Vec<ResourceReservation>,
}

/// Resource reservation
#[derive(Debug, Clone)]
pub struct ResourceReservation {
    reservation_id: String,
    requester: String,
    resources: HashMap<String, f64>,
    start_time: Instant,
    duration: Duration,
    priority: ReservationPriority,
}

/// Priority for resource reservations
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum ReservationPriority {
    Background,
    Normal,
    High,
    System,
    Emergency,
}

/// Resource limits for a node
#[derive(Debug, Clone)]
pub struct ResourceLimits {
    max_cpu_cores: f64,
    max_memory_bytes: usize,
    max_disk_bytes: usize,
    max_network_bandwidth: f64,
    max_gpu_utilization: f64,
    soft_limits: HashMap<String, f64>,
}

/// Snapshot of resource usage
#[derive(Debug, Clone)]
pub struct ResourceUsageSnapshot {
    timestamp: Instant,
    cpu_usage: f64,
    memory_usage: usize,
    disk_usage: usize,
    network_usage: f64,
    gpu_usage: HashMap<usize, f64>,
    operation_count: usize,
}

/// Strategy for resource allocation
#[derive(Debug, Clone)]
pub enum AllocationStrategy {
    FirstFit,
    BestFit,
    WorstFit,
    LoadBased,
    Performance,
    Locality,
    Custom(String),
}

impl<T> AdvancedDistributedFramework<T>
where
    T: scirs2_core::numeric::Float + Send + Sync + 'static,
{
    /// Create a new advanced distributed framework
    pub fn new() -> Self {
        Self {
            adaptive_balancer: AdaptiveLoadBalancer::new(crate::distributed::load_balancer::RebalancingConfig::default()),
            fault_manager: FaultToleranceManager::new(),
            comm_optimizer: CommunicationOptimizer::new(),
            performance_predictor: PerformancePredictor::new(),
            resource_manager: DistributedResourceManager::new(),
            topology_analyzer: NetworkTopologyAnalyzer::new(),
            _phantom: std::marker::PhantomData,
        }
    }
}

impl CommunicationOptimizer {
    fn new() -> Self {
        Self {
            topology: NetworkTopology::new(),
            bandwidth_predictor: BandwidthPredictor::new(),
            message_aggregator: MessageAggregator::new(),
            compression_optimizer: CompressionOptimizer::new(),
        }
    }
}

impl NetworkTopology {
    fn new() -> Self {
        Self {
            nodes: HashMap::new(),
            connections: HashMap::new(),
            routing_table: HashMap::new(),
        }
    }
}

impl BandwidthPredictor {
    fn new() -> Self {
        Self {
            bandwidth_history: HashMap::new(),
            prediction_models: HashMap::new(),
            current_predictions: HashMap::new(),
        }
    }
}

impl MessageAggregator {
    fn new() -> Self {
        Self {
            pending_messages: HashMap::new(),
            aggregation_strategies: HashMap::new(),
            timing_config: AggregationTimingConfig::default(),
        }
    }
}

impl CompressionOptimizer {
    fn new() -> Self {
        Self {
            algorithm_profiles: HashMap::new(),
            selection_model: CompressionSelectionModel::new(),
            adaptation_config: CompressionAdaptationConfig::default(),
        }
    }
}

impl CompressionSelectionModel {
    fn new() -> Self {
        Self {
            decision_factors: HashMap::new(),
            cost_weights: CostWeights::default(),
            performance_history: Vec::new(),
        }
    }
}

impl PerformancePredictor {
    fn new() -> Self {
        Self {
            operation_models: HashMap::new(),
            system_baseline: SystemPerformanceBaseline::default(),
            prediction_cache: HashMap::new(),
        }
    }
}

impl DistributedResourceManager {
    fn new() -> Self {
        Self {
            resource_pools: HashMap::new(),
            allocation_strategies: HashMap::new(),
            resource_monitor: ResourceMonitor::new(),
            capacity_planner: CapacityPlanner::new(Duration::from_secs(86400)), // 1 day
        }
    }
}

impl Default for AggregationTimingConfig {
    fn default() -> Self {
        Self {
            max_wait_time: Duration::from_millis(100),
            max_message_size: 1024 * 1024, // 1MB
            max_message_count: 100,
            adaptive_timing: true,
        }
    }
}

impl Default for CompressionAdaptationConfig {
    fn default() -> Self {
        Self {
            adaptive: true,
            min_improvement_threshold: 0.05,
            adaptation_frequency: Duration::from_secs(60),
            learning_rate: 0.1,
        }
    }
}

impl Default for CostWeights {
    fn default() -> Self {
        Self {
            compression_time_weight: 0.3,
            decompression_time_weight: 0.2,
            bandwidth_saving_weight: 0.4,
            cpu_usage_weight: 0.05,
            memory_usage_weight: 0.05,
        }
    }
}

impl Default for SystemPerformanceBaseline {
    fn default() -> Self {
        Self {
            cpu_benchmark_score: 1000.0,
            memory_bandwidth: 10000.0, // MB/s
            network_bandwidth: 1000.0, // Mbps
            disk_bandwidth: 500.0,     // MB/s
            gpu_benchmark_score: None,
            last_updated: Instant::now(),
        }
    }
}