示例#1
0
 internal void ModifyColors()
 {
     for (int i = 0; i < SPDAssets.MAX; i++)
     {
         SPDAssets.ModifyColor(GenerateBrush(i), GenerateOxyColor(i), i);
     }
 }
示例#2
0
 private List <ColumnItem> GenerateColumns(int category, double[] values)
 {
     return(values.Select((t, i) => new ColumnItem(t, category)
     {
         Color = SPDAssets.GetOxyColor(i)
     }).ToList());
 }
示例#3
0
 private void Akceptuj_Click(object sender, RoutedEventArgs e)
 {
     _typeFace = Box.SelectedItem.ToString();
     SPDAssets.ChangeFont(_typeFace);
     DialogResult = true;
     Close();
 }
示例#4
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;
            }
        }
示例#5
0
        private void MenuItemDelete_Click(object sender, RoutedEventArgs e)
        {
            if (MatricesListBox.SelectedIndex == -1)
            {
                return;
            }
            var MatrixDescription = (MatricesListBox.SelectedItems[0] as MatrixDescription);
            var L = Condition.Matrices;
            var M = Condition.Matrices.Where(m => m.ToString() != MatrixDescription.Description).ToList();

            for (int i = 0; i < Condition.Indices.GetLength(0); i++)
            {
                for (int j = 0; j < Condition.Indices.GetLength(1); j++)
                {
                    var I = Condition.Indices[i, j];
                    if (Condition.Matrices[I].ToString() == MatrixDescription.Description)
                    {
                        Condition.Indices[i, j] = 0;
                    }
                    else
                    {
                        Condition.Indices[i, j] = M.FindIndex(m => m.ToString() == L[I].ToString());
                    }
                }
            }
            Condition.Matrices    = M;
            BrushRectangles       = SPDAssets.GetBrushRectangles(MatrixCount);
            _comboBox.ItemsSource = BrushRectangles;
            Condition             = Condition;
        }
示例#6
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);
        }
示例#7
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);
        }
示例#8
0
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            var D = Validate();

            if (D == null)
            {
                MessageBox.Show(MainWindow.ErrorMessages[(int)Error]);
            }
            else
            {
                Condition.Matrices.Add(new PointMatrix((float)D[3], (float)D[2], (float)D[1], (float)D[0]));
                BrushRectangles       = SPDAssets.GetBrushRectangles(MatrixCount);
                _comboBox.ItemsSource = BrushRectangles;
                Condition             = Condition;
            }
        }
示例#9
0
        public MainWindow()
        {
            SPDAssets.CreateBrushes();
            SPDAssets.ChangeFont("Arial");
            SPDAssets.InitialiseDescriptions();
            _colorPicking = ColorPicking.RegularPickingFactory(10);
            InitializeComponent();

            InitialConditions.Initialise();
            ShapeBox.ItemsSource      = Enum.GetValues(typeof(Shape));
            NeighbourBox.ItemsSource  = Enum.GetValues(typeof(Neighbourhoods));
            ShapeBox.SelectedItem     = Shape.Płaski;
            NeighbourBox.SelectedItem = Neighbourhoods.Moore;

            DataContext  = this;
            Error        = ValidationErrors.None;
            _canvalidate = true;
        }
示例#10
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();
            }
        }
示例#11
0
        public DrawingImage GenerateImage(int x, int y, int width, int height, double CanvasWidth, double CanvasHeight)
        {
            var          IC = CreateICFromPick(this);
            var          di = IC.Grid.GenerateImage(x, y, width, height, CanvasWidth, CanvasHeight);
            DrawingGroup dg = di.Drawing as DrawingGroup;

            if (dg == null)
            {
                return(di);
            }
            int h = 20;

            for (int i = 0; i < Matrices.Count; i++)
            {
                RectangleGeometry rg =
                    new RectangleGeometry(new Rect(new Point(0, 10 + CanvasHeight + h * i),
                                                   new Point(10, 10 + CanvasHeight + h * (i + 1))));
                var gd = new GeometryDrawing
                {
                    Brush    = SPDAssets.GetBrush(i),
                    Geometry = rg,
                    Pen      = new Pen(Brushes.Black, 0.5)
                };
                var text = new FormattedText(Matrices[i].ToString(),
                                             CultureInfo.CurrentCulture,
                                             FlowDirection.LeftToRight,
                                             new Typeface(SPDAssets.GetFont()),
                                             10,
                                             Brushes.Black);
                var gd2 = new GeometryDrawing
                {
                    Pen      = new Pen(Brushes.Black, 1),
                    Brush    = Brushes.Black,
                    Geometry = text.BuildGeometry(new Point(11, 10 + (h / 2) + CanvasHeight + h * i))
                };
                dg.Children.Add(gd);
                dg.Children.Add(gd2);
            }
            return(new DrawingImage(dg));
        }
示例#12
0
        internal PointMatrixPicker(PointMatrix matrix, int Size1, int Size2, PointMatrixPick condition = null)
        {
            _condition      = condition ?? PointMatrixPick.SingularMatrixCondition(matrix, Size1, Size2);
            BrushRectangles = SPDAssets.GetBrushRectangles((int)MatrixCount);
            if (Condition.Size != Size)
            {
                _condition = Condition.Resize(Size);
            }
            this.Size1 = Size1;
            this.Size2 = Size2;
            Size       = Math.Max(Size1, Size2);
            InitializeComponent();


            _selectedOperation = Operation.None;

            _comboBox.ItemsSource   = BrushRectangles;
            _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);
            }
            _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);
            _canvalidate             = true;
            Condition = Condition;
        }
示例#13
0
        public DrawingImage GenerateImage(int x, int y, int width, int height, double CanvasWidth, double CanvasHeight, int replace = -1)
        {
            var cellWidth  = CanvasWidth / width;
            var cellHeight = CanvasHeight / height;


            var dg = new DrawingGroup();

            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 gd = new GeometryDrawing
                    {
                        Brush    = CellGrid[i, j].Value == replace?new SolidColorBrush(Color.FromRgb(0, 0, 0)):SPDAssets.GetBrush(this.CellGrid[i, j].Value),
                        Geometry = rg
                    };
                    dg.Children.Add(gd);
                }
            }
            return(new DrawingImage(dg));
        }
示例#14
0
        private void Font_OnClick(object sender, RoutedEventArgs e)
        {
            var fp = new FontPicker(SPDAssets.GetFont(), 2 + GetNeighboursCount((Neighbourhoods)NeighbourBox.SelectedItem, (int)Slider1.Value));

            fp.ShowDialog();
        }
示例#15
0
 private Brush GetBrush(int p)
 {
     return(SPDAssets.GetBrush(p));
 }
示例#16
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);
        }