コード例 #1
0
        /// <summary>
        /// Gets random car
        /// </summary>
        /// <param name="random">Randomizer used to generate random values</param>
        /// <param name="speeding">Is the car driving faster than the limit?</param>
        /// <returns></returns>
        public static SimulatedCar Randomize(Random random, TrafficSegmentSituation segmentSituation, string licensePlateFormat = "1-###-000")
        {
            var car = new SimulatedCar
            {
                LicensePlate = random.GetString(licensePlateFormat),
                Color        = Colors[random.Next(Colors.Count)],
                Make         = Makes[random.Next(Makes.Count)],
                Country      = Countries[random.NextTriangularValue(0, Countries.Count - 1, Convert.ToInt32(Countries.Count / 2))], // weighted randomization (to get more belgian cars)
                Speeding     = random.GetBooleanWithProbability(segmentSituation.SpeedingPercentage),
            };

            car.ExpectedSpeed = car.Speeding
                ? random.NextTriangularValue(segmentSituation.SpeedLimit, segmentSituation.MaxSpeed, segmentSituation.SpeedLimit + 15) // Generate speeding cars with weight of speeding around 15 more than allowed
                : random.NextTriangularValue(segmentSituation.MinSpeed, segmentSituation.SpeedLimit, segmentSituation.AverageSpeed);   // Generate non speeding cars, with weight closest to maxAllowed
            return(car);
        }
コード例 #2
0
 public static int CalculateLane(TrafficSegmentConfiguration segmentConfiguration, TrafficSegmentSituation segmentSituation, SimulatedCar car)
 {
     if (segmentConfiguration.NumberOfLanes > 2)
     {
         // do complexity
         if (car.Speeding && segmentSituation.IsRushHour(SimulatedClock.Time, out var rushHour))
         {
             // Only take the two most left lanes
             return(new Random().Next(1, 3));
         }
     }
     return(new Random().Next(1, segmentConfiguration.NumberOfLanes + 1));
 }