Esempio n. 1
0
        public StSimulator(SimulationOptions options)
        {
            Size          = options.Size;
            StartLocation = options.StartLocation;

            m_Data          = EdgeData.AllocateNew(Size);
            m_ProccesedData = EdgeData.AllocateLike(m_Data);

            SimulationInfo = new StSimulationInfo(TotalSimulations, AverageTravelPath, TotalSimTime);
            LastPath       = new StParticlePath(StartLocation, null, new List <GridIndex>());
        }
Esempio n. 2
0
        public void Reset()
        {
            m_Data = EdgeData.AllocateLike(m_Data);
            ProcessData();
            TotalSimulations  = 0;
            AverageTravelPath = 0;
            TotalSimTime      = 0;

            SimulationInfo = new StSimulationInfo(TotalSimulations, AverageTravelPath, TotalSimTime);
            LastPath       = new StParticlePath(StartLocation, null, new List <GridIndex>());
        }
Esempio n. 3
0
        public void SimulateSteps(long steps = 1)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            List <GridIndex> path = new List <GridIndex>();

            for (long step = 0; step < steps; step++)
            {
                GridIndex pos        = StartLocation;
                int       travelPath = 0;

                if (step == steps - 1) // last step
                {
                    path.Add(pos);     // record path
                }

                while (m_Data.Inaccessable.IsInside(pos))
                {
                    pos += SelectRandomDirection();

                    travelPath++;
                    if (step == steps - 1) // last step
                    {
                        path.Add(pos);
                    }
                }
                m_Data[pos] += 1;

                AverageTravelPath = (AverageTravelPath * TotalSimulations + travelPath) / ++TotalSimulations;
            }
            stopwatch.Stop();
            ProcessData();

            TotalSimTime += stopwatch.Elapsed.TotalMilliseconds;

            SimulationInfo = new StSimulationInfo(TotalSimulations, AverageTravelPath, TotalSimTime);
            LastPath       = new StParticlePath(StartLocation, path.Last(), path);
        }