diff --git a/html/index.js b/html/index.js
index edb8bd1..bd8a814 100644
--- a/html/index.js
+++ b/html/index.js
@@ -378,8 +378,8 @@ function changePreset() {
document.getElementById('txtMeekSurplusTolerance').value = '0.001%';
//document.getElementById('selSurplus').value = 'by_size';
document.getElementById('selTransfers').value = 'meek';
- //document.getElementById('selPapers').value = 'both';
- //document.getElementById('selExclusion').value = 'single_stage';
+ document.getElementById('selPapers').value = 'both';
+ document.getElementById('selExclusion').value = 'single_stage';
document.getElementById('selTies').value = 'backwards,random';
} else if (document.getElementById('selPreset').value === 'meek06') {
document.getElementById('selQuotaCriterion').value = 'geq';
@@ -406,8 +406,8 @@ function changePreset() {
document.getElementById('txtMeekSurplusTolerance').value = '0.0001';
//document.getElementById('selSurplus').value = 'by_size';
document.getElementById('selTransfers').value = 'meek';
- //document.getElementById('selPapers').value = 'both';
- //document.getElementById('selExclusion').value = 'single_stage';
+ document.getElementById('selPapers').value = 'both';
+ document.getElementById('selExclusion').value = 'single_stage';
document.getElementById('selTies').value = 'backwards,random';
} else if (document.getElementById('selPreset').value === 'meeknz') {
document.getElementById('selQuotaCriterion').value = 'geq';
@@ -434,8 +434,8 @@ function changePreset() {
document.getElementById('txtMeekSurplusTolerance').value = '0.0001';
//document.getElementById('selSurplus').value = 'by_size';
document.getElementById('selTransfers').value = 'meek';
- //document.getElementById('selPapers').value = 'both';
- //document.getElementById('selExclusion').value = 'single_stage';
+ document.getElementById('selPapers').value = 'both';
+ document.getElementById('selExclusion').value = 'single_stage';
document.getElementById('selTies').value = 'backwards,random';
} else if (document.getElementById('selPreset').value === 'senate') {
document.getElementById('selQuotaCriterion').value = 'geq';
diff --git a/html/worker.js b/html/worker.js
index 7d5ef5f..c5dde8f 100644
--- a/html/worker.js
+++ b/html/worker.js
@@ -36,6 +36,9 @@ onmessage = function(evt) {
// Init STV options
opts = wasm.STVOptions.new.apply(null, evt.data.optsStr);
+ // Validate options
+ opts.validate();
+
// Describe count
postMessage({'type': 'describeCount', 'content': wasm['describe_count_' + numbers](evt.data.filePath, election, opts)});
diff --git a/src/stv/mod.rs b/src/stv/mod.rs
index a686d41..28e1913 100644
--- a/src/stv/mod.rs
+++ b/src/stv/mod.rs
@@ -198,6 +198,14 @@ impl STVOptions {
if self.pp_decimals != 2 { flags.push(format!("--pp-decimals {}", self.pp_decimals)); }
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]
@@ -929,12 +937,21 @@ where
for<'r> &'r N: ops::Mul<&'r N, Output=N>,
for<'r> &'r N: ops::Div<&'r N, Output=N>,
{
- match opts.surplus {
- SurplusMethod::WIG | SurplusMethod::UIG | SurplusMethod::EG => {
+ match opts.exclusion {
+ 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);
}
- SurplusMethod::Meek => {
- meek::exclude_candidates(state, opts, excluded_candidates);
}
}
}
diff --git a/src/stv/wasm.rs b/src/stv/wasm.rs
index ec7964d..e13b44b 100644
--- a/src/stv/wasm.rs
+++ b/src/stv/wasm.rs
@@ -229,6 +229,11 @@ impl STVOptions {
pp_decimals,
))
}
+
+ /// Wrapper for [stv::STVOptions::validate]
+ pub fn validate(&self) {
+ self.0.validate();
+ }
}
impl STVOptions {