pub fn distribute_surplus_all_with_same_transfer_value(&mut self,candidate_to_distribute:CandidateIndex) -> PortionOfReasonBeingDoneThisCount {
        let votes : Rules::Tally = self.tally(candidate_to_distribute);
        let surplus: Rules::Tally  = votes.clone()-self.quota.clone();
        self.tallys[candidate_to_distribute.0]=self.quota.clone();
        let (ballots,provenance) =
            if Rules::use_last_parcel_for_surplus_distribution() {self.papers[candidate_to_distribute.0].extract_last_parcel()}
            else {
                let (_tally,ballots,provenance) = self.papers[candidate_to_distribute.0].extract_all_ballots_ignoring_transfer_value();
                (ballots,provenance)
            };
        let ballots_considered : BallotPaperCount = ballots.num_ballots;
        let distributed = DistributedVotes::distribute(&ballots.votes,&self.continuing_candidates,self.num_candidates);
        let continuing_ballots = ballots_considered-distributed.exhausted;
        let tv_denom = if Rules::transfer_value_method().denom_is_just_continuing() {continuing_ballots} else {ballots.num_ballots};
        let mut transfer_value : TransferValue = if tv_denom.is_zero() { TransferValue::one() } else {Rules::make_transfer_value(surplus.clone(),tv_denom)};
        let mut original_worth : Rules::Tally = surplus.clone();
        if Rules::transfer_value_method().limit_to_incoming_transfer_value() {
            let old_tv = provenance.transfer_value.clone().expect("If you are going to limit to an incoming transfer value, there must be a unique one.");
            let old_tv = Rules::munge_transfer_value_when_used_as_limit(old_tv);
            if old_tv<transfer_value {
                if !Rules::count_set_aside_due_to_transfer_value_limit_as_rounding() {
                    // work out how many votes lost this way.
                    let set_aside : Rules::Tally = surplus.clone()-Rules::use_transfer_value(&old_tv,tv_denom);
                    // println!("Set aside {} of {} votes to deal with rule limiting transfer value to incoming",set_aside,original_worth);
                    original_worth-=set_aside.clone();
                    self.add_set_aside(set_aside);
                }
                transfer_value=old_tv;
            }
        }
        // println!("Parcelling out {} votes with TV {} over {} ballots",original_worth,transfer_value,tv_denom);
        self.parcel_out_votes_with_given_transfer_value(transfer_value.clone(),distributed,Some(self.current_count),original_worth,!Rules::transfer_value_method().denom_is_just_continuing(),false,None);
        self.in_this_count.created_transfer_value=Some(TransferValueCreation{
            surplus,
            votes,
            excluded_exhausted_tally: None,
            original_transfer_value: provenance.transfer_value.clone(),
            multiplied_transfer_value: None,
            ballots_considered,
            continuing_ballots,
            transfer_value,
            source: Rules::transfer_value_method(),
        });
        provenance
    }
/// Transfer votes using a single transfer value. Used for Federal and Victoria and ACT
///
/// Federal Legislation:
/// > (9) Unless all the vacancies have been filled, the number (if any) of
/// > votes in excess of the quota (in this section referred to as surplus
/// > votes) of each elected candidate shall be transferred to the
/// > continuing candidates as follows:
/// > (a) the number of surplus votes of the elected candidate shall be
/// > divided by the number of first preference votes received by
/// > the candidate and the resulting fraction shall be the transfer
/// > value;
/// > (b) the total number of ballot papers of the elected candidate that
/// > express the first preference vote for that candidate and the
/// > next available preference for a particular continuing
/// > candidate shall be multiplied by the transfer value, the
/// > number so obtained (disregarding any fraction) shall be
/// > added to the number of first preference votes of the
/// > continuing candidate and all those ballot papers shall be
/// > transferred to the continuing candidate;
Transfer votes using a single transfer value.
Transfer votes using a single transfer value .
pub fn distribute_surplus_all_with_same_transfer_value(&mut self,candidate_to_distribute:CandidateIndex) -> PortionOfReasonBeingDoneThisCount {
        let votes : Rules::Tally = self.tally(candidate_to_distribute);
        let surplus: Rules::Tally  = votes.clone()-self.quota.clone();
        self.tallys[candidate_to_distribute.0]=self.quota.clone();
        let (ballots,provenance) =
            if Rules::use_last_parcel_for_surplus_distribution() {self.papers[candidate_to_distribute.0].extract_last_parcel()}
            else {
                let (_tally,ballots,provenance) = self.papers[candidate_to_distribute.0].extract_all_ballots_ignoring_transfer_value();
                (ballots,provenance)
            };
        let ballots_considered : BallotPaperCount = ballots.num_ballots;
        let distributed = DistributedVotes::distribute(&ballots.votes,&self.continuing_candidates,self.num_candidates);
        let continuing_ballots = ballots_considered-distributed.exhausted;
        let tv_denom = if Rules::transfer_value_method().denom_is_just_continuing() {continuing_ballots} else {ballots.num_ballots};
        let mut transfer_value : TransferValue = if tv_denom.is_zero() { TransferValue::one() } else {Rules::make_transfer_value(surplus.clone(),tv_denom)};
        let mut original_worth : Rules::Tally = surplus.clone();
        if Rules::transfer_value_method().limit_to_incoming_transfer_value() {
            let old_tv = provenance.transfer_value.clone().expect("If you are going to limit to an incoming transfer value, there must be a unique one.");
            let old_tv = Rules::munge_transfer_value_when_used_as_limit(old_tv);
            if old_tv<transfer_value {
                if !Rules::count_set_aside_due_to_transfer_value_limit_as_rounding() {
                    // work out how many votes lost this way.
                    let set_aside : Rules::Tally = surplus.clone()-Rules::use_transfer_value(&old_tv,tv_denom);
                    // println!("Set aside {} of {} votes to deal with rule limiting transfer value to incoming",set_aside,original_worth);
                    original_worth-=set_aside.clone();
                    self.add_set_aside(set_aside);
                }
                transfer_value=old_tv;
            }
        }
        // println!("Parcelling out {} votes with TV {} over {} ballots",original_worth,transfer_value,tv_denom);
        self.parcel_out_votes_with_given_transfer_value(transfer_value.clone(),distributed,Some(self.current_count),original_worth,!Rules::transfer_value_method().denom_is_just_continuing(),false,None);
        self.in_this_count.created_transfer_value=Some(TransferValueCreation{
            surplus,
            votes,
            excluded_exhausted_tally: None,
            original_transfer_value: provenance.transfer_value.clone(),
            multiplied_transfer_value: None,
            ballots_considered,
            continuing_ballots,
            transfer_value,
            source: Rules::transfer_value_method(),
        });
        provenance
    }
