示例#1
0
        public void CreateCombos(TopTeamsQueue ttQueue)
        {
            int[] loop_Count = new int[TeamSize];
            for (int loop = 0; loop < TeamSize; loop++)
            {
                loop_Count[loop] = loop;
            }

            int  posIncrement = TeamSize - 1;
            bool done         = false;

            while (!done)
            {
                AthleteCombo tempCombo = new AthleteCombo(TeamSize);

                for (int loop = 0; loop < TeamSize; loop++)
                {
                    tempCombo.AddAthlete(loop, names[loop_Count[loop]], times[loop_Count[loop]], costs[loop_Count[loop]]);
                }

                if (tempCombo.TotalCost <= MaximumCost)
                {
                    if (tempCombo.TotalTime <= ttQueue.GetSlowestTime())
                    {
                        ttQueue.Insert(tempCombo);
                    }
                }

                bool doneIncement = false;
                while (!doneIncement)
                {
                    if (loop_Count[posIncrement] < (AthleteCount - TeamSize + posIncrement))
                    {
                        loop_Count[posIncrement]++;
                        for (int loop = posIncrement + 1; loop < TeamSize; loop++)
                        {
                            loop_Count[loop] = loop_Count[loop - 1] + 1;
                        }
                        posIncrement = TeamSize - 1;
                        doneIncement = true;
                    }
                    else
                    {
                        posIncrement--;
                        if (posIncrement < 0)
                        {
                            doneIncement = true;
                            done         = true;
                        }
                    }
                }
            }
        }
示例#2
0
        public void Insert(AthleteCombo combo)
        {
            if (queueFillLevel == 0)
            {
                teams[0] = combo;
                if (queueFillLevel < queueSize)
                {
                    queueFillLevel++;
                }
            }
            else
            {
                int  loop = 0;
                bool done = false;
                while ((loop < queueFillLevel) && (!done))
                {
                    if (teams[loop].TotalTime < combo.TotalTime)
                    {
                        loop++;
                    }
                    else
                    if ((teams[loop].TotalTime == combo.TotalTime) && (teams[loop].TotalCost < combo.TotalCost))
                    {
                        loop++;
                    }
                    else
                    {
                        done = true;
                    }
                }

                int startPos = 0;
                if (queueFillLevel < queueSize)
                {
                    startPos = queueFillLevel;
                }
                else
                {
                    startPos = queueFillLevel - 1;
                }

                // I'm not sure about this for loop.  queueLevel should be changed after the insertion.  I'm adding it here as when revLoop = queueFillLevel (removing the -1) then
                // the code breaks when the queue is full.  So it should be -1.  But If the queue isn't full, then it's not going far enough in the loop (i.e. +1 from current) to shift
                // existing entries down in the queue.
                // For example: 1 3 6 8 9 <- Insert a 4.  This requires queueFillLevel -1 so that 9 becomes 8, 8 becomes 6, and 6 receives the 4 yeilding 1 3 4 6 8
                // However, if the queue is 1 3 6 X X <- Insert a 4. If queueFillLevel (3-1) makes the 6 a 4, but the 6 then vanishes instead of taking the first blank X's spot.
                // Not sure how to reconcile this cleanly yet.
                //
                // Added the variable startPos to make a determination on where to start the loop based on the above two scenarios.  Not sure if this fully works yet though.
                // It *definitely* needs more testing.
                //

                for (int revLoop = startPos; revLoop > loop; revLoop--)
                {
                    teams[revLoop] = teams[revLoop - 1];
                }
                teams[loop] = combo;

                if (queueFillLevel < queueSize)
                {
                    queueFillLevel++;
                }
            }
        }