Example #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());
        }
Example #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());
        }
        private static GridData NormalizeData(GridData data)
        {
            double min = double.MaxValue, max = double.MinValue;

            foreach (var idx in data.Bounds.EnumerateRegion())
            {
                min = Min(min, data[idx]);
                max = Max(max, data[idx]);
            }

            double magnitude = max - min;

            var newData = GridData.AllocateLike(data);

            foreach (var idx in data.Bounds.EnumerateRegion())
            {
                newData[idx] = (data[idx] - min) / magnitude;
            }

            return(newData);
        }