예제 #1
0
        /// <summary>
        /// Metoda generująca macierz losowego układu
        /// </summary>
        /// <param name="r">Randomizer</param>
        /// <param name="size">Rozmiar układu</param>
        /// <param name="stateCount">Ilość stanów</param>
        /// <returns>Macierz układu</returns>
        internal static InitialConditionsGrid GenerateRandom(Random r, int size = 100, int stateCount = SPDAssets.MAX)
        {
            int x = size;
            int y = size;

            List <InitialConditionCell>[] setLists = new List <InitialConditionCell> [stateCount];
            for (int i = 0; i < setLists.Length; i++)
            {
                setLists[i] = new List <InitialConditionCell>();
            }
            InitialConditionCell[,] grid = new InitialConditionCell[x, y];
            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    int k = r.Next(setLists.Length);
                    InitialConditionCell c = new InitialConditionCell(i, j, k, k);
                    grid[i, j] = c;
                    setLists[k].Add(c);
                }
            }
            var sets = setLists.Select(a => a.ToArray()).ToArray();
            InitialConditionsGrid ig = new InitialConditionsGrid
            {
                CellGrid = grid,
                CellSets = sets
            };

            return(ig);
        }
예제 #2
0
        /// <summary>
        /// Metoda factory generująca koło
        /// </summary>
        /// <param name="size">Rozmiar układu</param>
        /// <param name="stateCount">Ilość możliwych wartości</param>
        /// <returns>Układ początkowy z kołem</returns>
        internal static InitialConditionsGrid CircleFactory(int size=30,int stateCount=SPDAssets.MAX)
        {
            InitialConditionCell[,] ic = new InitialConditionCell[size, size];
            List<InitialConditionCell>[] setLists = new List<InitialConditionCell>[SPDAssets.MAX];
            for (int i = 0; i < setLists.Length; i++) setLists[i] = new List<InitialConditionCell>();
            for (int i = 0; i < size; i++)
                for (int j = 0; j < size; j++)
                {
                    InitialConditionCell c = new InitialConditionCell(i, j, 0, -1);
                    for (int k = 0;k<stateCount-1;k++)
                    {

                        if ((i - size/2) * (i - size/2) + (j - size/2) * (j - size/2) <= (size/2)*(size/2) / ((k+1)*(k + 1)))
                        {
                            c.Set = k;
                        }
                    }
                    if (c.Set < 0)
                    {
                        c.Set = stateCount-1;
                    }
                    ic[i, j] = c;
                    setLists[c.Set].Add(c);
                }
            var sets = setLists.Select(a => a.ToArray()).ToArray();
            InitialConditionsGrid ig = new InitialConditionsGrid
            {
                CellGrid = ic,
                CellSets = sets
            };
            return ig;
        }
예제 #3
0
        /// <summary>
        /// Metoda factory generująca przekątną
        /// </summary>
        /// <param name="size">Rozmiar układu</param>
        /// <param name="stateCount">Ilość możliwych wartości</param>
        /// <returns>Układ początkowy z przekątną</returns>
        internal static InitialConditionsGrid DiagonalFactory(int size = 30, int stateCount = SPDAssets.MAX)
        {
            InitialConditionCell[,] ic = new InitialConditionCell[size, size];
            List <InitialConditionCell>[] setLists = new List <InitialConditionCell> [stateCount];
            for (int i = 0; i < setLists.Length; i++)
            {
                setLists[i] = new List <InitialConditionCell>();
            }
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    int k = Math.Abs(i - j);
                    int m = Math.Max(ic.GetLength(0), ic.GetLength(1));
                    InitialConditionCell c = new InitialConditionCell(i, j, 0, k * (stateCount) / m);


                    ic[i, j] = c;
                    setLists[c.Set].Add(c);
                }
            }
            var sets = setLists.Select(a => a.ToArray()).ToArray();
            InitialConditionsGrid ig = new InitialConditionsGrid
            {
                CellGrid = ic,
                CellSets = sets
            };

            return(ig);
        }
