コード例 #1
0
        /// <summary>
        /// Metoda rysująca wykres automatu bądź jego fragment.
        /// </summary>
        /// <param name="spd">Odwołanie do instancji SPD</param>
        /// <param name="x">Współrzedna X lewej górnej komórki wykresu do wyświetlenia</param>
        /// <param name="y">Współrzędna Y lewej górnej komórki wykresu do wyświetlenia</param>
        /// <param name="width">Ile kolumn automatu będzie wyrysowanych</param>
        /// <param name="height">Ile wierszy automatu będzie wyrysowanych</param>
        /// <param name="iteration">Dla której iteracji wygenerować wykres (-1 oznacza najbardziej aktualną)</param>
        /// <returns>Wyrysowany wykres</returns>
        private DrawingImage GenerateImage(SPD.Engine.SPD spd, int x, int y, int width, int height, int iteration = -1)
        {
            var cellWidth  = Canvas.Width / width;
            var cellHeight = Canvas.Height / height;


            var dg = new DrawingGroup();
            var C  = GetStateByIteration(iteration < 0?Iteration:iteration);

            for (var i = x; i < x + width; i++)
            {
                for (var j = y; j < y + height; j++)
                {
                    var rg = new RectangleGeometry(new Rect(new Point((i - x) * cellWidth, (j - y) * cellHeight), new Point((i - x + 1) * cellWidth, (j + 1 - y) * cellHeight)));
                    var c  = new IntegerStrategy(C[i, j].Item1);
                    var gd = new GeometryDrawing
                    {
                        Brush =
                            c.BetrayalThreshold == ToolTipID?new SolidColorBrush(Color.FromRgb(0, 0, 0)):GetBrush(c.BetrayalThreshold),
                        Geometry = rg
                    };
                    dg.Children.Add(gd);
                }
            }
            var result = new DrawingImage(dg);

            return(result);
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: SPDView.xaml.cs プロジェクト: kujawskip/SPD
        /// <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);
        }