Пример #1
0
 public static PointMatrixPick SingularMatrixCondition(PointMatrix M, int size1,int size2)
 {
     PointMatrixPick p = new PointMatrixPick
     {
         Indices = new int[size1, size2],
         Matrices = new List<PointMatrix> {M}
     };
     for (int i = 0; i < size1; i++) for (int j = 0; j < size2; j++) p.Indices[i, j] = 0;
     return p;
 }
Пример #2
0
 public static PointMatrixPick CreatePickFromIC(InitialConditions IC,PointMatrixPick _pick)
 {
     PointMatrixPick Condition=new PointMatrixPick();
     Condition.Matrices = _pick.Matrices.ToList();
     Condition.Indices = new int[IC.Grid.CellGrid.GetLength(0), IC.Grid.CellGrid.GetLength(1)];
     for (int i = 0; i < IC.Grid.CellGrid.GetLength(0); i++)
     {
         for (int j = 0; j < IC.Grid.CellGrid.GetLength(1); j++)
         {
             Condition.Indices[i, j] = IC.Grid.CellGrid[i, j].Value >= Condition.Matrices.Count ? Condition.Matrices.Count - 1 : IC.Grid.CellGrid[i, j].Value;
         }
     }
     return Condition;
 }
Пример #3
0
 public static InitialConditions CreateICFromPick(PointMatrixPick Condition)
 {
     var IC = new InitialConditions();
     var IG = new InitialConditionsGrid();
     IG.CellGrid = new InitialConditionCell[Condition.Indices.GetLength(0), Condition.Indices.GetLength(1)];
     for (int i = 0; i < Condition.Indices.GetLength(0); i++)
     {
         for (int j = 0; j < Condition.Indices.GetLength(1); j++)
         {
             IG.CellGrid[i, j] = new InitialConditionCell(i, j, Condition.Indices[i, j], Condition.Indices[i, j]);
         }
     }
     IC.Grid = IG;
     return IC;
 }
Пример #4
0
 private void AdvancedMatrix_OnClick(object sender, RoutedEventArgs e)
 {
     AdvancedPointMatrix = true;
     var d = Validate();
     if (d == null)
     {
         MessageBox.Show("Podstawowa Macierz musi być poprawna przed przejściem do zaawansowanych ustawień");
     }
     var D = d.Select(x=>(float)x).ToArray();
     PointMatrixPicker picker = new PointMatrixPicker(new PointMatrix(D[3], D[2], D[1], D[0]), _ic.Grid.CellGrid.GetLength(0), _ic.Grid.CellGrid.GetLength(1), pointMatrix);
     var b = picker.ShowDialog();
     if (b.HasValue && b.Value)
     {
         AdvancedMatrixAccepted = true;
         pointMatrix = picker.Condition;
     }
 }
Пример #5
0
        public PointMatrixPick Resize(int Size)
        {
            PointMatrixPick result = new PointMatrixPick
            {
                Matrices = Matrices.ToList(),
                Indices = new int[Size, Size]
            };

            double d = (double)Size / this.Size;
            for (int i = 0; i < Size; i++)
            {
                double index = i / d;
                int k = (int)Math.Floor(index);
                int l = k + 1;
                double prob = 1 - (index - k);
                int I = random.NextDouble() < prob ? k : l;
                for (int j = 0; j < Size; j++)
                {
                    index = i / d;
                    k = (int)Math.Floor(index);
                    l = k + 1;
                    prob = 1 - (index - k);
                    int J = random.NextDouble() < prob ? k : l;
                    result.Indices[i, j] = Indices[I, J];
                }
            }
            return result;
        }
