src/STV/ElectionRunner.php
protected function allocateVotes(Ballot $ballot, float $multiplier = 1.0, float $divisor = 1.0): Ballot
    {
        $currentWeight = $ballot->getWeight();
        // p. 49(3)
        // "A divided by B" Where A = the value which is calculated
        // by multiplying the surplus of the transferring candidate
        // by the value of the ballot paper when received by that candidate; and
        // B = the total number of votes credited to that candidate
        $weight = $ballot->setWeight(($currentWeight * $multiplier) / $divisor);

        // Get the next candidate on their ballot paper which has not been assigned
        // a vote this could be the first candidate in round 1
        $candidate = $ballot->getNextChoice();

        $this->logger->debug("Allocating vote of weight $weight to $candidate. Previous weight: $currentWeight", array(
            'ballot' => $ballot,
        ));

        // Check there was a next candidate, if only x candidates where listed where
        // x < the number of candidates standing this will occur.
        if ($candidate !== null) {
            // Allocate those surplus votes. p. 49(1) and p. 49(2)
            $this->election->getCandidate($candidate)->addVotes($weight);
            $ballot->incrementLevelUsed();
            $this->logger->debug('Vote added to candidate');

            // If the candidate is no longer running due to being defeated or
            // elected then we re-allocate their vote again.
            if (!in_array($candidate, $this->election->getActiveCandidateIds())) {
                $this->allocateVotes($ballot);
            }
        }

        return $ballot;
    }
protected function allocateVotes(Ballot $ballot, float $multiplier = 1.0, float $divisor = 1.0): Ballot
    {
        $currentWeight = $ballot->getWeight();
        // p. 49(3)
        // "A divided by B" Where A = the value which is calculated
        // by multiplying the surplus of the transferring candidate
        // by the value of the ballot paper when received by that candidate; and
        // B = the total number of votes credited to that candidate
        $weight = $ballot->setWeight(($currentWeight * $multiplier) / $divisor);

        // Get the next candidate on their ballot paper which has not been assigned
        // a vote this could be the first candidate in round 1
        $candidate = $ballot->getNextChoice();

        $this->logger->debug("Allocating vote of weight $weight to $candidate. Previous weight: $currentWeight", array(
            'ballot' => $ballot,
        ));

        // Check there was a next candidate, if only x candidates where listed where
        // x < the number of candidates standing this will occur.
        if ($candidate !== null) {
            // Allocate those surplus votes. p. 49(1) and p. 49(2)
            $this->election->getCandidate($candidate)->addVotes($weight);
            $ballot->incrementLevelUsed();
            $this->logger->debug('Vote added to candidate');

            // If the candidate is no longer running due to being defeated or
            // elected then we re-allocate their vote again.
            if (!in_array($candidate, $this->election->getActiveCandidateIds())) {
                $this->allocateVotes($ballot);
            }
        }

        return $ballot;
    }
protected function allocateVotes ( Ballot $ ballot , float $ multiplier = 1.0 , float $ divisor = 1.0 ) : Ballot { $ currentWeight = $ ballot -> getWeight ( ) ; // p. 49(3) // "A divided by B" Where A = the value which is calculated // by multiplying the surplus of the transferring candidate // by the value of the ballot paper when received by that candidate; and // B = the total number of votes credited to that candidate $ weight = $ ballot -> setWeight ( ( $ currentWeight * $ multiplier ) / $ divisor ) ; // Get the next candidate on their ballot paper which has not been assigned // a vote this could be the first candidate in round 1 $ candidate = $ ballot -> getNextChoice ( ) ; $ this -> logger -> debug ( "Allocating vote of weight $weight to $candidate. Previous weight: $currentWeight" , array ( 'ballot' => $ ballot , ) ) ; // Check there was a next candidate, if only x candidates where listed where // x < the number of candidates standing this will occur. if ( $ candidate !== null ) { // Allocate those surplus votes. p. 49(1) and p. 49(2) $ this -> election -> getCandidate ( $ candidate ) -> addVotes ( $ weight ) ; $ ballot -> incrementLevelUsed ( ) ; $ this -> logger -> debug ( 'Vote added to candidate' ) ; // If the candidate is no longer running due to being defeated or // elected then we re-allocate their vote again. if ( ! in_array ( $ candidate , $ this -> election -> getActiveCandidateIds ( ) ) ) { $ this -> allocateVotes ( $ ballot ) ; } } return $ ballot ; }
Allocate the next votes from a Ballot.
p. 49.

@param Ballot $ballot     The ballot to allocate the votes from
@param float  $multiplier Number to multiply the weight by (surplus)
@param float  $divisor    The divisor of the weight (Total number of
candidate votes)

@return Ballot The same ballot passed in modified
Allocate the next votes from a Ballot . p . 49 .