Page MenuHomePhabricator

Implement STVTallier::addVote() [M]
Closed, ResolvedPublic

Description

Implement addVote() so that finishTally() has an aggregate result to work with. Copy pasta-ing from T283728#7139581:

This step would deal with writing the STVTallier constructor, unpackRecord(), and addVote(). addVote() should return something like:

[
  1 => [
    A => 2
    B => 0
    C => 1
  ],
  2 => [
    A => 1
    B => 1
    C => 1
  ],
  3 => [
    A => 0,
    B => 2,
    C => 1
  ]
]

Event Timeline

ARamirez_WMF renamed this task from Implement STVTallier::addVote() to Implement STVTallier::addVote() [M].Jun 9 2021, 4:19 PM

Tšepo and I agreed on a new aggregate schema to pass to the algorithm. The aggregation is to make it 1. easier to access votes at the rank they're needed at and 2. avoid having to loop through a lot of votes (say, 5k) more than once. This generates an x^2 large array where x is the number of candidates but it should still be more performant than trying to repeatedly loop through the votes to check their values at whatever rank is being calculated.

Given votes:

[A, B, C]
[C, A, B]
[A, C, B]

Aggregate them by choice at rank:

[
  1 => [
    A => 2
    B => 0
    C => 1
  ],
  2 => [
    A => 1
    B => 1
    C => 1
  ],
  3 => [
    A => 0,
    B => 2,
    C => 1
  ]
]

Change 699285 had a related patch set uploaded (by STran; author: STran):

[mediawiki/extensions/SecurePoll@master] Implement STVTallier::addVote

https://gerrit.wikimedia.org/r/699285

New schema based on another discussion with Tšepo. Looking at more practical/real-world examples, the specific combination of votes does matter for the weighting.

Given votes:

[A]
[B, C]
[B, C]
[A, B, C]
[C, A, B]
[
  'A' => [
    count => 1,
    rank => [
      1 => 'A'
      ]
    ],
  'BC' => [
    count => 2,
    rank => [
      1 => 'B',
      2 => 'C'
    ]
  ],
  'ABC' => [
    count => 1,
    rank => [
      1 => 'A',
      2 => 'B',
      3 => 'C
    ]
  ],
  'CAB' => [
    count => 1,
    rank => [
      1 => 'C',
      2 => 'A',
      3 => 'B'
    ]
  ]
]

Change 699285 merged by jenkins-bot:

[mediawiki/extensions/SecurePoll@master] Implement STVTallier::addVote

https://gerrit.wikimedia.org/r/699285