Implement --surplus-order
This commit is contained in:
parent
76d69913c7
commit
a4a28f3345
|
@ -72,6 +72,9 @@ struct STV {
|
||||||
#[clap(help_heading=Some("STV VARIANTS"), long, possible_values=&["wig", "uig", "eg", "meek"], default_value="wig", value_name="method")]
|
#[clap(help_heading=Some("STV VARIANTS"), long, possible_values=&["wig", "uig", "eg", "meek"], default_value="wig", value_name="method")]
|
||||||
surplus: String,
|
surplus: String,
|
||||||
|
|
||||||
|
#[clap(help_heading=Some("STV VARIANTS"), long, possible_values=&["by_size", "by_order"], default_value="by_size", value_name="order")]
|
||||||
|
surplus_order: String,
|
||||||
|
|
||||||
/// Examine only transferable papers during surplus distributions
|
/// Examine only transferable papers during surplus distributions
|
||||||
#[clap(help_heading=Some("STV VARIANTS"), long)]
|
#[clap(help_heading=Some("STV VARIANTS"), long)]
|
||||||
transferable_only: bool,
|
transferable_only: bool,
|
||||||
|
@ -131,6 +134,11 @@ where
|
||||||
"meek" => stv::SurplusMethod::Meek,
|
"meek" => stv::SurplusMethod::Meek,
|
||||||
_ => panic!("Invalid --surplus"),
|
_ => panic!("Invalid --surplus"),
|
||||||
},
|
},
|
||||||
|
surplus_order: match cmd_opts.surplus_order.as_str() {
|
||||||
|
"by_size" => stv::SurplusOrder::BySize,
|
||||||
|
"by_order" => stv::SurplusOrder::ByOrder,
|
||||||
|
_ => panic!("Invalid --surplus-order"),
|
||||||
|
},
|
||||||
transferable_only: cmd_opts.transferable_only,
|
transferable_only: cmd_opts.transferable_only,
|
||||||
exclusion: match cmd_opts.exclusion.as_str() {
|
exclusion: match cmd_opts.exclusion.as_str() {
|
||||||
"single_stage" => stv::ExclusionMethod::SingleStage,
|
"single_stage" => stv::ExclusionMethod::SingleStage,
|
||||||
|
|
|
@ -32,6 +32,7 @@ use std::ops;
|
||||||
pub struct STVOptions {
|
pub struct STVOptions {
|
||||||
pub round_votes: Option<usize>,
|
pub round_votes: Option<usize>,
|
||||||
pub surplus: SurplusMethod,
|
pub surplus: SurplusMethod,
|
||||||
|
pub surplus_order: SurplusOrder,
|
||||||
pub transferable_only: bool,
|
pub transferable_only: bool,
|
||||||
pub exclusion: ExclusionMethod,
|
pub exclusion: ExclusionMethod,
|
||||||
pub pp_decimals: usize,
|
pub pp_decimals: usize,
|
||||||
|
@ -46,6 +47,13 @@ pub enum SurplusMethod {
|
||||||
Meek,
|
Meek,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
pub enum SurplusOrder {
|
||||||
|
BySize,
|
||||||
|
ByOrder,
|
||||||
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum ExclusionMethod {
|
pub enum ExclusionMethod {
|
||||||
|
@ -253,8 +261,14 @@ where
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if has_surplus.len() > 0 {
|
if has_surplus.len() > 0 {
|
||||||
// TODO: Different sorting orders
|
match opts.surplus_order {
|
||||||
has_surplus.sort_unstable_by(|a, b| a.1.order_elected.partial_cmp(&b.1.order_elected).unwrap());
|
SurplusOrder::BySize => {
|
||||||
|
has_surplus.sort_unstable_by(|a, b| a.1.votes.partial_cmp(&b.1.votes).unwrap());
|
||||||
|
}
|
||||||
|
SurplusOrder::ByOrder => {
|
||||||
|
has_surplus.sort_unstable_by(|a, b| a.1.order_elected.partial_cmp(&b.1.order_elected).unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Distribute top candidate's surplus
|
// Distribute top candidate's surplus
|
||||||
// TODO: Handle ties
|
// TODO: Handle ties
|
||||||
|
|
|
@ -56,6 +56,7 @@ fn aec_tas19_rational() {
|
||||||
let stv_opts = stv::STVOptions {
|
let stv_opts = stv::STVOptions {
|
||||||
round_votes: Some(0),
|
round_votes: Some(0),
|
||||||
surplus: stv::SurplusMethod::UIG,
|
surplus: stv::SurplusMethod::UIG,
|
||||||
|
surplus_order: stv::SurplusOrder::ByOrder,
|
||||||
transferable_only: false,
|
transferable_only: false,
|
||||||
exclusion: stv::ExclusionMethod::ByValue,
|
exclusion: stv::ExclusionMethod::ByValue,
|
||||||
pp_decimals: 2,
|
pp_decimals: 2,
|
||||||
|
|
Loading…
Reference in New Issue