Example #1
0
 internal static InitialConditionsGrid FromCellArray(Tuple<int,float>[,] cells)
 {
     InitialConditionCell[,] arr = new InitialConditionCell[cells.GetLength(0),cells.GetLength(1)];
     var list = new List<List<InitialConditionCell>>();
     for(int i=0;i<SPDAssets.MAX;i++) list.Add(new List<InitialConditionCell>());
     for(int i=0;i<cells.GetLength(0);i++)
         for (int j = 0; j < cells.GetLength(1); j++)
         {
             int k = (new IntegerStrategy(cells[i,j].Item1)).BetrayalThreshold;
             arr[i,j] = new InitialConditionCell(i,j,k,k);
             list[k].Add(arr[i, j]);
         }
     var arr2 = list.Select(l => l.ToArray()).ToArray();
     return new InitialConditionsGrid {CellGrid = arr, CellSets = arr2};
 }
Example #2
0
        private static void PrintPredecessorMatrix(Tuple<Vector2, Vector2>[,] predecessorMatrix)
        {
            System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\gertj\myPredecessorMatrix.txt");
            //Print distance matrix
            for (int j = 0; j < predecessorMatrix.GetLength(0); j++)
            {
                string array = "";
                Console.Write("[");
                for (int k = 0; k < predecessorMatrix.GetLength(1); k++)
                {
                    if (predecessorMatrix[j, k] == null)
                    {
                        array += "X";
                        Console.Write("X");
                    }
                    else
                    {
                        array += predecessorMatrix[j, k];
                        Console.Write(" " + predecessorMatrix[j, k]);
                    }
                }
                array += " ]";
                Console.Write(" ] \r\n");

                file.WriteLine(array);
                array = "";
            }
            Console.Write(" ] \r\n");
        }
Example #3
0
        /// <summary>
        /// Metoda wyliczająca dane do wykresów na podstawie stanu automatu
        /// </summary>
        double[][] CalculateModels(Tuple<int,float>[,] cells)
        {
            var result = new double[_strategyCount];
            var count = new double[result.Length];
            var sum = new double[result.Length];
            for (var i = 0; i < result.Length; i++)
            {
                result[i] = 0;
                count[i] = 0;
                
            }
            for (var i = 0; i < cells.GetLength(0); i++)
                for (var j = 0; j < cells.GetLength(1); j++)
                {
                    var c = cells[i, j];

                    var integerStrategy = (IntegerStrategy) _strategyDictionary[c.Item1];


                    if (integerStrategy != null)
                    {
                        var k = integerStrategy.BetrayalThreshold;
                        double d = (double)c.Item2/_spd.Neighbours(i,j).Length;
                        result[k] += d;
                        count[k]++;
                        
                    }
                }
            for (var i = 0; i < count.Length; i++)
            {
                if ((count[i] - 100*Double.Epsilon) <= 0) continue;
                result[i] /= count[i];
                

            }
            var d1 = result.Sum();
            if (Math.Abs(d1) < double.Epsilon*100) d1 = 1;
            var d2 = count.Sum();
            if (Math.Abs(d2) < double.Epsilon * 100) d2 = 1;
            result = result.Select(d => 100 * d / d1).ToArray();
            for (int i = 0; i < result.Length; i++) _sumPoints[i] += result[i];
            _sumPointsHistory.Add(_sumPoints);
            count = count.Select(d => 100 * d / d2).ToArray();
            return new[] { count, result };
        }