Exemplo n.º 1
0
        public void SimulateSteps(long steps = 1)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            for (long step = 0; step < steps; step++)
            {
                GridData newData = GridData.AllocateLike(m_Data);
                foreach (var idx in m_Data.Bounds.Shrink(1).EnumerateRegion())
                {
                    newData[idx.Right()]       += m_Data[idx] * HorizontalVerticalMovePropability;
                    newData[idx.TopRight()]    += m_Data[idx] * DiagonalMovePropability;
                    newData[idx.Top()]         += m_Data[idx] * HorizontalVerticalMovePropability;
                    newData[idx.TopLeft()]     += m_Data[idx] * DiagonalMovePropability;
                    newData[idx.Left()]        += m_Data[idx] * HorizontalVerticalMovePropability;
                    newData[idx.BottomLeft()]  += m_Data[idx] * DiagonalMovePropability;
                    newData[idx.Bottom()]      += m_Data[idx] * HorizontalVerticalMovePropability;
                    newData[idx.BottomRight()] += m_Data[idx] * DiagonalMovePropability;
                }

                foreach (var idx in m_Data.Bounds.EnumerateEdge())
                {
                    newData[idx] += m_Data[idx];
                }

                m_Data = newData;
                Step++;
            }
            stopwatch.Stop();
            TotalSimTime += stopwatch.Elapsed.TotalMilliseconds;

            SimulationInfo = new PrSimulationInfo(Step, TotalSimTime, GetCenterSum(), GetEdgeSum(), GetTotalSum());
        }
Exemplo n.º 2
0
        public void Reset()
        {
            m_Data                = GridData.AllocateLike(m_Data);
            Step                  = 0;
            TotalSimTime          = 0;
            m_Data[StartLocation] = 1;

            SimulationInfo = new PrSimulationInfo(Step, TotalSimTime, GetCenterSum(), GetEdgeSum(), GetTotalSum());
        }
Exemplo n.º 3
0
 public PrSimulator(SimulationOptions options)
 {
     Size                  = options.Size;
     StartLocation         = options.StartLocation;
     m_Data                = GridData.AllocateNew(Size);
     m_Data[StartLocation] = 1;
     Step                  = 0;
     TotalSimTime          = 0;
     SimulationInfo        = new PrSimulationInfo(Step, TotalSimTime, 1, 0, 1);
 }