Пример #6
0
        /// <summary>
        /// Konstruktor okna realizującego symulacje
        /// </summary>
        /// <param name="PayValues">Tablica zawierająca informacje wyekstrahowane z macierzy wypłat </param>
        /// <param name="strategies">Tablica zawierająca początkowe strategie w automacie</param>
        /// <param name="torus">Zmienna informująca czy obliczenia automatu realizowane są na torusie</param>
        /// <param name="vonneumann">Zmienna informująca czy obliczenia automatu realizowane są z sąsiedztwem Von Neumanna</param>
        public SPDView(PointMatrixPick Matrix, int[,] strategies, int _neighboursCount, INeighbourhood _neighbourhood)
        {
            _tooltip = -1;
            _strategyCount = 2 + _neighboursCount;
            _sumPointsHistory = new List<double[]>();
            _sumPoints = new double[_strategyCount];
            DataContext = this;
            pointMatrixPick = Matrix;
            float[,] fakePoints = new float[strategies.GetLength(0), strategies.GetLength(1)];

            AddHistory(strategies,fakePoints);
            
            for (int i = 0; i < _sumPoints.Length; i++) _sumPoints[i] = 0;
            
            _strategies = strategies;
            neighbourhood = _neighbourhood;
#if DEBUG
            var threadNum = 1; //debugging purposes DON'T remove
#else
            var threadNum = 16;
#endif
            _strategyDictionary = GenerateIntegerStrategies(_strategyCount);
            
            _spd =

                new SPD.Engine.SPD(
                    Matrix.Function,
                    neighbourhood, strategies,
                  _strategyDictionary, 10, threadNum, Matrix.ModifiedPointCounting ? OptimizationKind.Relative : OptimizationKind.Absolute);

            Speed = 1;
            PointsModel = new PlotModel();
            CountModel = new PlotModel();
            ChangeModel = new PlotModel();
            SumModel = new PlotModel();
            PointsModel.Title = "Średnie wartości punktowe";
            CountModel.Title = "Liczebność strategii";
            ChangeModel.Title = "Niestabilność układu";
            SumModel.Title = "Punkty dla strategii zagregowane";
            _iterations = new List<Tuple<int, string>>();

            PointsModel.Axes.Add(new CategoryAxis { ItemsSource = _iterations, LabelField = "Item2" });

            CountModel.Axes.Add(new CategoryAxis { ItemsSource = _iterations, LabelField = "Item2" });
            PointsModel.Axes.Add(new LinearAxis { MinimumPadding = 0, AbsoluteMinimum = 0 });
            CountModel.Axes.Add(new LinearAxis { MinimumPadding = 0, AbsoluteMinimum = 0 });

            PointsModel.Series.Add(new ColumnSeries { ColumnWidth = 10, IsStacked = true });
            CountModel.Series.Add(new ColumnSeries { ColumnWidth = 10, IsStacked = true });

            ChangeModel.Axes.Add(new CategoryAxis { ItemsSource = _iterations, LabelField = "Item2" });
            ChangeModel.Axes.Add(new LinearAxis { MinimumPadding = 0, AbsoluteMinimum = 0 });
            ChangeModel.Series.Add(new ColumnSeries {ColumnWidth = 10, IsStacked = true});
                 SumModel.Axes.Add(new CategoryAxis { ItemsSource = _iterations, LabelField = "Item2" });
            SumModel.Axes.Add(new LinearAxis { MinimumPadding = 0, AbsoluteMinimum = 0 });
            SumModel.Series.Add(new ColumnSeries { ColumnWidth = 10, IsStacked = true });
       

            UpdateModels();

            InitializeComponent();
            Iteration = 0;

            var D =  SPDAssets.GenerateLegend(Legenda.Height, _strategyCount);

           
            _width = _strategies.GetLength(0);
            _height = _strategies.GetLength(1);
            var image2 = new Image
            {
                Source = GenerateImage(_spd, 0, 0, _strategies.GetLength(0), _strategies.GetLength(1))

            };


            Canvas.SetTop(D, 0);
            Canvas.SetLeft(D, 0);
            Legenda.Children.Add(D);
            Canvas.Children.Add(image2);
        }