Vote weight
Description
You can add weight (integer >= 1
) to each vote. If you enable this mode at the election level (deactivated by default), then the votes will be proportional to their weight when calculating all the algorithms.
For example, if the weight is 2
, then the vote will count double. This is an alternative and complementary approach to adding multiple votes. Using this mode of operation can save you (for large elections) a high cost in RAM and can also speed up computation. It can prevent you from having to configure or develop a DataHandler, which can be complex. However, if you need to keep the information of each elector inside Condorcet, this functionality will not satisfy you. It is useful if, at this level, the voting information is useless or if it makes no sense.
$election->parseCandidates('A;B;C;D');
$election->parseVotes('
A > C > D * 6
B > A > D * 1
C > B > D * 3
D > B > A * 3
');
$voteWithWeight = $election->addVote('D > C > B'); // Returns a new vote object
$voteWithWeight->setWeight(2); // You set a weight, but weight is still not allowed at the election level.
// Return 'A > C > D > B'
$election->getResult('Schulze Winning')->rankingAsString;
$election->allowsVoteWeight(true);
// Return 'A = D > C > B'
$election->getResult('Schulze Winning')->rankingAsString;
$election->removeVote($voteWithWeight);
$election->parseVotes('
D > C > B ^2
');
// Return 'A = D > C > B',
$election->getResult('Schulze Winning')->rankingAsString;
$election->addVote('D > C > B');
$election->getVotesListAsString();
// Return D > C > B > A with 2 lines. one for weight ^2 and one for force ^1
/*
A > C > D > B * 6
C > B > D > A * 3
D > B > A > C * 3
D > C > B > A ^2 * 1
B > A > D > C * 1
D > C > B > A * 1
*/
Reference
use CondorcetPHP\Condorcet\Vote;
$election->allowsVoteWeight();
$election->parseCandidates('A;B;C;D');
$vote = new Vote('A>B');
$vote->setWeight(42);
$election->addVote($vote);
$election->countVotes(); // 1
$election->sumVoteWeights(); // 42