Пример #1
0
        private static Pairing GetLessGreedyPairing(List <Pairing> validPairs)
        {
            if (validPairs.Count != 0)
            {
                List <Pairing> lessGreedyPairings = new List <Pairing>();
                int            currentHunger      = validPairs.Count;
                foreach (Pairing p in validPairs)
                {
                    int pairHunger = GetHunger(p, ref validPairs);
                    if (pairHunger < currentHunger)
                    {
                        lessGreedyPairings = new List <Pairing>();
                        currentHunger      = pairHunger;
                    }
                    if (pairHunger == currentHunger)
                    {
                        lessGreedyPairings.Add(p);
                    }
                }

                Pairing toReturn = lessGreedyPairings[0];
                foreach (Pairing p in lessGreedyPairings)
                {
                    if (p.Priority > toReturn.Priority)
                    {
                        toReturn = p;
                    }
                }
                return(toReturn);
            }
            else
            {
                return(new Pairing());
            }
        }
Пример #2
0
 private static void RemoveFromPairings(Pairing toRemove, ref List <Pairing> pairings)
 {
     for (int i = 0; i < pairings.Count; i++)
     {
         if (toRemove.IDPeriod == pairings[i].IDPeriod || toRemove.IDStudent == pairings[i].IDStudent)
         {
             pairings.RemoveAt(i);
             i--;
         }
     }
 }
Пример #3
0
        private static int GetHunger(Pairing pair, ref List <Pairing> pairings)
        {
            int hunger = 0;

            foreach (Pairing p in pairings)
            {
                if (p.IDStudent == pair.IDStudent || p.IDPeriod == pair.IDPeriod)
                {
                    hunger++;
                }
            }
            return(hunger);
        }
Пример #4
0
        public static List <Pairing> Match(List <Period> periods, List <Disponibility> disponibilities)
        {
            List <Pairing> assignedPairs = new List <Pairing>();
            List <Pairing> validPairs    = GetValidPairs(periods, disponibilities);

            while (validPairs.Count != 0)
            {
                Pairing currentPair = GetFirstSinglePossibilityPairing(validPairs);
                while (currentPair.IDStudent != null)
                {
                    assignedPairs.Add(currentPair);
                    RemoveFromPairings(currentPair, ref validPairs);
                    currentPair = GetFirstSinglePossibilityPairing(validPairs);
                }

                currentPair = GetLessGreedyPairing(validPairs);
                if (currentPair.IDStudent != null)
                {
                    assignedPairs.Add(currentPair);
                    RemoveFromPairings(currentPair, ref validPairs);
                }
            }
            return(assignedPairs);
        }