Anti-Harassment Tools/SecurePoll Improvements/Test Results/100 so2011 2 elections

From mediawiki.org
Jump to navigation Jump to search

Comments[edit]

I used a script to generate 100 random elections. The popularity of the candidates followed the same distribution as first preference votes in the Stack Overflow 2011 (2nd) moderator elections. My hope was to simulate re-running that election 100 times.

Election setup[edit]

  • Candidates: 12
  • Seats: 4
  • Votes: 5000

Comparisons[edit]

A script compared the candidates SecurePoll and OpenSTV elected. No discrepancies between elected candidates were found in 100 elections.

R code used to generate test data[edit]

writeBallot <- function(filename, ballots, candidates, numSeats, totalVotes) {
    sink(filename)

    cat(sprintf("%s %s", length(candidates), numSeats))
    cat("\n")
    for (i in 1:totalVotes) {
        cat("1")
        for (cand in ballots[[i]]) {
            if (!is.na(cand)) {
                cat(" ")
                cat(cand)
            }
        }
        cat(" 0")
        cat("\n")
    }
    cat("0")
    cat("\n")
    for (candidate in candidates) {
        cat("\"")
        cat(candidate)
        cat("\"")
        cat("\n")
    }
    cat("\"")
    cat("ElectionTitle")
    cat("\"")
    cat("\n")

    sink()
}

candidates <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
numSeats <- 4
totalVotes <- 5000

## stackoverflow-com-2011-election-results_2.csv comes from here: https://github.com/dominic998/SecurePoll-Test-Data/blob/main/test_data/stackoverflow-com-2011-election-results_2.csv
so2011_2 <- read.csv("stackoverflow-com-2011-election-results_2.csv", header=FALSE)
distribution <- table(so2011_2$V1)

for (j in 1:100) {

    ballots <- list()
    for (i in 1:totalVotes) {
        ballots[[i]] <- sample(1:length(candidates), sample(1:length(candidates), 1), replace=FALSE, distribution)
    }

    randomInt <- sample(1:9999999999, 1)
    filename <- sprintf("%s_%s_%s_%s.blt", length(candidates), numSeats, totalVotes, randomInt)

    writeBallot(filename, ballots, candidates, numSeats, totalVotes)

}

Files[edit]

All test data and output here: https://github.com/dominic998/SecurePoll-Test-Data/tree/main/test_data/100_so2011_2_elections

  • Test blt files: files ending in .blt
  • SecurePoll results: files ending _results.txt
  • OpenSTV results: files ending in .php

Environment[edit]

  • Where you tested: local docker using PHPUnit
  • Version of SecurePoll: 3.0.0 (58bf4c8) 11:07, 31 August 2021