public void CarMovementOpenCL()
        {
            CellBasedSim sim = new CellBasedSim(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].CarIndex);

            OpenCLDispatcher dispatcher;
            OpenCLDevice     device;

            TestUtils.GetOpenCLDispatcherAndDevice(out dispatcher, out device);

            sim.DoStepOpenCL(dispatcher, device);
            sim.DoStepOpenCL(dispatcher, device);

            Car carNext = sim.Current.Cars[0];

            Assert.AreEqual(sim.Current.Cells[carPrev.Position].T1, carNext.Position);
            Assert.AreEqual(1f, carNext.Speed);

            Assert.AreEqual(0, sim.Current.CellsToCar[carNext.Position].CarIndex);
        }
        public void OneStepOpenCL()
        {
            CellBasedSim sim = new CellBasedSim(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.CellBased, 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(15460, sim.Current.Cells.Length);
            Assert.AreEqual(15460, sim.Current.CellsToCar.Length);
            Assert.AreEqual(15460, sim.Current.CellsUi.Length);
            Assert.AreEqual(140, sim.Current.Generators.Length);
            Assert.AreEqual(100, sim.Current.Junctions.Length);

            Assert.IsFalse(string.IsNullOrWhiteSpace(sim.ToString()));
        }
        public void CarTerminationOpenCL()
        {
            CellBasedSim sim = new CellBasedSim(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()
        {
            CellBasedSim sim = new CellBasedSim(TestUtils.RandomSeed);

            sim.GenerateNew(24, 10, 10, 500, 3000, 0.1f, TestUtils.RandomSeed);

            TestUtils.AssertSimulationWithState(sim, SimulationType.CellBased, "CellBasedGenerated.trs");
        }
        public void DoBatchToCheckpointOpenCL()
        {
            CellBasedSim sim = new CellBasedSim(TestUtils.RandomSeed);

            sim.GenerateNew(24, 10, 10, 500, 3000, 0.1f, TestUtils.RandomSeed);

            TestUtils.DoBatchOpenCLToCheckpointAndAssert(sim, SimulationType.CellBased, "CellBased.trs");
        }
        public void DoStepsToCheckpointReference()
        {
            CellBasedSim sim = new CellBasedSim(TestUtils.RandomSeed);

            sim.GenerateNew(24, 10, 10, 500, 3000, 0.1f, TestUtils.RandomSeed);

            TestUtils.DoStepsReferenceToCheckpointAndAssert(sim, SimulationType.CellBased, "CellBased.trs");
        }
        public void CheckIntegrity()
        {
            CellBasedSim sim = new CellBasedSim(TestUtils.RandomSeed);

            sim.GenerateNew(24, 10, 10, 500, 3000, 0.1f, TestUtils.RandomSeed);

            sim.DoStepReference();

            bool result = sim.CheckIntegrity();

            Assert.IsTrue(result);
        }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
        private void OnPaintCellBasedSim(PaintEventArgs e, CellBasedSim simulation)
        {
            const int OverdrawSize = 60;

            if (simulation == null || simulation.Current.Cells == null)
            {
                return;
            }

            Matrix oldTransform = e.Graphics.Transform;

            e.Graphics.ScaleTransform(scaleFactor, scaleFactor);

            Size clientSize = ClientSize;

            ref SimulationData current = ref simulation.Current;
Ejemplo n.º 10
0
        public static CellBasedSim CreateCellBasedSim(IBenchmarkTrace trace, int distance,
                                                      int junctionsX, int junctionsY, int carCount, int maxCarCount, float generatorProbability)
        {
            PrintBenchmarkInfoIfNeeded <CellBasedSim>(trace, distance,
                                                      junctionsX, junctionsY, carCount, maxCarCount, generatorProbability);

            CellBasedSim sim = new CellBasedSim(RandomSeed);

            sim.GenerateNew(distance, junctionsX, junctionsY, carCount, maxCarCount, generatorProbability, RandomSeed);

            for (int i = 0; i < WarmupStepCount; i++)
            {
                sim.DoStepReference();
            }

            return(sim);
        }
Ejemplo n.º 11
0
        /// <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;
            }
        }
        public void CarSpawnReference()
        {
            CellBasedSim sim = new CellBasedSim(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].CarIndex);
        }
        public void CarTerminationReference()
        {
            CellBasedSim sim = new CellBasedSim(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()
        {
            CellBasedSim sim = new CellBasedSim(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].CarIndex);

            sim.DoStepReference();
            sim.DoStepReference();

            Car carNext = sim.Current.Cars[0];

            Assert.AreEqual(sim.Current.Cells[carPrev.Position].T1, carNext.Position);
            Assert.AreEqual(1f, carNext.Speed);

            Assert.AreEqual(0, sim.Current.CellsToCar[carNext.Position].CarIndex);
        }
        public void OneStepReference()
        {
            CellBasedSim sim = new CellBasedSim(TestUtils.RandomSeed);

            sim.GenerateNew(24, 10, 10, 500, 3000, 0.1f, TestUtils.RandomSeed);

            sim.DoStepReference();

            Assert.AreEqual(SimulationType.CellBased, 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(15460, sim.Current.Cells.Length);
            Assert.AreEqual(15460, sim.Current.CellsToCar.Length);
            Assert.AreEqual(15460, sim.Current.CellsUi.Length);
            Assert.AreEqual(140, sim.Current.Generators.Length);
            Assert.AreEqual(100, sim.Current.Junctions.Length);

            Assert.IsFalse(string.IsNullOrWhiteSpace(sim.ToString()));
        }
        public void CarSpawnOpenCL()
        {
            CellBasedSim sim = new CellBasedSim(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].CarIndex);
        }