/// <summary> /// Create pairs from the set of users /// </summary> /// <param name="channelAccounts">users to make pairs</param> /// <returns>a list of pairs</returns> public MatchResult CreateMatches(List <ChannelAccount> channelAccounts) { var people = channelAccounts.Select(account => new Person <ChannelAccount>(account)).ToList(); var numRetries = this.numRetryOnPreviouslyMatchedPair; MatchResult result; do { RandomAlgorithm.Shuffle <Person <ChannelAccount> >(this.random, people); result = this.CreateMatches(people); }while (result.HasAnyPreviouslyMatchedPair && (numRetries-- > 0)); return(result); }
/// <summary> /// Create pairs from the set of users. /// </summary> /// <param name="users">users to make pairs</param> /// <returns>a list of pairs</returns> public MatchResult CreateMatches(List <ChannelAccount> users) { RandomAlgorithm.Shuffle(this.random, users); var pairs = new List <MatchResult.MatchPair>(); int i = 0; for (; i < users.Count - 1; i += 2) { // TODO: Get real isPreviouslyMatched by going to the DB. // Not bothering with that right now because this is only used for small sets. pairs.Add(new MatchResult.MatchPair(users[i], users[i + 1], isPreviouslyMatched: false)); } var oddPerson = i == users.Count ? null : users[i]; return(new MatchResult(pairs, oddPerson)); }