public override AbstractTiebreaker CreateTiebreaker(TabulationMediator mediator) { AbstractTiebreaker fallbackTiebreaker = FallbackTiebreakerFactory?.CreateTiebreaker(mediator); AbstractTiebreaker tiebreaker = InstantiateTiebreaker(fallbackTiebreaker); tiebreaker.Mediator = mediator; return(tiebreaker); }
/// <summary> /// Initialize the tabulation state from a set of bandidates, withdrawn candidates, and a number of seats. /// </summary> /// <param name="ballots">The ballots to tabulate.</param> /// <param name="withdrawn">Candidates excluded from tabulation.</param> /// <param name="seats">The number of seats to elect.</param> protected virtual void InitializeTabulation(BallotSet ballots, IEnumerable <Candidate> withdrawn, int seats) { this.seats = seats; this.ballots = ballots; candidateStates.Clear(); if (!(withdrawn is null)) { InitializeCandidateStates(withdrawn, CandidateState.States.withdrawn); } // Initialize hopefuls InitializeCandidateStates(ballots.SelectMany(x => x.Votes.Select(y => y.Candidate)).Distinct().Except(candidateStates.Keys)); tiebreaker = tiebreakerFactory.CreateTiebreaker(mediator); }
public BallotSetFixture() { string ballotSet = "c|Alex|0\n" + "c|Chris|1\n" + "c|Sam|2\n" + "b|20|0 1 2\n" + "b|15|2 1\n" + "b|8|1 2 0\n" + "b|5|1 0"; // Decode the above into a thing. (Candidates, Ballots) = DecodeBallots(ballotSet); AbstractTiebreaker firstDifference = new FirstDifferenceTiebreaker(); tiebreaker = firstDifference; }
protected virtual AbstractTiebreaker InstantiateTiebreaker(AbstractTiebreaker fallbackTiebreaker) => Activator.CreateInstance(typeof(T), new object[] { fallbackTiebreaker }) as T;