/// <summary> /// Fills the pairwise preferences. /// This goes through each voter's ranking options and updates an array indicating /// which options are preferred over which other options. Each higher-ranked /// option gains one point in 'beating' a lower-ranked option. /// </summary> /// <param name="voterRankings">The voter rankings.</param> /// <param name="listOfChoices">The list of choices.</param> /// <returns>Returns a filled-in preferences array.</returns> private int[,] GetPairwisePreferences(IEnumerable<VoterRankings> voterRankings, List<string> listOfChoices) { int[,] pairwisePreferences = new int[listOfChoices.Count, listOfChoices.Count]; var choiceIndexes = GroupRankVotes.GetChoicesIndexes(listOfChoices); foreach (var voter in voterRankings) { var rankedChoices = voter.RankedVotes.Select(v => v.Vote); var unrankedChoices = listOfChoices.Except(rankedChoices); foreach (var choice in voter.RankedVotes) { // Each choice matching or beating the ranks of other ranked choices is marked. foreach (var otherChoice in voter.RankedVotes) { if ((choice.Vote != otherChoice.Vote) && (choice.Rank <= otherChoice.Rank)) { pairwisePreferences[choiceIndexes[choice.Vote], choiceIndexes[otherChoice.Vote]]++; } } // Each choice is ranked higher than all unranked choices foreach (var nonChoice in unrankedChoices) { pairwisePreferences[choiceIndexes[choice.Vote], choiceIndexes[nonChoice]]++; } } } return pairwisePreferences; }
/// <summary> /// Fills the pairwise preferences. /// This goes through each voter's ranking options and updates an array indicating /// which options are preferred over which other options. /// Each higher-ranked option gains the difference in ranking in 'beating' a lower-ranked option. /// </summary> /// <param name="voterRankings">The voter rankings.</param> /// <param name="listOfChoices">The list of choices.</param> /// <returns>Returns a filled-in preferences array.</returns> private static DistanceData GetPairwiseData(IEnumerable <VoterRankings> voterRankings, List <string> listOfChoices) { DistanceData data = new DistanceData { Paths = new int[listOfChoices.Count, listOfChoices.Count] }; var choiceIndexes = GroupRankVotes.GetChoicesIndexes(listOfChoices); foreach (var voter in voterRankings) { var rankedChoices = voter.RankedVotes.Select(v => v.Vote); var unrankedChoices = listOfChoices.Except(rankedChoices); foreach (var choice in voter.RankedVotes) { foreach (var otherChoice in voter.RankedVotes) { // Each ranked vote that has a higher rank (lower number) than each // alternative has the distance between the choices added to the // corresponding table entry. if (choice.Vote != otherChoice.Vote && choice.Rank < otherChoice.Rank) { data.Paths[choiceIndexes[choice.Vote], choiceIndexes[otherChoice.Vote]] += otherChoice.Rank - choice.Rank; } } // All unranked options are considered to be at distance 0 from *all* ranked options. // There is no relative preference, nor does it place unranked options 'beneath' // ranked options, such that higher ranked options have greater distance from them. // Unranked options are agnostic choices. //foreach (var nonChoice in unrankedChoices) //{ // //data.Paths[choiceIndexes[choice.Vote], choiceIndexes[nonChoice]]++; //} } // All unranked options are at distance 0 from each other, and thus have no effect // on the distance table. } return(data); }