예제 #1
0
        /// <summary>
        /// Konstruktor okna warunków początkowych
        /// </summary>
        internal InitialCondition(int _mode = SPDAssets.MAX, InitialConditions condition = null)
        {
            _tooltip = -1;
            InitializeComponent();

            Mode = _mode;
            _selectedOperation     = Operation.None;
            ComboBox.ItemsSource   = SPDAssets.GetBrushRectangles(Mode, InitialConditions.GetTransformation(Mode));
            ComboBox.SelectedIndex = 0;
            DataContext            = this;
            _conditionNames        = new List <Tuple <string, Tuple <string, bool> > >();
            _conditions            = new Dictionary <Tuple <string, bool>, Func <bool, int, int, bool, InitialConditions> >();
            foreach (var T in new[] { false, true })
            {
                _conditions.Add(new Tuple <string, bool>("Donut", T), InitialConditions.DonutFactory);
                _conditions.Add(new Tuple <string, bool>("Circle", T), InitialConditions.CircleFactory);
                _conditions.Add(new Tuple <string, bool>("Diagonal", T), InitialConditions.DiagonalFactory);
                _conditions.Add(new Tuple <string, bool>("NowakMay", T), InitialConditions.NowakMayFactory);
            }
            _conditionNames.AddRange(
                _conditions.Select(
                    k =>
                    new Tuple <string, Tuple <string, bool> >(k.Value(k.Key.Item2, 1, 10, false).Name,
                                                              new Tuple <string, bool>(k.Key.Item1, k.Key.Item2))));
            ComboBoxCopy.ItemsSource = _conditionNames.Select(s => s.Item1);
            var D = SPDAssets.GenerateLegend(Legend.Height, Mode, InitialConditions.GetTransformation(Mode));

            D.Stretch = Stretch.Fill;

            Legend.Children.Add(D);
            if (condition != null)
            {
                Condition = condition;
            }
        }
예제 #2
0
        private void Left_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SPDAssets.ChangeFont(Box.SelectedItem.ToString());
            Canvas.Children.Clear();
            var D = SPDAssets.GenerateLegend(Canvas.Height, _statecount);

            Canvas.Children.Add(D);
            SPDAssets.ChangeFont(_typeFace);
        }
예제 #3
0
        private void Left_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ChangeColors(Box.SelectedItem as ColorPicking);
            _id = Box.SelectedIndex;
            var D = SPDAssets.GenerateLegend(Canvas.Height, _stateCount);

            Canvas.Children.Clear();
            Canvas.Children.Add(D);
            ChangeColors(Box.Items[Id] as ColorPicking);
        }
예제 #4
0
        private void FinalSave_OnClick(object sender, RoutedEventArgs e)
        {
            FolderBrowserDialog _dialog = new FolderBrowserDialog();
            var dr = _dialog.ShowDialog();

            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                var path = _dialog.SelectedPath;
                SaveImageToFile(path + "//matrix.png",
                                new Image()
                {
                    Source = pointMatrixPick.GenerateImage(0, 0, _width, _height, Canvas.Width, Canvas.Height)
                });
                SaveImageToFile(path + "//legend.png", SPDAssets.GenerateLegend(Legenda.Height, _strategyCount));
                SaveImageToFile(path + "//end.png", new Image()
                {
                    Source = GenerateImage(_spd, 0, 0, _width, _height)
                });
                SaveImageToFile(path + "//start.png", new Image()
                {
                    Source = GenerateImage(_spd, 0, 0, _width, _height, 0)
                });
                SavePlot(PointsModel, path + "//PointsModel.png");
                SavePlot(ChangeModel, path + "//ChangeModel.png");
                SavePlot(SumModel, path + "//SumModel.png");
                SavePlot(CountModel, path + "//CountModel.png");
                XmlTextWriter xml = new XmlTextWriter(path + "//raport.txt", null);
                xml.WriteElementString("Neighbourhood", neighbourhood.ToString());
                xml.WriteElementString("StandardPointCalculation", (!pointMatrixPick.ModifiedPointCounting).ToString());
                for (int i = 0; i < _sumPointsHistory.Count(); i++)
                {
                    xml.WriteStartElement("iteration");
                    xml.WriteElementString("number", i.ToString());
                    for (int j = 0; j < _sumPointsHistory[i].Length; j++)
                    {
                        xml.WriteElementString("strategy", j.ToString());
                        xml.WriteElementString("points", _sumPointsHistory[i][j].ToString());
                    }
                    xml.WriteEndElement();
                }

                xml.Close();
            }
        }
예제 #5
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);
        }