public void CarMovementOpenCL() { CarFollowingSim sim = new CarFollowingSim(TestUtils.RandomSeed); sim.Flags = SimulationFlags.NoSpawn; sim.GenerateNew(10, 2, 1, 1, 1, float.PositiveInfinity, TestUtils.RandomSeed); Car carPrev = sim.Current.Cars[0]; Assert.AreEqual(0, sim.Current.CellsToCar[carPrev.Position * sim.Current.CarsPerCell]); OpenCLDispatcher dispatcher; OpenCLDevice device; TestUtils.GetOpenCLDispatcherAndDevice(out dispatcher, out device); sim.DoStepOpenCL(dispatcher, device); Car carNext = sim.Current.Cars[0]; Assert.AreEqual(carPrev.Position, carNext.Position); Assert.AreEqual(1f, carNext.Speed); Assert.AreEqual(0, sim.Current.CellsToCar[carNext.Position * sim.Current.CarsPerCell]); }
public void OneStepOpenCL() { CarFollowingSim sim = new CarFollowingSim(TestUtils.RandomSeed); sim.GenerateNew(24, 10, 10, 500, 3000, 0.1f, TestUtils.RandomSeed); OpenCLDispatcher dispatcher; OpenCLDevice device; TestUtils.GetOpenCLDispatcherAndDevice(out dispatcher, out device); sim.DoStepOpenCL(dispatcher, device); Assert.AreEqual(SimulationType.CarFollowing, sim.CurrentType); Assert.IsTrue(sim.IsReady); Assert.AreEqual(1, sim.CurrentStep); Assert.AreEqual(3000, sim.Current.Cars.Length); Assert.AreEqual(3000, sim.Current.CarsUi.Length); Assert.AreEqual(1380, sim.Current.Cells.Length); Assert.AreEqual(33120, sim.Current.CellsToCar.Length); Assert.AreEqual(1380, sim.Current.CellsUi.Length); Assert.AreEqual(140, sim.Current.Generators.Length); Assert.AreEqual(100, sim.Current.Junctions.Length); Assert.AreEqual(24, sim.Current.CarsPerCell); Assert.IsFalse(string.IsNullOrWhiteSpace(sim.ToString())); }
public void CarTerminationOpenCL() { CarFollowingSim sim = new CarFollowingSim(TestUtils.RandomSeed); sim.Flags = SimulationFlags.NoSpawn; sim.GenerateNew(10, 1, 1, 1, 1, float.PositiveInfinity, TestUtils.RandomSeed); Car carPrev = sim.Current.Cars[0]; Assert.AreNotEqual(Cell.None, carPrev.Position); OpenCLDispatcher dispatcher; OpenCLDevice device; TestUtils.GetOpenCLDispatcherAndDevice(out dispatcher, out device); for (int i = 0; i < 20; i++) { sim.DoStepOpenCL(dispatcher, device); } Car carNext = sim.Current.Cars[0]; Assert.AreEqual(Cell.None, carNext.Position); }
public void GenerateNew() { CarFollowingSim sim = new CarFollowingSim(TestUtils.RandomSeed); sim.GenerateNew(24, 10, 10, 500, 3000, 0.1f, TestUtils.RandomSeed); TestUtils.AssertSimulationWithState(sim, SimulationType.CarFollowing, "CarFollowingGenerated.trs"); }
public void DoBatchToCheckpointOpenCL() { CarFollowingSim sim = new CarFollowingSim(TestUtils.RandomSeed); sim.GenerateNew(24, 10, 10, 500, 3000, 0.1f, TestUtils.RandomSeed); TestUtils.DoBatchOpenCLToCheckpointAndAssert(sim, SimulationType.CarFollowing, "CarFollowing.trs"); }
public void DoStepsToCheckpointReference() { CarFollowingSim sim = new CarFollowingSim(TestUtils.RandomSeed); sim.GenerateNew(24, 10, 10, 500, 3000, 0.1f, TestUtils.RandomSeed); TestUtils.DoStepsReferenceToCheckpointAndAssert(sim, SimulationType.CarFollowing, "CarFollowing.trs"); }
public void CheckIntegrity() { CarFollowingSim sim = new CarFollowingSim(TestUtils.RandomSeed); sim.GenerateNew(24, 10, 10, 500, 3000, 0.1f, TestUtils.RandomSeed); sim.DoStepReference(); bool result = sim.CheckIntegrity(); Assert.IsTrue(result); }
private void OnNewButtonClick(object sender, EventArgs e) { using (CreateNewDialog dialog = new CreateNewDialog()) { DialogResult result = dialog.ShowDialog(this); if (result != DialogResult.OK) { return; } SimulationBase sim; switch (dialog.SimulationType) { case SimulationType.CellBased: sim = new CellBasedSim(); break; case SimulationType.CarFollowing: sim = new CarFollowingSim(); break; default: throw new InvalidDataException("Unknown simulation type"); } ProgressDialog progressDialog = new ProgressDialog { Text = "Generating road network", MainInstruction = "Generating road network…", ShowInTaskbar = false, MinimizeBox = false, ProgressMarquee = true }; ThreadPool.UnsafeQueueUserWorkItem(delegate { BeginInvoke((MethodInvoker) delegate { progressDialog.ShowDialog(this); }); sim.GenerateNew(dialog.Distance, dialog.JunctionsX, dialog.JunctionsY, dialog.CarCount, dialog.MaxCarCount, dialog.GeneratorProbability); BindSimulation(sim); BeginInvoke((MethodInvoker) delegate { progressDialog.TaskCompleted(); RefreshToolbar(false); }); }, null); } }
public static CarFollowingSim CreateCarFollowingSim(IBenchmarkTrace trace, int distance, int junctionsX, int junctionsY, int carCount, int maxCarCount, float generatorProbability) { PrintBenchmarkInfoIfNeeded <CarFollowingSim>(trace, distance, junctionsX, junctionsY, carCount, maxCarCount, generatorProbability); CarFollowingSim sim = new CarFollowingSim(RandomSeed); sim.GenerateNew(distance, junctionsX, junctionsY, carCount, maxCarCount, generatorProbability, RandomSeed); for (int i = 0; i < WarmupStepCount; i++) { sim.DoStepReference(); } return(sim); }
public void CarSpawnReference() { CarFollowingSim sim = new CarFollowingSim(TestUtils.RandomSeed); sim.GenerateNew(10, 1, 1, 0, 1, 0, TestUtils.RandomSeed); Car carPrev = sim.Current.Cars[0]; Assert.AreEqual(Cell.None, carPrev.Position); sim.DoStepReference(); Car carNext = sim.Current.Cars[0]; Assert.AreNotEqual(Cell.None, carNext.Position); Assert.AreEqual(0f, carNext.Speed); Assert.AreEqual(0, sim.Current.CellsToCar[carNext.Position * sim.Current.CarsPerCell]); }
public void CarTerminationReference() { CarFollowingSim sim = new CarFollowingSim(TestUtils.RandomSeed); sim.Flags = SimulationFlags.NoSpawn; sim.GenerateNew(10, 1, 1, 1, 1, float.PositiveInfinity, TestUtils.RandomSeed); Car carPrev = sim.Current.Cars[0]; Assert.AreNotEqual(Cell.None, carPrev.Position); for (int i = 0; i < 20; i++) { sim.DoStepReference(); } Car carNext = sim.Current.Cars[0]; Assert.AreEqual(Cell.None, carNext.Position); }
public void CarMovementReference() { CarFollowingSim sim = new CarFollowingSim(TestUtils.RandomSeed); sim.Flags = SimulationFlags.NoSpawn; sim.GenerateNew(10, 2, 1, 1, 1, float.PositiveInfinity, TestUtils.RandomSeed); Car carPrev = sim.Current.Cars[0]; Assert.AreEqual(0, sim.Current.CellsToCar[carPrev.Position * sim.Current.CarsPerCell]); sim.DoStepReference(); Car carNext = sim.Current.Cars[0]; Assert.AreEqual(carPrev.Position, carNext.Position); Assert.AreEqual(1f, carNext.Speed); Assert.AreEqual(0, sim.Current.CellsToCar[carNext.Position * sim.Current.CarsPerCell]); }
public void CarSpawnOpenCL() { CarFollowingSim sim = new CarFollowingSim(TestUtils.RandomSeed); sim.GenerateNew(10, 1, 1, 0, 1, 0, TestUtils.RandomSeed); Car carPrev = sim.Current.Cars[0]; Assert.AreEqual(Cell.None, carPrev.Position); OpenCLDispatcher dispatcher; OpenCLDevice device; TestUtils.GetOpenCLDispatcherAndDevice(out dispatcher, out device); sim.DoStepOpenCL(dispatcher, device); Car carNext = sim.Current.Cars[0]; Assert.AreNotEqual(Cell.None, carNext.Position); Assert.AreEqual(0f, carNext.Speed); Assert.AreEqual(0, sim.Current.CellsToCar[carNext.Position * sim.Current.CarsPerCell]); }