Validate option combinations
This commit is contained in:
parent
2e034d06c8
commit
08821c3c18
|
@ -378,8 +378,8 @@ function changePreset() {
|
||||||
document.getElementById('txtMeekSurplusTolerance').value = '0.001%';
|
document.getElementById('txtMeekSurplusTolerance').value = '0.001%';
|
||||||
//document.getElementById('selSurplus').value = 'by_size';
|
//document.getElementById('selSurplus').value = 'by_size';
|
||||||
document.getElementById('selTransfers').value = 'meek';
|
document.getElementById('selTransfers').value = 'meek';
|
||||||
//document.getElementById('selPapers').value = 'both';
|
document.getElementById('selPapers').value = 'both';
|
||||||
//document.getElementById('selExclusion').value = 'single_stage';
|
document.getElementById('selExclusion').value = 'single_stage';
|
||||||
document.getElementById('selTies').value = 'backwards,random';
|
document.getElementById('selTies').value = 'backwards,random';
|
||||||
} else if (document.getElementById('selPreset').value === 'meek06') {
|
} else if (document.getElementById('selPreset').value === 'meek06') {
|
||||||
document.getElementById('selQuotaCriterion').value = 'geq';
|
document.getElementById('selQuotaCriterion').value = 'geq';
|
||||||
|
@ -406,8 +406,8 @@ function changePreset() {
|
||||||
document.getElementById('txtMeekSurplusTolerance').value = '0.0001';
|
document.getElementById('txtMeekSurplusTolerance').value = '0.0001';
|
||||||
//document.getElementById('selSurplus').value = 'by_size';
|
//document.getElementById('selSurplus').value = 'by_size';
|
||||||
document.getElementById('selTransfers').value = 'meek';
|
document.getElementById('selTransfers').value = 'meek';
|
||||||
//document.getElementById('selPapers').value = 'both';
|
document.getElementById('selPapers').value = 'both';
|
||||||
//document.getElementById('selExclusion').value = 'single_stage';
|
document.getElementById('selExclusion').value = 'single_stage';
|
||||||
document.getElementById('selTies').value = 'backwards,random';
|
document.getElementById('selTies').value = 'backwards,random';
|
||||||
} else if (document.getElementById('selPreset').value === 'meeknz') {
|
} else if (document.getElementById('selPreset').value === 'meeknz') {
|
||||||
document.getElementById('selQuotaCriterion').value = 'geq';
|
document.getElementById('selQuotaCriterion').value = 'geq';
|
||||||
|
@ -434,8 +434,8 @@ function changePreset() {
|
||||||
document.getElementById('txtMeekSurplusTolerance').value = '0.0001';
|
document.getElementById('txtMeekSurplusTolerance').value = '0.0001';
|
||||||
//document.getElementById('selSurplus').value = 'by_size';
|
//document.getElementById('selSurplus').value = 'by_size';
|
||||||
document.getElementById('selTransfers').value = 'meek';
|
document.getElementById('selTransfers').value = 'meek';
|
||||||
//document.getElementById('selPapers').value = 'both';
|
document.getElementById('selPapers').value = 'both';
|
||||||
//document.getElementById('selExclusion').value = 'single_stage';
|
document.getElementById('selExclusion').value = 'single_stage';
|
||||||
document.getElementById('selTies').value = 'backwards,random';
|
document.getElementById('selTies').value = 'backwards,random';
|
||||||
} else if (document.getElementById('selPreset').value === 'senate') {
|
} else if (document.getElementById('selPreset').value === 'senate') {
|
||||||
document.getElementById('selQuotaCriterion').value = 'geq';
|
document.getElementById('selQuotaCriterion').value = 'geq';
|
||||||
|
|
|
@ -36,6 +36,9 @@ onmessage = function(evt) {
|
||||||
// Init STV options
|
// Init STV options
|
||||||
opts = wasm.STVOptions.new.apply(null, evt.data.optsStr);
|
opts = wasm.STVOptions.new.apply(null, evt.data.optsStr);
|
||||||
|
|
||||||
|
// Validate options
|
||||||
|
opts.validate();
|
||||||
|
|
||||||
// Describe count
|
// Describe count
|
||||||
postMessage({'type': 'describeCount', 'content': wasm['describe_count_' + numbers](evt.data.filePath, election, opts)});
|
postMessage({'type': 'describeCount', 'content': wasm['describe_count_' + numbers](evt.data.filePath, election, opts)});
|
||||||
|
|
||||||
|
|
|
@ -198,6 +198,14 @@ impl STVOptions {
|
||||||
if self.pp_decimals != 2 { flags.push(format!("--pp-decimals {}", self.pp_decimals)); }
|
if self.pp_decimals != 2 { flags.push(format!("--pp-decimals {}", self.pp_decimals)); }
|
||||||
return flags.join(" ");
|
return flags.join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Validate the combination of [STVOptions] and panic if invalid
|
||||||
|
pub fn validate(&self) {
|
||||||
|
if self.surplus == SurplusMethod::Meek {
|
||||||
|
if self.transferable_only { panic!("--surplus meek is incompatible with --transferable-only"); }
|
||||||
|
if self.exclusion != ExclusionMethod::SingleStage { panic!("--surplus meek requires --exclusion single_stage"); }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enum of options for [STVOptions::sum_surplus_transfers]
|
/// Enum of options for [STVOptions::sum_surplus_transfers]
|
||||||
|
@ -929,12 +937,21 @@ where
|
||||||
for<'r> &'r N: ops::Mul<&'r N, Output=N>,
|
for<'r> &'r N: ops::Mul<&'r N, Output=N>,
|
||||||
for<'r> &'r N: ops::Div<&'r N, Output=N>,
|
for<'r> &'r N: ops::Div<&'r N, Output=N>,
|
||||||
{
|
{
|
||||||
match opts.surplus {
|
match opts.exclusion {
|
||||||
SurplusMethod::WIG | SurplusMethod::UIG | SurplusMethod::EG => {
|
ExclusionMethod::SingleStage => {
|
||||||
|
match opts.surplus {
|
||||||
|
SurplusMethod::WIG | SurplusMethod::UIG | SurplusMethod::EG => {
|
||||||
|
gregory::exclude_candidates(state, opts, excluded_candidates);
|
||||||
|
}
|
||||||
|
SurplusMethod::Meek => {
|
||||||
|
meek::exclude_candidates(state, opts, excluded_candidates);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ExclusionMethod::ByValue | ExclusionMethod::ParcelsByOrder => {
|
||||||
|
// Exclusion in parts compatible only with Gregory method
|
||||||
gregory::exclude_candidates(state, opts, excluded_candidates);
|
gregory::exclude_candidates(state, opts, excluded_candidates);
|
||||||
}
|
}
|
||||||
SurplusMethod::Meek => {
|
|
||||||
meek::exclude_candidates(state, opts, excluded_candidates);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,6 +229,11 @@ impl STVOptions {
|
||||||
pp_decimals,
|
pp_decimals,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Wrapper for [stv::STVOptions::validate]
|
||||||
|
pub fn validate(&self) {
|
||||||
|
self.0.validate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl STVOptions {
|
impl STVOptions {
|
||||||
|
|
Loading…
Reference in New Issue