use super_fair_division::{calculate_fair_division_equal_weights, calculate_fair_division_weighted};
fn main() {
println!("Super Fair Division Library Demo\n");
let values = vec![100, 200, 300, 400, 500];
println!("Input values: {:?}", values);
match calculate_fair_division_equal_weights(&values) {
Ok(allocation) => {
println!("Equal weights allocation: {:?}", allocation);
let sum: i128 = allocation.iter().sum();
println!("Sum of allocations: {} (should be 0)\n", sum);
let mut max_v = values[0];
let mut max_index = 0;
for (i, &v) in values.iter().enumerate() {
if v > max_v {
max_v = v;
max_index = i;
}
}
println!("Highest bidder (index {}): {}", max_index, values[max_index]);
println!("Allocation for highest bidder: {}\n", allocation[max_index]);
},
Err(err) => eprintln!("Error calculating equal weights division: {:?}\n", err),
}
let values = vec![100, 200, 300, 400, 500];
let weights = vec![1, 2, 3, 4, 5];
println!("Input values: {:?}", values);
println!("Weights: {:?}", weights);
match calculate_fair_division_weighted(&values, &weights) {
Ok(allocation) => {
println!("Weighted allocation: {:?}", allocation);
let sum: i128 = allocation.iter().sum();
println!("Sum of allocations: {} (should be 0)\n", sum);
println!("Weight vs Allocation:");
for i in 0..values.len() {
println!("Weight: {}, Allocation: {}", weights[i], allocation[i]);
}
println!();
},
Err(err) => eprintln!("Error calculating weighted division: {:?}\n", err),
}
let edge_case = vec![i128::MAX / 2, i128::MIN / 2, i128::MAX / 4];
let edge_weights = vec![1, 2, 3];
println!("Edge case values: {:?}", edge_case);
println!("Edge case weights: {:?}", edge_weights);
match calculate_fair_division_equal_weights(&edge_case) {
Ok(allocation) => println!("Edge case equal weights allocation: {:?}", allocation),
Err(err) => eprintln!("Error with edge case equal weights: {:?}", err),
}
match calculate_fair_division_weighted(&edge_case, &edge_weights) {
Ok(allocation) => println!("Edge case weighted allocation: {:?}", allocation),
Err(err) => eprintln!("Error with edge case weighted: {:?}", err),
}
}