pub fn distribute_surplus_all_with_same_transfer_value ( & mut self , candidate_to_distribute : CandidateIndex ) -> PortionOfReasonBeingDoneThisCount { let votes : Rules :: Tally = self . tally ( candidate_to_distribute ) ; let surplus : Rules :: Tally = votes . clone ( ) - self . quota . clone ( ) ; self . tallys [ candidate_to_distribute . 0 ] = self . quota . clone ( ) ; let ( ballots , provenance ) = if Rules :: use_last_parcel_for_surplus_distribution ( ) { self . papers [ candidate_to_distribute . 0 ] . extract_last_parcel ( ) } else { let ( _tally , ballots , provenance ) = self . papers [ candidate_to_distribute . 0 ] . extract_all_ballots_ignoring_transfer_value ( ) ; ( ballots , provenance ) } ; let ballots_considered : BallotPaperCount = ballots . num_ballots ; let distributed = DistributedVotes :: distribute ( & ballots . votes , & self . continuing_candidates , self . num_candidates ) ; let continuing_ballots = ballots_considered - distributed . exhausted ; let tv_denom = if Rules :: transfer_value_method ( ) . denom_is_just_continuing ( ) { continuing_ballots } else { ballots . num_ballots } ; let mut transfer_value : TransferValue = if tv_denom . is_zero ( ) { TransferValue :: one ( ) } else { Rules :: make_transfer_value ( surplus . clone ( ) , tv_denom ) } ; let mut original_worth : Rules :: Tally = surplus . clone ( ) ; if Rules :: transfer_value_method ( ) . limit_to_incoming_transfer_value ( ) { let old_tv = provenance . transfer_value . clone ( ) . expect ( " " ) ; let old_tv = Rules :: munge_transfer_value_when_used_as_limit ( old_tv ) ; if old_tv < transfer_value { if ! Rules :: count_set_aside_due_to_transfer_value_limit_as_rounding ( ) { // work out how many votes lost this way. let set_aside : Rules :: Tally = surplus . clone ( ) - Rules :: use_transfer_value ( & old_tv , tv_denom ) ; // println!("Set aside {} of {} votes to deal with rule limiting transfer value to incoming",set_aside,original_worth); original_worth -= set_aside . clone ( ) ; self . add_set_aside ( set_aside ) ; } transfer_value = old_tv ; } } // println!("Parcelling out {} votes with TV {} over {} ballots",original_worth,transfer_value,tv_denom); self . parcel_out_votes_with_given_transfer_value ( transfer_value . clone ( ) , distributed , Some ( self . current_count ) , original_worth , ! Rules :: transfer_value_method ( ) . denom_is_just_continuing ( ) , false , None ) ; self . in_this_count . created_transfer_value = Some ( TransferValueCreation { surplus , votes , excluded_exhausted_tally : None , original_transfer_value : provenance . transfer_value . clone ( ) , multiplied_transfer_value : None , ballots_considered , continuing_ballots , transfer_value , source : Rules :: transfer_value_method ( ) , } ) ; provenance }
Transfer votes using a single transfer value.
Transfer votes using a single transfer value .
&mut self
candidate_to_distribute
CandidateIndex
&mut self
candidate_to_distribute
CandidateIndex