예제 #4
0
        internal static InitialConditionsGrid NowakMayFactory(int size = 31, int StateCount = SPDAssets.MAX)
        {
            InitialConditionCell[,] ic = new InitialConditionCell[size, size];
            List <InitialConditionCell>[] setLists = new List <InitialConditionCell> [SPDAssets.MAX];
            for (int i = 0; i < setLists.Length; i++)
            {
                setLists[i] = new List <InitialConditionCell>();
            }
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    int k = -1;
                    if (size % 2 == 0)
                    {
                        if (i == size / 2 || i + 1 == size / 2)
                        {
                            if (j == size / 2 || j + 1 == size / 2)
                            {
                                k = 0;
                            }
                        }
                    }
                    else
                    {
                        if (i == size / 2)
                        {
                            if (j == size / 2)
                            {
                                k = 0;
                            }
                        }
                    }
                    if (k < 0)
                    {
                        k = StateCount - 1;
                    }
                    InitialConditionCell c = new InitialConditionCell(i, j, k, k);
                    ic[i, j] = c;
                    setLists[c.Set].Add(c);
                }
            }
            var sets = setLists.Select(a => a.ToArray()).ToArray();
            InitialConditionsGrid ig = new InitialConditionsGrid
            {
                CellGrid = ic,
                CellSets = sets
            };

            return(ig);
        }
예제 #5
0
        /// <summary>
        /// Metoda factory generująca koło
        /// </summary>
        /// <param name="size">Rozmiar układu</param>
        /// <param name="stateCount">Ilość możliwych wartości</param>
        /// <returns>Układ początkowy z kołem</returns>
        internal static InitialConditionsGrid CircleFactory(int size = 30, int stateCount = SPDAssets.MAX)
        {
            InitialConditionCell[,] ic = new InitialConditionCell[size, size];
            List <InitialConditionCell>[] setLists = new List <InitialConditionCell> [SPDAssets.MAX];
            for (int i = 0; i < setLists.Length; i++)
            {
                setLists[i] = new List <InitialConditionCell>();
            }
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    InitialConditionCell c = new InitialConditionCell(i, j, 0, -1);
                    for (int k = 0; k < stateCount - 1; k++)
                    {
                        if ((i - size / 2) * (i - size / 2) + (j - size / 2) * (j - size / 2) <= (size / 2) * (size / 2) / ((k + 1) * (k + 1)))
                        {
                            c.Set = k;
                        }
                    }
                    if (c.Set < 0)
                    {
                        c.Set = stateCount - 1;
                    }
                    ic[i, j] = c;
                    setLists[c.Set].Add(c);
                }
            }
            var sets = setLists.Select(a => a.ToArray()).ToArray();
            InitialConditionsGrid ig = new InitialConditionsGrid
            {
                CellGrid = ic,
                CellSets = sets
            };

            return(ig);
        }
예제 #6
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
            });
        }
예제 #7
0
        /// <summary>
        /// Metoda tworząca kopię układu
        /// </summary>
        /// <returns>Kopia układu</returns>
        internal InitialConditionsGrid GetCopy()
        {
            List <InitialConditionCell[]> list = new List <InitialConditionCell[]>();

            InitialConditionCell[,] grid = new InitialConditionCell[CellGrid.GetLength(0), CellGrid.GetLength(1)];
            foreach (InitialConditionCell[] t in CellSets)
            {
                List <InitialConditionCell> l = new List <InitialConditionCell>();
                foreach (InitialConditionCell t1 in t)
                {
                    var c = t1.GetCopy();
                    grid[c.X, c.Y] = c;
                    l.Add(c);
                }
                list.Add(l.ToArray());
            }
            var set = list.ToArray();

            return(new InitialConditionsGrid
            {
                CellGrid = grid,
                CellSets = set
            });
        }
