public static void RunReference(SimulationBase sim) { for (int i = 0; i < RunStepCount; i++) { sim.DoStepReference(); } }
private void OnSaveButtonClick(object sender, EventArgs e) { if (simulation == null) { return; } using (SaveFileDialog dialog = new SaveFileDialog()) { const string ext = ".trs"; dialog.Filter = "Simulation State File (*" + ext + ")|*" + ext; dialog.FilterIndex = 0; dialog.RestoreDirectory = true; dialog.Title = "Save state as…"; dialog.FileName = "Untitled" + ext; if (dialog.ShowDialog(this) != DialogResult.OK) { return; } string filename = dialog.FileName; using (FileStream s = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None)) { SimulationBase.SaveToStream(s, simulation); } } }
/// <summary> /// Loads, saves and checks if it's equal /// </summary> /// <param name="stateName">State name</param> public static void LoadSaveAndAssert(string stateName) { MemoryStream streamExpected = new MemoryStream(); MemoryStream streamCurrent = new MemoryStream(); using (Stream streamTemp = OpenStateFromResources(stateName)) { streamTemp.CopyTo(streamExpected); } streamExpected.Position = 0; streamCurrent.Position = 0; SimulationBase sim = SimulationBase.LoadFromStream(streamExpected); SimulationBase.SaveToStream(streamCurrent, sim); streamExpected.Position = 0; streamCurrent.Position = 0; SHA1Managed hash = new SHA1Managed(); byte[] hashExpected = hash.ComputeHash(streamExpected); byte[] hashCurrent = hash.ComputeHash(streamCurrent); AssertArraysEqual(hashExpected, hashCurrent); }
/// <summary> /// Execute simulation with reference implementation to checkpoint and compare with expected state /// </summary> /// <param name="sim">Simulation</param> /// <param name="simType">Simulation type</param> /// <param name="stateName">State name</param> public static void DoStepsReferenceToCheckpointAndAssert(SimulationBase sim, SimulationType simType, string stateName) { for (int i = 0; i < StepCountToCheckpoint; i++) { sim.DoStepReference(); } AssertSimulationWithState(sim, simType, stateName); }
/// <summary> /// Executes simulation with OpenCL implementation in batch to checkpoint and compares with expected state /// </summary> /// <param name="sim">Simulation</param> /// <param name="simType">Simulation type</param> /// <param name="stateName">State name</param> public static void DoBatchOpenCLToCheckpointAndAssert(SimulationBase sim, SimulationType simType, string stateName) { OpenCLDispatcher dispatcher; OpenCLDevice device; GetOpenCLDispatcherAndDevice(out dispatcher, out device); sim.DoBatchOpenCL(dispatcher, device, StepCountToCheckpoint); AssertSimulationWithState(sim, simType, stateName); }
/// <summary> /// Executes simulation with OpenCL implementation to checkpoint and compares with expected state /// </summary> /// <param name="sim">Simulation</param> /// <param name="simType">Simulation type</param> /// <param name="stateName">State name</param> public static void DoStepsOpenCLToCheckpointAndAssert(SimulationBase sim, SimulationType simType, string stateName) { OpenCLDispatcher dispatcher; OpenCLDevice device; GetOpenCLDispatcherAndDevice(out dispatcher, out device); for (int i = 0; i < StepCountToCheckpoint; i++) { sim.DoStepOpenCL(dispatcher, device); } AssertSimulationWithState(sim, simType, stateName); }
/// <summary> /// Binds simulation as active /// </summary> /// <param name="sim"></param> private void BindSimulation(SimulationBase sim) { if (sim == null) { this.simulation = null; return; } this.simulation = sim; trafficView.Simulation = sim; runTimer.Enabled = false; }
protected override void OnClosed(EventArgs e) { base.OnClosed(e); if (runTimer != null) { runTimer.Dispose(); runTimer = null; } if (simulation != null) { simulation.Dispose(); simulation = null; } }
/// <summary> /// Checks if current simulation state is the same as expected state /// </summary> /// <param name="simCurrent">Simulation</param> /// <param name="simType">Simulation type</param> /// <param name="stateName">State name</param> public static void AssertSimulationWithState(SimulationBase simCurrent, SimulationType simType, string stateName) { SimulationBase simExpected = SimulationBase.LoadFromStream(OpenStateFromResources(stateName), RandomSeed); Assert.AreEqual(simType, simExpected.CurrentType); Assert.AreEqual(simExpected.CurrentType, simCurrent.CurrentType); Assert.IsTrue(simExpected.IsReady); Assert.AreEqual(simExpected.IsReady, simCurrent.IsReady); Assert.AreEqual(simExpected.CurrentStep, simCurrent.CurrentStep); Assert.AreEqual(simExpected.GetType(), simCurrent.GetType()); switch (simType) { case SimulationType.CellBased: { CellBasedSim simExpected2 = simExpected as CellBasedSim; Assert.IsNotNull(simExpected2); CellBasedSim simCurrent2 = simCurrent as CellBasedSim; Assert.IsNotNull(simCurrent2); Assert.IsTrue(simCurrent2.CheckIntegrity()); break; } case SimulationType.CarFollowing: { CarFollowingSim simExpected2 = simExpected as CarFollowingSim; Assert.IsNotNull(simExpected2); CarFollowingSim simCurrent2 = simCurrent as CarFollowingSim; Assert.IsNotNull(simCurrent2); Assert.AreEqual(simExpected2.Current.CarsPerCell, simCurrent2.Current.CarsPerCell); Assert.IsTrue(simCurrent2.CheckIntegrity()); break; } default: Assert.Fail("Unknown simulation type"); break; } }
private void OnOpenButtonClick(object sender, EventArgs e) { using (OpenFileDialog dialog = new OpenFileDialog()) { const string ext = ".trs"; dialog.CheckFileExists = true; dialog.Filter = "Simulation State File (*" + ext + ")|*" + ext; dialog.FilterIndex = 0; dialog.RestoreDirectory = true; dialog.Title = "Load state…"; if (dialog.ShowDialog(this) != DialogResult.OK) { return; } string filename = dialog.FileName; using (FileStream s = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { BindSimulation(SimulationBase.LoadFromStream(s)); RefreshToolbar(false); } } }
/// <summary>Register service method with a service binder with or without implementation. Useful when customizing the service binding logic. /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary> /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static void BindService(grpc::ServiceBinderBase serviceBinder, SimulationBase serviceImpl) { serviceBinder.AddMethod(__Method_DoStep, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::GeminiOSPInterface.StepRequest, global::GeminiOSPInterface.StepResponse>(serviceImpl.DoStep)); serviceBinder.AddMethod(__Method_SetStartTime, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::GeminiOSPInterface.SetStartTimeRequest, global::GeminiOSPInterface.SetStartTimeResponse>(serviceImpl.SetStartTime)); }
/// <summary>Creates service definition that can be registered with a server</summary> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static grpc::ServerServiceDefinition BindService(SimulationBase serviceImpl) { return(grpc::ServerServiceDefinition.CreateBuilder() .AddMethod(__Method_DoStep, serviceImpl.DoStep) .AddMethod(__Method_SetStartTime, serviceImpl.SetStartTime).Build()); }
/// <summary>Register service method with a service binder with or without implementation. Useful when customizing the service binding logic. /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary> /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static void BindService(grpc::ServiceBinderBase serviceBinder, SimulationBase serviceImpl) { serviceBinder.AddMethod(__Method_DoStep, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::Simulation.StepRequest, global::Simulation.StepResponse>(serviceImpl.DoStep)); serviceBinder.AddMethod(__Method_Reset, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::Simulation.ResetRequest, global::Simulation.ResetResponse>(serviceImpl.Reset)); }
public void Setup(BenchmarkContext context) { sim = BenchmarkUtils.CreateCarFollowingSim(context.Trace, 24, 50, 50, 12000, 72000, 0.005f); }
public void Setup(BenchmarkContext context) { sim = BenchmarkUtils.CreateCellBasedSim(context.Trace, 24, 100, 100, 50000, 300000, 0.01f); }
public static void RunOpenCL(SimulationBase sim) { sim.DoBatchOpenCL(dispatcher, device, RunStepCount); }
public static void Cleanup(SimulationBase sim) { sim.Dispose(); }
public void Setup(BenchmarkContext context) { sim = BenchmarkUtils.CreateCarFollowingSim(context.Trace, 24, 220, 220, 250000, 1500000, 0.01f); }