示例#1
0
 public static void RunReference(SimulationBase sim)
 {
     for (int i = 0; i < RunStepCount; i++)
     {
         sim.DoStepReference();
     }
 }
示例#2
0
        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);
        }
示例#7
0
        /// <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;
        }
示例#8
0
        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;
            }
        }
示例#10
0
        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);
                }
            }
        }
示例#11
0
 /// <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));
 }
示例#12
0
 /// <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());
 }
示例#13
0
 /// <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));
 }
示例#14
0
 public void Setup(BenchmarkContext context)
 {
     sim = BenchmarkUtils.CreateCarFollowingSim(context.Trace, 24, 50, 50, 12000, 72000, 0.005f);
 }
示例#15
0
 public void Setup(BenchmarkContext context)
 {
     sim = BenchmarkUtils.CreateCellBasedSim(context.Trace, 24, 100, 100, 50000, 300000, 0.01f);
 }
示例#16
0
 public static void RunOpenCL(SimulationBase sim)
 {
     sim.DoBatchOpenCL(dispatcher, device, RunStepCount);
 }
示例#17
0
 public static void Cleanup(SimulationBase sim)
 {
     sim.Dispose();
 }
示例#18
0
 public void Setup(BenchmarkContext context)
 {
     sim = BenchmarkUtils.CreateCarFollowingSim(context.Trace, 24, 220, 220, 250000, 1500000, 0.01f);
 }