예제 #8
0
        /// <summary>
        /// Metoda factory generująca przekątną
        /// </summary>
        /// <param name="size">Rozmiar układu</param>
        /// <param name="stateCount">Ilość możliwych wartości</param>
        /// <returns>Układ początkowy z przekątną</returns>
        internal static InitialConditionsGrid DiagonalFactory(int size=30,int stateCount=SPDAssets.MAX)
        {
            InitialConditionCell[,] ic = new InitialConditionCell[size, size];
            List<InitialConditionCell>[] setLists = new List<InitialConditionCell>[stateCount];
            for (int i = 0; i < setLists.Length; i++) setLists[i] = new List<InitialConditionCell>();
            for (int i = 0; i < size; i++)
                for (int j = 0; j < size; j++)
                {
                    int k = Math.Abs(i - j);
                    int m = Math.Max(ic.GetLength(0), ic.GetLength(1));
                    InitialConditionCell c = new InitialConditionCell(i, j, 0, k * (stateCount) / m);

                    ic[i, j] = c;
                    setLists[c.Set].Add(c);
                }
            var sets = setLists.Select(a => a.ToArray()).ToArray();
            InitialConditionsGrid ig = new InitialConditionsGrid
            {
                CellGrid = ic,
                CellSets = sets
            };
            return ig;
        }
예제 #9
0
 /// <summary>
 /// Metoda tworząca kopię układu
 /// </summary>
 /// <returns>Kopia układu</returns>
 internal InitialConditionsGrid GetCopy()
 {
     List<InitialConditionCell[]> list = new List<InitialConditionCell[]>();
     InitialConditionCell[,] grid = new InitialConditionCell[CellGrid.GetLength(0), CellGrid.GetLength(1)];
     foreach (InitialConditionCell[] t in CellSets)
     {
         List<InitialConditionCell> l = new List<InitialConditionCell>();
         foreach (InitialConditionCell t1 in t)
         {
             var c = t1.GetCopy();
             grid[c.X, c.Y] = c;
             l.Add(c);
         }
         list.Add(l.ToArray());
     }
     var set = list.ToArray();
     return new InitialConditionsGrid
     {
         CellGrid = grid,
         CellSets = set
     };
 }
예제 #10
0
 internal static InitialConditionsGrid NowakMayFactory(int size = 31, int StateCount = SPDAssets.MAX)
 {
     InitialConditionCell[,] ic = new InitialConditionCell[size, size];
     List<InitialConditionCell>[] setLists = new List<InitialConditionCell>[SPDAssets.MAX];
     for (int i = 0; i < setLists.Length; i++) setLists[i] = new List<InitialConditionCell>();
     for (int i = 0; i < size; i++)
         for (int j = 0; j < size; j++)
         {
             int k=-1;
             if (size%2 == 0)
             {
                 if (i == size/2 || i + 1 == size/2)
                 {
                     if (j == size / 2 || j + 1 == size / 2)
                     {
                         k = 0;
                     }
                 }
             }
             else
             {
                 if (i == size / 2)
                 {
                     if (j == size / 2 )
                     {
                         k = 0;
                     }
                 }
             }
             if (k < 0) k = StateCount - 1;
             InitialConditionCell c = new InitialConditionCell(i,j,k,k);
             ic[i, j] = c;
             setLists[c.Set].Add(c);
         }
     var sets = setLists.Select(a => a.ToArray()).ToArray();
     InitialConditionsGrid ig = new InitialConditionsGrid
     {
         CellGrid = ic,
         CellSets = sets
     };
     return ig;
 }
예제 #11
0
        /// <summary>
        /// Metoda generująca macierz losowego układu
        /// </summary>
        /// <param name="r">Randomizer</param>
        /// <param name="size">Rozmiar układu</param>
        /// <param name="stateCount">Ilość stanów</param>
        /// <returns>Macierz układu</returns>
        internal static InitialConditionsGrid GenerateRandom(Random r,int size=100,int stateCount=SPDAssets.MAX)
        {
            int x = size;
            int y = size;
            List<InitialConditionCell>[] setLists = new List<InitialConditionCell>[stateCount];
            for(int i=0;i<setLists.Length;i++) setLists[i]=new List<InitialConditionCell>();
            InitialConditionCell[,] grid = new InitialConditionCell[x,y];
            for(int i=0;i<x;i++)
                for (int j = 0; j < y; j++)
                {
                    int k = r.Next(setLists.Length);
                    InitialConditionCell c = new InitialConditionCell(i,j,k,k);
                    grid[i, j] = c;
                    setLists[k].Add(c);

                }
            var sets = setLists.Select(a => a.ToArray()).ToArray();
            InitialConditionsGrid ig = new InitialConditionsGrid
            {
                CellGrid = grid,
                CellSets = sets
            };
            return ig;
        }
예제 #12
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};
 }