Beispiel #1
0
        private void ScheduleNewArrivalEvent(TramStop stop)
        {
            var rates       = _passengerRates.ToArray();
            var arrivalRate = rates.Where(r => r.Route == stop.Route && r.Name == stop.Name && r.TimeEnd == _time + 900 - _time % 900).First();

            if (Math.Abs(arrivalRate.RateIn) < 0.0001)
            {
                stop.GeneratingEvents = false;
                return;
            }
            else
            {
                stop.GeneratingEvents = true;
            }
            var time = _time + RandomDistribution.GenerateNextPoisson(arrivalRate.RateIn);

            if (stop.Route == 2)
            {
                rates = rates.Reverse().ToArray();
            }
            var routes = rates.Where(r => r.Route == stop.Route && r.TimeEnd == _time + 900 - _time % 900)
                         .SkipWhile(r => r.Name != stop.Name).Skip(1).ToArray();
            var destination = routes[RandomDistribution.GenerateNextEmpirical(routes.Select(r => r.RateOut).ToArray())].Name;

            ScheduleEvent(new PassengerArrivalEvent(time, destination), stop);
        }
Beispiel #2
0
        public int GetTimeToNextDestination()
        {
            // Use a Lognormal distribution to simulate driving times as per the fit on the Nieuwegeinlijn.
            // The mean is set to the average driving time and the standard deviation is found to be 3.01% of the mean on average.
            // The mean and standard deviation are logarithmic.
            int time = RandomDistribution.GenerateNextLognormal((float)Math.Log(AvgTimeToNextDestination), (float)Math.Log(AvgTimeToNextDestination) * 0.0301f);

            return(Math.Abs(time));
        }