Ejemplo n.º 1
0
        public override bool Update(DateTime now, IDriverList drivers)
        {
            Random rnd = new Random();

            TimeSpan next  = TimeSpan.FromSeconds(SpawnRate.TotalSeconds * (float)(-Math.Log(rnd.NextDouble())));
            int      added = 0;

            while (next < now - LastUpdate && added < 5)
            {
                LastUpdate += next;

                Driver driver =
                    new Driver()
                {
                    Location    = Location,
                    Name        = "Spawned [" + next.TotalSeconds.ToString() + "]" + added.ToString(),
                    Destination = Destination,
                    LastUpdate  = LastUpdate,
                    Route       = CalculcatedRoutes.Get(Location, Destination, true)
                };

                drivers.Add(driver);

                added++;

                next = TimeSpan.FromSeconds(SpawnRate.TotalSeconds * (float)(-Math.Log(rnd.NextDouble())));
            }

            LastUpdate = now;
            // n.b. Due to the nature of the Poisson distribution exiting and not storing the time of
            // the next event will not change the nature of the distribution.  Knowing that the next
            // event is "not yet" is sufficient.

            return(true);
        }
Ejemplo n.º 2
0
 public virtual bool Update(DateTime now, IDriverList drivers)
 {
     return(false);
 }