added new voting system
This commit is contained in:
parent
ae8b1c8989
commit
ba091c6803
|
|
@ -41,5 +41,26 @@ impl Counter {
|
|||
scores
|
||||
}
|
||||
|
||||
pub fn count_all_with_powers_of_2(&self, ty: BallotType, running: &[bool]) -> Vec<f64> {
|
||||
let mut scores = vec![0.0; running.len()];
|
||||
|
||||
for ballot in self.ballots.iter() {
|
||||
if ballot.ty != ty {
|
||||
continue;
|
||||
}
|
||||
let mut m = 0.5;
|
||||
for &id in ballot.votes.iter() {
|
||||
if !running[id] {
|
||||
continue;
|
||||
}
|
||||
scores[id] += m;
|
||||
m *= 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
scores
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,15 +65,15 @@ fn main() {
|
|||
println!();
|
||||
eprintln!("Running election rounds:");
|
||||
|
||||
let mut scores: Vec<u32> = Vec::new();
|
||||
let mut scores: Vec<f64> = Vec::new();
|
||||
|
||||
for index in 0..(running.len() - winner_count) {
|
||||
scores = counter.count_primaries(ty, &running);
|
||||
let (id_worst, score_worst) = match scores.iter().copied().enumerate().filter(|&(i,_)| running[i]).min_by(|a, b| u32::cmp(&a.1, &b.1)) {
|
||||
scores = counter.count_all_with_powers_of_2(ty, &running);
|
||||
let (id_worst, score_worst) = match scores.iter().copied().enumerate().filter(|&(i,_)| running[i]).min_by(|a, b| f64::total_cmp(&a.1, &b.1)) {
|
||||
Some(v) => v,
|
||||
None => break
|
||||
};
|
||||
let (id_best, score_best) = match scores.iter().copied().enumerate().filter(|&(i,_)| running[i]).min_by(|a, b| u32::cmp(&b.1, &a.1)) {
|
||||
let (id_best, score_best) = match scores.iter().copied().enumerate().filter(|&(i,_)| running[i]).min_by(|a, b| f64::total_cmp(&b.1, &a.1)) {
|
||||
Some(v) => v,
|
||||
None => break,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue