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); }
public Tram(TramStop start) { Previous = start; Destination = start; }
//Maakt route aan private void InitializeRoute() { var PRDeUithof = new TramStop { Name = "P+R De Uithof", DistanceToNextStop = 600, AvgTimeToNextDestination = 110, Route = 1 }; var WKZ = new TramStop { Name = "WKZ", DistanceToNextStop = 600, AvgTimeToNextDestination = 78, Route = 1 }; var UMC = new TramStop { Name = "UMC", DistanceToNextStop = 400, AvgTimeToNextDestination = 82, Route = 1 }; var Heidelberglaan = new TramStop { Name = "Heidelberglaan", DistanceToNextStop = 400, AvgTimeToNextDestination = 60, Route = 1 }; var Padualaan = new TramStop { Name = "Padualaan", DistanceToNextStop = 800, AvgTimeToNextDestination = 100, Route = 1 }; var KrommeRijn = new TramStop { Name = "Kromme Rijn", DistanceToNextStop = 600, AvgTimeToNextDestination = 59, Route = 1 }; var GalgenWaard = new TramStop { Name = "Galgenwaard", DistanceToNextStop = 3100, AvgTimeToNextDestination = 243, Route = 1 }; var VaartscheRijn = new TramStop { Name = "Vaartsche Rijn", DistanceToNextStop = 1400, AvgTimeToNextDestination = 135, Route = 1 }; var CentraalStation = new TramStop { Name = "Centraal Station", IsEndPoint = true, Route = 1 }; var CentraalStation2 = new TramStop { Name = "Centraal Station", DistanceToNextStop = 1400, AvgTimeToNextDestination = 134, Route = 2 }; var VaartscheRijn2 = new TramStop { Name = "Vaartsche Rijn", DistanceToNextStop = 3100, AvgTimeToNextDestination = 243, Route = 2 }; var GalgenWaard2 = new TramStop { Name = "Galgenwaard", DistanceToNextStop = 600, AvgTimeToNextDestination = 59, Route = 2 }; var KrommeRijn2 = new TramStop { Name = "Kromme Rijn", DistanceToNextStop = 800, AvgTimeToNextDestination = 101, Route = 2 }; var Padualaan2 = new TramStop { Name = "Padualaan", DistanceToNextStop = 400, AvgTimeToNextDestination = 60, Route = 2 }; var Heidelberglaan2 = new TramStop { Name = "Heidelberglaan", DistanceToNextStop = 400, AvgTimeToNextDestination = 86, Route = 2 }; var UMC2 = new TramStop { Name = "UMC", DistanceToNextStop = 600, AvgTimeToNextDestination = 78, Route = 2 }; var WKZ2 = new TramStop { Name = "WKZ", DistanceToNextStop = 600, AvgTimeToNextDestination = 113, Route = 2 }; var PRDeUithof2 = new TramStop { Name = "P+R De Uithof", IsEndPoint = true, Route = 2 }; PRDeUithof.NextStop = WKZ; WKZ.NextStop = UMC; UMC.NextStop = Heidelberglaan; Heidelberglaan.NextStop = Padualaan; Padualaan.NextStop = KrommeRijn; KrommeRijn.NextStop = GalgenWaard; GalgenWaard.NextStop = VaartscheRijn; VaartscheRijn.NextStop = CentraalStation; CentraalStation2.NextStop = VaartscheRijn2; VaartscheRijn2.NextStop = GalgenWaard2; GalgenWaard2.NextStop = KrommeRijn2; KrommeRijn2.NextStop = Padualaan2; Padualaan2.NextStop = Heidelberglaan2; Heidelberglaan2.NextStop = UMC2; UMC2.NextStop = WKZ2; WKZ2.NextStop = PRDeUithof2; _route1 = PRDeUithof; _route1End = CentraalStation; _route2 = CentraalStation2; _route2End = PRDeUithof2; var stop = PRDeUithof; while (!stop.IsEndPoint) { _stops.Add(stop); ScheduleNewArrivalEvent(stop); stop = stop.NextStop; } stop = CentraalStation2; while (!stop.IsEndPoint) { _stops.Add(stop); ScheduleNewArrivalEvent(stop); stop = stop.NextStop; } }
public TramChangeTrackEvent(int time, TramStop newRoute) : base(Name, time) { NewRoute = newRoute; }