Skip to main content

quantrs2_device/job_scheduling/
types.rs

1//! Advanced Job Priority and Scheduling Optimization for Quantum Hardware
2//!
3//! This module provides comprehensive job scheduling, prioritization, and optimization
4//! capabilities for quantum hardware backends, including:
5//! - Multi-level priority queue management
6//! - Intelligent resource allocation and load balancing
7//! - Cross-provider job coordination
8//! - SciRS2-powered scheduling optimization algorithms
9//! - Queue analytics and prediction
10//! - Job persistence and recovery mechanisms
11//! - Dynamic backend selection based on performance metrics
12
13use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
14use std::sync::{Arc, Mutex, RwLock};
15use std::time::{Duration, SystemTime};
16
17use crate::{translation::HardwareBackend, CircuitResult};
18use quantrs2_circuit::prelude::Circuit;
19
20use serde::{Deserialize, Serialize};
21use tokio::sync::mpsc;
22use uuid::Uuid;
23
24/// Job priority levels
25#[derive(
26    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Default,
27)]
28pub enum JobPriority {
29    /// System critical jobs (maintenance, calibration)
30    Critical = 0,
31    /// High priority research or production jobs
32    High = 1,
33    /// Normal priority jobs
34    #[default]
35    Normal = 2,
36    /// Low priority background jobs
37    Low = 3,
38    /// Best effort jobs that can be delayed
39    BestEffort = 4,
40}
41
42/// Job execution status
43#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
44pub enum JobStatus {
45    /// Job is pending in queue
46    Pending,
47    /// Job is being validated
48    Validating,
49    /// Job is scheduled for execution
50    Scheduled,
51    /// Job is currently running
52    Running,
53    /// Job completed successfully
54    Completed,
55    /// Job failed during execution
56    Failed,
57    /// Job was cancelled
58    Cancelled,
59    /// Job timed out
60    TimedOut,
61    /// Job is retrying after failure
62    Retrying,
63    /// Job is paused/suspended
64    Paused,
65}
66
67/// Advanced scheduling strategies
68#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
69pub enum SchedulingStrategy {
70    /// First-In-First-Out with priority levels
71    PriorityFIFO,
72    /// Shortest Job First
73    ShortestJobFirst,
74    /// Shortest Remaining Time First
75    ShortestRemainingTimeFirst,
76    /// Fair Share scheduling
77    FairShare,
78    /// Round Robin with priority
79    PriorityRoundRobin,
80    /// Backfill scheduling
81    Backfill,
82    /// Earliest Deadline First
83    EarliestDeadlineFirst,
84    /// Rate Monotonic scheduling
85    RateMonotonic,
86    /// Machine learning optimized scheduling using SciRS2
87    MLOptimized,
88    /// Multi-objective optimization using SciRS2
89    MultiObjectiveOptimized,
90    /// Reinforcement Learning based scheduling
91    ReinforcementLearning,
92    /// Genetic Algorithm scheduling
93    GeneticAlgorithm,
94    /// Game-theoretic fair scheduling
95    GameTheoreticFair,
96    /// Energy-aware scheduling
97    EnergyAware,
98    /// Deadline-aware scheduling with SLA guarantees
99    DeadlineAwareSLA,
100    /// Custom scheduling function
101    Custom(String),
102}
103
104/// Advanced resource allocation strategies
105#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
106pub enum AllocationStrategy {
107    /// First available backend
108    FirstFit,
109    /// Best performance for job requirements
110    BestFit,
111    /// Worst fit for load balancing
112    WorstFit,
113    /// Least loaded backend
114    LeastLoaded,
115    /// Most loaded backend (for consolidation)
116    MostLoaded,
117    /// Round robin across backends
118    RoundRobin,
119    /// Weighted round robin
120    WeightedRoundRobin,
121    /// Cost-optimized allocation
122    CostOptimized,
123    /// Performance-optimized allocation
124    PerformanceOptimized,
125    /// Energy-efficient allocation
126    EnergyEfficient,
127    /// SciRS2-optimized allocation using ML
128    SciRS2Optimized,
129    /// Multi-objective allocation (cost, performance, energy)
130    MultiObjectiveOptimized,
131    /// Locality-aware allocation
132    LocalityAware,
133    /// Fault-tolerant allocation
134    FaultTolerant,
135    /// Predictive allocation based on historical patterns
136    PredictiveAllocation,
137}
138
139/// Job submission configuration
140#[derive(Debug, Clone, Serialize, Deserialize)]
141pub struct JobConfig {
142    /// Job priority level
143    pub priority: JobPriority,
144    /// Maximum execution time
145    pub max_execution_time: Duration,
146    /// Maximum wait time in queue
147    pub max_queue_time: Option<Duration>,
148    /// Number of retry attempts on failure
149    pub retry_attempts: u32,
150    /// Retry delay between attempts
151    pub retry_delay: Duration,
152    /// Resource requirements
153    pub resource_requirements: ResourceRequirements,
154    /// Preferred backends (ordered by preference)
155    pub preferred_backends: Vec<HardwareBackend>,
156    /// Job tags for grouping and filtering
157    pub tags: HashMap<String, String>,
158    /// Job dependencies
159    pub dependencies: Vec<JobId>,
160    /// Deadline for completion
161    pub deadline: Option<SystemTime>,
162    /// Cost constraints
163    pub cost_limit: Option<f64>,
164}
165
166impl Default for JobConfig {
167    fn default() -> Self {
168        Self {
169            priority: JobPriority::Normal,
170            max_execution_time: Duration::from_secs(3600), // 1 hour
171            max_queue_time: Some(Duration::from_secs(86400)), // 24 hours
172            retry_attempts: 3,
173            retry_delay: Duration::from_secs(60),
174            resource_requirements: ResourceRequirements::default(),
175            preferred_backends: vec![],
176            tags: HashMap::new(),
177            dependencies: vec![],
178            deadline: None,
179            cost_limit: None,
180        }
181    }
182}
183
184/// Resource requirements for job execution
185#[derive(Debug, Clone, Serialize, Deserialize)]
186pub struct ResourceRequirements {
187    /// Minimum number of qubits required
188    pub min_qubits: usize,
189    /// Maximum circuit depth
190    pub max_depth: Option<usize>,
191    /// Required gate fidelity
192    pub min_fidelity: Option<f64>,
193    /// Required connectivity (if specific topology needed)
194    pub required_connectivity: Option<String>,
195    /// Memory requirements (MB)
196    pub memory_mb: Option<u64>,
197    /// CPU requirements
198    pub cpu_cores: Option<u32>,
199    /// Special hardware features required
200    pub required_features: Vec<String>,
201}
202
203impl Default for ResourceRequirements {
204    fn default() -> Self {
205        Self {
206            min_qubits: 1,
207            max_depth: None,
208            min_fidelity: None,
209            required_connectivity: None,
210            memory_mb: None,
211            cpu_cores: None,
212            required_features: vec![],
213        }
214    }
215}
216
217/// Unique job identifier
218#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
219pub struct JobId(pub String);
220
221impl Default for JobId {
222    fn default() -> Self {
223        Self::new()
224    }
225}
226
227impl JobId {
228    pub fn new() -> Self {
229        Self(Uuid::new_v4().to_string())
230    }
231
232    pub const fn from_string(s: String) -> Self {
233        Self(s)
234    }
235}
236
237impl std::fmt::Display for JobId {
238    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
239        write!(f, "{}", self.0)
240    }
241}
242
243/// Quantum circuit job definition
244#[derive(Debug, Clone)]
245pub struct QuantumJob<const N: usize> {
246    /// Unique job identifier
247    pub id: JobId,
248    /// Job configuration
249    pub config: JobConfig,
250    /// Circuit to execute
251    pub circuit: Circuit<N>,
252    /// Number of shots
253    pub shots: usize,
254    /// Job submission time
255    pub submitted_at: SystemTime,
256    /// Job status
257    pub status: JobStatus,
258    /// Execution history and attempts
259    pub execution_history: Vec<JobExecution>,
260    /// Job metadata
261    pub metadata: HashMap<String, String>,
262    /// User/group information
263    pub user_id: String,
264    /// Job group/project
265    pub group_id: Option<String>,
266    /// Estimated execution time
267    pub estimated_duration: Option<Duration>,
268    /// Assigned backend
269    pub assigned_backend: Option<HardwareBackend>,
270    /// Cost tracking
271    pub estimated_cost: Option<f64>,
272    pub actual_cost: Option<f64>,
273}
274
275/// Job execution attempt record
276#[derive(Debug, Clone, Serialize, Deserialize)]
277pub struct JobExecution {
278    /// Attempt number
279    pub attempt: u32,
280    /// Backend used for execution
281    pub backend: HardwareBackend,
282    /// Execution start time
283    pub started_at: SystemTime,
284    /// Execution end time
285    pub ended_at: Option<SystemTime>,
286    /// Execution result
287    pub result: Option<CircuitResult>,
288    /// Error information if failed
289    pub error: Option<String>,
290    /// Execution metrics
291    pub metrics: ExecutionMetrics,
292}
293
294/// Execution performance metrics
295#[derive(Debug, Clone, Serialize, Deserialize)]
296pub struct ExecutionMetrics {
297    /// Actual queue time
298    pub queue_time: Duration,
299    /// Actual execution time
300    pub execution_time: Option<Duration>,
301    /// Resource utilization
302    pub resource_utilization: f64,
303    /// Cost incurred
304    pub cost: Option<f64>,
305    /// Quality metrics (fidelity, error rates, etc.)
306    pub quality_metrics: HashMap<String, f64>,
307}
308
309impl Default for ExecutionMetrics {
310    fn default() -> Self {
311        Self {
312            queue_time: Duration::from_secs(0),
313            execution_time: None,
314            resource_utilization: 0.0,
315            cost: None,
316            quality_metrics: HashMap::new(),
317        }
318    }
319}
320
321/// Backend performance tracking
322#[derive(Debug, Clone)]
323pub struct BackendPerformance {
324    /// Backend identifier
325    pub backend: HardwareBackend,
326    /// Current queue length
327    pub queue_length: usize,
328    /// Average queue time
329    pub avg_queue_time: Duration,
330    /// Average execution time
331    pub avg_execution_time: Duration,
332    /// Success rate (0.0 - 1.0)
333    pub success_rate: f64,
334    /// Current utilization (0.0 - 1.0)
335    pub utilization: f64,
336    /// Cost per job
337    pub avg_cost: Option<f64>,
338    /// Last updated timestamp
339    pub last_updated: SystemTime,
340    /// Historical performance data
341    pub history: VecDeque<PerformanceSnapshot>,
342}
343
344/// Performance snapshot for historical tracking
345#[derive(Debug, Clone, Serialize, Deserialize)]
346pub struct PerformanceSnapshot {
347    pub timestamp: SystemTime,
348    pub queue_length: usize,
349    pub utilization: f64,
350    pub avg_queue_time_secs: f64,
351    pub success_rate: f64,
352}
353
354/// Queue analytics and predictions
355#[derive(Debug, Clone)]
356pub struct QueueAnalytics {
357    /// Current total queue length across all backends
358    pub total_queue_length: usize,
359    /// Queue length by priority
360    pub queue_by_priority: HashMap<JobPriority, usize>,
361    /// Queue length by backend
362    pub queue_by_backend: HashMap<HardwareBackend, usize>,
363    /// Predicted queue times
364    pub predicted_queue_times: HashMap<HardwareBackend, Duration>,
365    /// System load metrics
366    pub system_load: f64,
367    /// Throughput (jobs per hour)
368    pub throughput: f64,
369    /// Average wait time
370    pub avg_wait_time: Duration,
371}
372
373/// Job scheduling optimization parameters
374#[derive(Debug, Clone)]
375pub struct SchedulingParams {
376    /// Scheduling strategy
377    pub strategy: SchedulingStrategy,
378    /// Resource allocation strategy
379    pub allocation_strategy: AllocationStrategy,
380    /// Time slice for round robin (if applicable)
381    pub time_slice: Duration,
382    /// Maximum jobs per user in queue
383    pub max_jobs_per_user: Option<usize>,
384    /// Fair share weights by user/group
385    pub fair_share_weights: HashMap<String, f64>,
386    /// Backfill threshold
387    pub backfill_threshold: Duration,
388    /// Load balancing parameters
389    pub load_balance_factor: f64,
390    /// SciRS2 optimization parameters
391    pub scirs2_params: SciRS2SchedulingParams,
392}
393
394/// Advanced SciRS2-specific scheduling optimization parameters
395#[derive(Debug, Clone)]
396pub struct SciRS2SchedulingParams {
397    /// Enable SciRS2 optimization
398    pub enabled: bool,
399    /// Optimization objective weights
400    pub objective_weights: HashMap<String, f64>,
401    /// Historical data window for learning
402    pub learning_window: Duration,
403    /// Optimization frequency
404    pub optimization_frequency: Duration,
405    /// Prediction model parameters
406    pub model_params: HashMap<String, f64>,
407    /// Machine learning algorithm selection
408    pub ml_algorithm: MLAlgorithm,
409    /// Multi-objective optimization weights
410    pub multi_objective_weights: MultiObjectiveWeights,
411    /// Reinforcement learning parameters
412    pub rl_params: RLParameters,
413    /// Genetic algorithm parameters
414    pub ga_params: GAParameters,
415    /// Enable predictive modeling
416    pub enable_prediction: bool,
417    /// Model retraining frequency
418    pub retrain_frequency: Duration,
419    /// Feature engineering parameters
420    pub feature_params: FeatureParams,
421}
422
423impl Default for SciRS2SchedulingParams {
424    fn default() -> Self {
425        Self {
426            enabled: true,
427            objective_weights: [
428                ("throughput".to_string(), 0.25),
429                ("fairness".to_string(), 0.25),
430                ("utilization".to_string(), 0.2),
431                ("cost".to_string(), 0.15),
432                ("energy".to_string(), 0.1),
433                ("sla_compliance".to_string(), 0.05),
434            ]
435            .into_iter()
436            .collect(),
437            learning_window: Duration::from_secs(86400), // 24 hours
438            optimization_frequency: Duration::from_secs(180), // 3 minutes
439            model_params: HashMap::new(),
440            ml_algorithm: MLAlgorithm::EnsembleMethod,
441            multi_objective_weights: MultiObjectiveWeights::default(),
442            rl_params: RLParameters::default(),
443            ga_params: GAParameters::default(),
444            enable_prediction: true,
445            retrain_frequency: Duration::from_secs(3600), // 1 hour
446            feature_params: FeatureParams::default(),
447        }
448    }
449}
450
451impl Default for SchedulingParams {
452    fn default() -> Self {
453        Self {
454            strategy: SchedulingStrategy::MLOptimized,
455            allocation_strategy: AllocationStrategy::SciRS2Optimized,
456            time_slice: Duration::from_secs(60),
457            max_jobs_per_user: Some(100),
458            fair_share_weights: HashMap::new(),
459            backfill_threshold: Duration::from_secs(300),
460            load_balance_factor: 0.8,
461            scirs2_params: SciRS2SchedulingParams::default(),
462        }
463    }
464}
465
466/// Advanced Job Scheduler and Queue Manager
467pub struct QuantumJobScheduler {
468    /// Scheduling parameters
469    pub(super) params: Arc<RwLock<SchedulingParams>>,
470    /// Job queues by priority level
471    pub(super) job_queues: Arc<Mutex<BTreeMap<JobPriority, VecDeque<JobId>>>>,
472    /// All active jobs
473    pub(super) jobs: Arc<RwLock<HashMap<JobId, Box<dyn std::any::Any + Send + Sync>>>>,
474    /// Backend performance tracking
475    pub(super) backend_performance: Arc<RwLock<HashMap<HardwareBackend, BackendPerformance>>>,
476    /// Available backends
477    pub(super) backends: Arc<RwLock<HashSet<HardwareBackend>>>,
478    /// Running jobs
479    pub(super) running_jobs: Arc<RwLock<HashMap<JobId, (HardwareBackend, SystemTime)>>>,
480    /// Job execution history
481    pub(super) execution_history: Arc<RwLock<Vec<JobExecution>>>,
482    /// User fair share tracking
483    pub(super) user_shares: Arc<RwLock<HashMap<String, UserShare>>>,
484    /// Scheduler control
485    pub(super) scheduler_running: Arc<Mutex<bool>>,
486    /// Event notifications
487    pub(super) event_sender: mpsc::UnboundedSender<SchedulerEvent>,
488    /// Performance predictor
489    pub(super) performance_predictor: Arc<Mutex<PerformancePredictor>>,
490    /// Resource manager
491    pub(super) resource_manager: Arc<Mutex<ResourceManager>>,
492    /// Lightweight job-status side-channel (type-erased jobs cannot carry mutable status)
493    pub(super) job_status_map: Arc<RwLock<HashMap<JobId, JobStatus>>>,
494    /// Job config side-channel for resource-aware backend selection (avoids downcasting Any)
495    pub(super) job_config_map: Arc<RwLock<HashMap<JobId, JobConfig>>>,
496    /// Execution metrics side-channel for recording start/end times without downcasting
497    pub(super) job_metrics_map: Arc<RwLock<HashMap<JobId, ExecutionMetrics>>>,
498}
499
500/// User fair share tracking
501#[derive(Debug, Clone)]
502pub(super) struct UserShare {
503    pub(super) user_id: String,
504    pub(super) allocated_share: f64,
505    pub(super) used_share: f64,
506    pub(super) jobs_running: usize,
507    pub(super) jobs_queued: usize,
508    pub(super) last_updated: SystemTime,
509}
510
511/// Scheduler events for monitoring and notifications
512#[derive(Debug, Clone)]
513pub enum SchedulerEvent {
514    JobSubmitted(JobId),
515    JobScheduled(JobId, HardwareBackend),
516    JobStarted(JobId),
517    JobCompleted(JobId, CircuitResult),
518    JobFailed(JobId, String),
519    JobCancelled(JobId),
520    BackendStatusChanged(HardwareBackend, BackendStatus),
521    QueueAnalyticsUpdated(QueueAnalytics),
522}
523
524/// Backend status information
525#[derive(Debug, Clone)]
526pub enum BackendStatus {
527    Available,
528    Busy,
529    Maintenance,
530    Offline,
531    Error(String),
532}
533
534/// Performance prediction using SciRS2 algorithms
535pub(super) struct PerformancePredictor {
536    /// Historical performance data
537    pub(super) history: VecDeque<PredictionDataPoint>,
538    /// Learned model parameters
539    pub(super) model_params: HashMap<String, f64>,
540    /// Prediction accuracy metrics
541    pub(super) accuracy_metrics: HashMap<String, f64>,
542}
543
544/// Data point for performance prediction
545#[derive(Debug, Clone)]
546pub(super) struct PredictionDataPoint {
547    pub(super) timestamp: SystemTime,
548    pub(super) backend: HardwareBackend,
549    pub(super) queue_length: usize,
550    pub(super) job_complexity: f64,
551    pub(super) execution_time: Duration,
552    pub(super) success: bool,
553}
554
555/// Resource allocation and management
556pub(super) struct ResourceManager {
557    /// Available resources by backend
558    pub(super) available_resources: HashMap<HardwareBackend, ResourceCapacity>,
559    /// Resource reservations
560    pub(super) reservations: HashMap<JobId, ResourceReservation>,
561    /// Resource utilization history
562    pub(super) utilization_history: VecDeque<ResourceSnapshot>,
563}
564
565/// Resource capacity for a backend
566#[derive(Debug, Clone)]
567pub(super) struct ResourceCapacity {
568    pub(super) qubits: usize,
569    pub(super) max_circuit_depth: Option<usize>,
570    pub(super) memory_mb: u64,
571    pub(super) cpu_cores: u32,
572    pub(super) concurrent_jobs: usize,
573    pub(super) features: HashSet<String>,
574}
575
576/// Resource reservation for a job
577#[derive(Debug, Clone)]
578pub(super) struct ResourceReservation {
579    pub(super) job_id: JobId,
580    pub(super) backend: HardwareBackend,
581    pub(super) resources: ResourceRequirements,
582    pub(super) reserved_at: SystemTime,
583    pub(super) expires_at: SystemTime,
584}
585
586/// Resource utilization snapshot
587#[derive(Debug, Clone)]
588pub(super) struct ResourceSnapshot {
589    pub(super) timestamp: SystemTime,
590    pub(super) backend: HardwareBackend,
591    pub(super) utilization: f64,
592    pub(super) active_jobs: usize,
593}
594
595/// Advanced machine learning algorithms for scheduling
596#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
597pub enum MLAlgorithm {
598    /// Linear regression for simple predictions
599    LinearRegression,
600    /// Support Vector Machine for classification
601    SVM,
602    /// Random Forest for ensemble learning
603    RandomForest,
604    /// Gradient Boosting for performance optimization
605    GradientBoosting,
606    /// Neural Network for complex patterns
607    NeuralNetwork,
608    /// Ensemble method combining multiple algorithms
609    EnsembleMethod,
610    /// Deep Reinforcement Learning
611    DeepRL,
612    /// Graph Neural Network for topology-aware scheduling
613    GraphNN,
614}
615
616/// Multi-objective optimization weights
617#[derive(Debug, Clone, Serialize, Deserialize)]
618pub struct MultiObjectiveWeights {
619    /// Throughput optimization weight
620    pub throughput: f64,
621    /// Cost minimization weight
622    pub cost: f64,
623    /// Energy efficiency weight
624    pub energy: f64,
625    /// Fairness weight
626    pub fairness: f64,
627    /// SLA compliance weight
628    pub sla_compliance: f64,
629    /// Quality of service weight
630    pub qos: f64,
631}
632
633/// Reinforcement Learning parameters
634#[derive(Debug, Clone, Serialize, Deserialize)]
635pub struct RLParameters {
636    /// Learning rate
637    pub learning_rate: f64,
638    /// Discount factor
639    pub discount_factor: f64,
640    /// Exploration rate
641    pub exploration_rate: f64,
642    /// Episode length
643    pub episode_length: usize,
644    /// Reward function weights
645    pub reward_weights: HashMap<String, f64>,
646    /// State representation dimension
647    pub state_dimension: usize,
648    /// Action space size
649    pub action_space_size: usize,
650}
651
652/// Genetic Algorithm parameters
653#[derive(Debug, Clone, Serialize, Deserialize)]
654pub struct GAParameters {
655    /// Population size
656    pub population_size: usize,
657    /// Number of generations
658    pub generations: usize,
659    /// Crossover probability
660    pub crossover_prob: f64,
661    /// Mutation probability
662    pub mutation_prob: f64,
663    /// Selection strategy
664    pub selection_strategy: String,
665    /// Elite size
666    pub elite_size: usize,
667}
668
669/// Feature engineering parameters
670#[derive(Debug, Clone, Serialize, Deserialize)]
671pub struct FeatureParams {
672    /// Enable time-based features
673    pub enable_temporal_features: bool,
674    /// Enable circuit complexity features
675    pub enable_complexity_features: bool,
676    /// Enable user behavior features
677    pub enable_user_features: bool,
678    /// Enable platform performance features
679    pub enable_platform_features: bool,
680    /// Enable historical pattern features
681    pub enable_historical_features: bool,
682    /// Feature normalization method
683    pub normalization_method: String,
684    /// Feature selection threshold
685    pub selection_threshold: f64,
686}
687
688/// Service Level Agreement configuration
689#[derive(Debug, Clone, Serialize, Deserialize)]
690pub struct SLAConfig {
691    /// Maximum allowed queue time
692    pub max_queue_time: Duration,
693    /// Maximum allowed execution time
694    pub max_execution_time: Duration,
695    /// Minimum required availability
696    pub min_availability: f64,
697    /// Penalty for SLA violations
698    pub violation_penalty: f64,
699    /// SLA tier (Gold, Silver, Bronze)
700    pub tier: SLATier,
701}
702
703/// SLA tier levels
704#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
705pub enum SLATier {
706    Gold,
707    Silver,
708    Bronze,
709    Basic,
710}
711
712/// Default implementations for new types
713impl Default for MultiObjectiveWeights {
714    fn default() -> Self {
715        Self {
716            throughput: 0.3,
717            cost: 0.2,
718            energy: 0.15,
719            fairness: 0.15,
720            sla_compliance: 0.1,
721            qos: 0.1,
722        }
723    }
724}
725
726impl Default for RLParameters {
727    fn default() -> Self {
728        Self {
729            learning_rate: 0.001,
730            discount_factor: 0.95,
731            exploration_rate: 0.1,
732            episode_length: 1000,
733            reward_weights: [
734                ("throughput".to_string(), 1.0),
735                ("fairness".to_string(), 0.5),
736                ("cost".to_string(), -0.3),
737            ]
738            .into_iter()
739            .collect(),
740            state_dimension: 64,
741            action_space_size: 16,
742        }
743    }
744}
745
746impl Default for GAParameters {
747    fn default() -> Self {
748        Self {
749            population_size: 50,
750            generations: 100,
751            crossover_prob: 0.8,
752            mutation_prob: 0.1,
753            selection_strategy: "tournament".to_string(),
754            elite_size: 5,
755        }
756    }
757}
758
759impl Default for FeatureParams {
760    fn default() -> Self {
761        Self {
762            enable_temporal_features: true,
763            enable_complexity_features: true,
764            enable_user_features: true,
765            enable_platform_features: true,
766            enable_historical_features: true,
767            normalization_method: "z_score".to_string(),
768            selection_threshold: 0.1,
769        }
770    }
771}