private IEnumerable <Event> WorldUpdates() { var updateInterval = 1000L; // must be > 1 while (true) { // uncomment if you prefer world updates only for changes //if (_worldChanged) { if (World.PolicyTime > 0) { // Simulate that the policy took a certain time to calculate World.PolicyTime = Math.Max(World.PolicyTime - updateInterval, 0L); // milliseconds } World.Now = Now; World.KPIs.CraneUtilizationMean = CraneUtilization.Mean; World.KPIs.HandoverUtilizationMean = HandoverUtilization.Mean; World.KPIs.UpstreamUtilizationMean = UpstreamUtilization.Mean; World.KPIs.BlockedArrivalTime = (1 - UpstreamUtilization.Mean) * (sim.Now - sim.StartDate).TotalSeconds; if (World.PolicyTime == 0) { var sw = Stopwatch.StartNew(); var schedule = policy?.GetSchedule(World); sw.Stop(); World.PolicyTime = SimulateAsync ? sw.ElapsedMilliseconds : 1L; if (schedule != null) { sim.Process(Crane(schedule, World.PolicyTime)); } } WorldChanged?.Invoke(this, EventArgs.Empty); World.InvalidMoves.Clear(); _worldChanged = false; //} yield return(sim.Timeout(TimeSpan.FromMilliseconds(updateInterval))); } }
public void ChangeWorld(int worldId) { WorldChanged?.Invoke(worldId); }