Ejemplo n.º 1
0
        private bool matchExistingGroup(QueueList masterQueueList)
        {
            if (potentialGroups.Count <= 0)
            {
                return(false);
            }
            bool        matched      = false;
            List <User> matchedUsers = new List <User>();
            ArrayList   usersInQueue = masterQueueList.UserList;

            for (int i = 0; i < potentialGroups.Count; i++)
            {
                for (int j = 0; j < usersInQueue.Count; j++)
                {
                    Group currentGroup = potentialGroups[i];
                    //check if current group is already at max capacity if so skip it
                    if (currentGroup.memberLimit())
                    {
                        continue;
                    }
                    User   grouplead            = currentGroup.GetGroupLead();
                    User   currentUser          = (User)usersInQueue[j];
                    double firstUserLimitRange  = grouplead.MaxRange;
                    double secondUserLimitRange = currentUser.MaxRange;
                    double distanceAway         = this.GetDistanceFromLatLonInKm(grouplead, currentUser);

                    if (distanceAway <= firstUserLimitRange && distanceAway <= secondUserLimitRange)
                    {
                        ArrayList matches         = GetMatchesAgainstGroup(currentGroup, currentUser);
                        int       matchesRequired = currentGroup.groupFormPatience();
                        Console.WriteLine("matches Required " + matchesRequired);
                        //found someone to join group
                        if (matches.Count >= matchesRequired)
                        {
                            Console.WriteLine("matched user to existing group" + currentUser.ToString());
                            currentGroup.AddUser(currentUser);
                            matchedUsers.Add(currentUser);
                            matched = true;
                        }
                    }
                }
                //remove users that have been matched
                for (int j = 0; j < matchedUsers.Count; j++)
                {
                    User currentUser      = matchedUsers[j];
                    int  currentUserIndex = masterQueueList.UserList.IndexOf(currentUser);
                    if (currentUserIndex >= 0)
                    {
                        masterQueueList.UserList.RemoveAt(currentUserIndex);
                    }
                }
            }

            return(matched);
        }
Ejemplo n.º 2
0
 public void removeGroupedUsers(Group newGroup, QueueList masterQueueList)
 {
     for (int i = 0; i < newGroup.Users.Count; i++)
     {
         int currentIndex = masterQueueList.UserList.IndexOf(newGroup.Users[i]);
         //don't remove anything if it's not there
         if (currentIndex != -1)
         {
             masterQueueList.UserList.RemoveAt(currentIndex);
         }
     }
 }
Ejemplo n.º 3
0
        private bool matchNewGroup(QueueList masterQueueList)
        {
            if (masterQueueList.UserList.Count <= 0)
            {
                return(false);
            }
            Console.WriteLine("making new group");
            int   maxMatchDeincrement = 0;
            Group tempGroup           = new Group();
            User  grouplead           = (User)masterQueueList.UserList[STARTGROUPLEAD];

            tempGroup.AddUser(grouplead);
            masterQueueList.UserList.RemoveAt(STARTGROUPLEAD);
            Boolean createdGroup = false;

            for (int i = 0; i < masterQueueList.UserList.Count; i++)
            {
                User currentUser = (User)masterQueueList.UserList[i];
                Console.WriteLine("current user " + currentUser);
                double firstUserLimitRange  = grouplead.MaxRange;
                double secondUserLimitRange = currentUser.MaxRange;
                double distanceAway         = this.GetDistanceFromLatLonInKm(grouplead, currentUser);

                //if they're within their required distance ranges then check their preferences
                Console.WriteLine(distanceAway);
                if (distanceAway <= firstUserLimitRange && distanceAway <= secondUserLimitRange)
                {
                    Console.WriteLine("Distance match");
                    ArrayList currentMatches = GetMatches(grouplead, currentUser);
                    if (currentMatches.Count >= (MAX_PREF_MATCH - maxMatchDeincrement))
                    {
                        Console.WriteLine("Preference match & distance match");
                        tempGroup.AddUser(currentUser);
                        tempGroup.MatchedPreferences = currentMatches;
                        createdGroup = true;
                    }
                }
            }
            if (createdGroup)
            {
                Console.WriteLine("here22");
                potentialGroups.Add(tempGroup);
                removeGroupedUsers(tempGroup, masterQueueList);
            }
            else
            {
                Console.WriteLine("here");
                masterQueueList.UserList.Add(grouplead);
            }
            return(createdGroup);
        }
Ejemplo n.º 4
0
        public void MatchQueue(QueueList masterQueueList)
        {
            //check precondition
            if (masterQueueList.UserList == null && masterQueueList.UserList.Count < 0)
            {
                Console.WriteLine("no users in queue list");
                return;
            }

            bool matched = matchExistingGroup(masterQueueList);

            //try to match a new group if there's no group that works
            if (matched == false)
            {
                matchNewGroup(masterQueueList);
            }
        }