#[derive(Debug, Clone, PartialEq, Default)]
pub enum Distribution {
#[default]
Shuffled,
NearlySorted,
Reversed,
FewUnique,
Sorted,
WithDuplicates,
}
#[derive(Debug, Clone, PartialEq)]
pub enum FairnessMode {
ComparisonBudget { k: usize },
Weighted { alpha: f32, beta: f32 },
WallTime { slice_ms: u64 },
Adaptive { learning_rate: f32 },
EqualSteps,
}
impl Default for FairnessMode {
fn default() -> Self {
FairnessMode::ComparisonBudget { k: 10 }
}
}
#[derive(Debug, Clone)]
pub struct RunConfiguration {
pub array_size: usize,
pub distribution: Distribution,
pub seed: u64,
pub fairness_mode: FairnessMode,
pub target_fps: u32,
}
impl Default for RunConfiguration {
fn default() -> Self {
Self {
array_size: 100,
distribution: Distribution::default(),
seed: 42,
fairness_mode: FairnessMode::default(),
target_fps: 30,
}
}
}
impl RunConfiguration {
pub fn new() -> Self {
Self::default()
}
pub fn with_array_size(mut self, size: usize) -> Self {
self.array_size = size;
self
}
pub fn with_distribution(mut self, distribution: Distribution) -> Self {
self.distribution = distribution;
self
}
pub fn with_seed(mut self, seed: u64) -> Self {
self.seed = seed;
self
}
pub fn with_fairness_mode(mut self, fairness_mode: FairnessMode) -> Self {
self.fairness_mode = fairness_mode;
self
}
pub fn with_target_fps(mut self, fps: u32) -> Self {
self.target_fps = fps;
self
}
pub fn validate(&self) -> Result<(), String> {
if self.array_size == 0 {
return Err("Array size must be greater than 0".to_string());
}
if self.target_fps == 0 {
return Err("Target FPS must be greater than 0".to_string());
}
match &self.fairness_mode {
FairnessMode::ComparisonBudget { k } => {
if *k == 0 {
return Err("Comparison budget must be greater than 0".to_string());
}
}
FairnessMode::WallTime { slice_ms } => {
if *slice_ms == 0 {
return Err("Wall time limit must be greater than 0".to_string());
}
}
FairnessMode::Weighted { alpha, beta } => {
if *alpha < 0.0 || *beta < 0.0 {
return Err("Weights must be non-negative".to_string());
}
}
FairnessMode::Adaptive { learning_rate } => {
if *learning_rate < 0.0 || *learning_rate > 1.0 {
return Err("Learning rate must be between 0.0 and 1.0".to_string());
}
}
FairnessMode::EqualSteps => {}
}
Ok(())
}
}
#[derive(Debug, Clone)]
pub struct VisualConfiguration {
pub window_width: u32,
pub window_height: u32,
pub show_comparisons: bool,
pub show_names: bool,
pub show_metrics: bool,
pub animation_speed: f32,
}
impl Default for VisualConfiguration {
fn default() -> Self {
Self {
window_width: 800,
window_height: 600,
show_comparisons: true,
show_names: true,
show_metrics: true,
animation_speed: 1.0,
}
}
}