예제 #1
0
        public LinkedList <Round> ArangeHeats()
        {
            LinkedList <Round> rounds = new LinkedList <Round>();

            //The first round is randmoly assigned
            Round round1 = randomAssignRound(1, _drivers);

            rounds.AddLast(round1);
            EvaluateWhichDriversMet(round1);
            //Sort the drivers list descending by the diffrence to the expected avg starting position
            IOrderedEnumerable <Driver> drivers = _drivers.OrderByDescending(o => o.diffAvgPositionToExpected(_expectedAvgStartingPosition));

            //For the other rounds assigne based on the statistics of diff to avg starting position ans drivers met
            for (int i = 2; i <= _numRounds; i++)
            {
                Round round = new Round(i, _numHeats, _heatSize);

                foreach (Driver driver in drivers)
                {
                    Heat heat = findHeatForDriver(round, driver);
                    int  recommendedStartingPosition = nextStartingPosition(driver);
                    int  startingPosition            = findFreeStartingPosition(heat, recommendedStartingPosition);
                    heat.addDriverToGrid(startingPosition, driver);
                }
                rounds.AddLast(round);
                EvaluateWhichDriversMet(round);
                //Sort the drivers list descending by the diffrence to the expected avg starting position
                drivers = drivers.OrderByDescending(o => o.diffAvgPositionToExpected(_expectedAvgStartingPosition));
            }

            return(rounds);
        }
예제 #2
0
        /// <summary> Randomly assigne the drivers to heats and starting position
        /// </summary>
        private Round randomAssignRound(int roundNum, List <Driver> driversOrg)
        {
            List <Driver> drivers = new List <Driver>(driversOrg);

            Round round = new Round(roundNum, _numHeats, _heatSize);

            Random rnd = new Random();

            while (drivers.Count != 0)
            {
                Driver[] driverArray = drivers.ToArray();

                //Pick random heat
                int rndHeat = rnd.Next(0, _numHeats);
                //Check if heat as free grid positions
                while (round.Heats[rndHeat].FreeGridPositions <= 0)
                {
                    rndHeat = rnd.Next(0, _numHeats);
                }
                //Get the heat
                Heat heat = round.Heats[rndHeat];

                //Pick random driver
                int rndDriver = rnd.Next(0, driverArray.Length);

                //Pick random starting position and check if free
                int rndPostion = rnd.Next(1, heat.StartingGrid.Length + 1);
                while (!heat.StartingGrid[rndPostion - 1].IsFree())
                {
                    rndPostion = rnd.Next(1, heat.StartingGrid.Length + 1);
                }

                //Get driver and remove him
                Driver driver = driverArray[rndDriver];
                drivers.Remove(driver);

                //Place the driver on the grid
                heat.addDriverToGrid(rndPostion, driver);
            }

            return(round);
        }