Example #1
0
        public ViewResult Index(Comparison model)
        {
            Graph graph = new Graph();
            Fiduccia_Mattheyses_partitioning fmPartitioning = new Fiduccia_Mattheyses_partitioning();
            BeePartitioning beePartitioning = new BeePartitioning();

            List <Graph> graphs = new List <Graph>();

            for (int i = 0; i < 5; i++)
            {
                graph.Generate((4 + (model.step * i)), (3 + (model.step * i)));
                graphs.Add((Graph)graph.Clone());
            }
            var fmDates  = new List <Tuple <long, int> >();
            var beeDates = new List <Tuple <long, int> >();

            //New------------------
            resultTables.Clear();
            //New------------------
            #region Histogram
            foreach (var item in graphs)
            {
                Stopwatch stopwatchFM  = new Stopwatch();
                Stopwatch stopwatchBee = new Stopwatch();

                //Параметри бджолиного алгоритма для створення графіка
                int r;
                if (item.vertices.Count > 20)
                {
                    r = 3;
                }
                else if (item.vertices.Count > 10)
                {
                    r = 2;
                }
                else
                {
                    r = 1;
                }
                stopwatchBee.Start();
                Bee resultBee = beePartitioning.Partitioning(item, 15, 5, 15, r, 10);
                stopwatchBee.Stop();

                stopwatchFM.Start();
                List <Edge> resultFM = fmPartitioning.Partitioning(item);
                stopwatchFM.Stop();

                //New--------------------------------------------
                model.Initialize(resultBee, resultFM);
                resultTables.Add((Comparison)model.Clone());
                //New------------------------------------------

                fmDates.Add(new Tuple <long, int>(stopwatchFM.ElapsedMilliseconds, item.vertices.Count));
                beeDates.Add(new Tuple <long, int>(stopwatchBee.ElapsedMilliseconds, item.vertices.Count));
            }


            var chart = new Chart();
            chart.Width                   = 700;
            chart.Height                  = 400;
            chart.BackColor               = Color.LightYellow;
            chart.BorderlineDashStyle     = ChartDashStyle.Solid;
            chart.BackSecondaryColor      = Color.White;
            chart.BackGradientStyle       = GradientStyle.TopBottom;
            chart.BorderlineWidth         = 1;
            chart.Palette                 = ChartColorPalette.BrightPastel;
            chart.BorderlineColor         = Color.FromArgb(26, 59, 105);
            chart.RenderType              = RenderType.BinaryStreaming;
            chart.BorderSkin.SkinStyle    = BorderSkinStyle.Emboss;
            chart.AntiAliasing            = AntiAliasingStyles.All;
            chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;
            chart.Titles.Add(CreateTitle());
            chart.Legends.Add(CreateLegendFM());
            chart.Legends.Add(CreateLegendBee());
            chart.Series.Add(CreateSeriesFM(fmDates, SeriesChartType.Column, Color.GreenYellow));
            chart.Series.Add(CreateSeriesBee(beeDates, SeriesChartType.Column, Color.DarkRed));
            chart.ChartAreas.Add(CreateChartArea());

            var ms = new MemoryStream();
            chart.SaveImage(ms);
            ViewBag.Image = ms.GetBuffer();
            #endregion
            #region Bee

            var beeDiagram = new List <Tuple <long, int> >();
            int j          = 1;
            foreach (var item in model.diagramDataBee)
            {
                beeDiagram.Add(new Tuple <long, int>(item, j));
                j++;
            }

            var chartBee = new Chart();
            chartBee.Width                   = 700;
            chartBee.Height                  = 400;
            chartBee.BackColor               = Color.LightYellow;
            chartBee.BorderlineDashStyle     = ChartDashStyle.Solid;
            chartBee.BackSecondaryColor      = Color.White;
            chartBee.BackGradientStyle       = GradientStyle.TopBottom;
            chartBee.BorderlineWidth         = 1;
            chartBee.Palette                 = ChartColorPalette.BrightPastel;
            chartBee.BorderlineColor         = Color.FromArgb(26, 59, 105);
            chartBee.RenderType              = RenderType.BinaryStreaming;
            chartBee.BorderSkin.SkinStyle    = BorderSkinStyle.Emboss;
            chartBee.AntiAliasing            = AntiAliasingStyles.All;
            chartBee.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;
            chartBee.Titles.Add(CreateTitleBee());
            chartBee.Series.Add(CreateSeriesBeeDiagram(beeDiagram, SeriesChartType.Line, Color.DarkRed));
            chartBee.ChartAreas.Add(CreateChartAreaBee());

            var msBee = new MemoryStream();
            chartBee.SaveImage(msBee);
            ViewBag.ImageBee = msBee.GetBuffer();
            #endregion
            #region FM
            var fmDiagram = new List <Tuple <long, int> >();
            int k         = 1;
            foreach (var item in model.diagramDataFM)
            {
                fmDiagram.Add(new Tuple <long, int>(item, k));
                k++;
            }

            var chartFM = new Chart();
            chartFM.Width                   = 700;
            chartFM.Height                  = 400;
            chartFM.BackColor               = Color.LightYellow;
            chartFM.BorderlineDashStyle     = ChartDashStyle.Solid;
            chartFM.BackSecondaryColor      = Color.White;
            chartFM.BackGradientStyle       = GradientStyle.TopBottom;
            chartFM.BorderlineWidth         = 1;
            chartFM.Palette                 = ChartColorPalette.BrightPastel;
            chartFM.BorderlineColor         = Color.FromArgb(26, 59, 105);
            chartFM.RenderType              = RenderType.BinaryStreaming;
            chartFM.BorderSkin.SkinStyle    = BorderSkinStyle.Emboss;
            chartFM.AntiAliasing            = AntiAliasingStyles.All;
            chartFM.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;
            chartFM.Titles.Add(CreateTitleFM());
            if (fmDiagram.Count == 1)
            {
                chartFM.Series.Add(CreateSeriesFMDiagram(fmDiagram, SeriesChartType.Point, Color.DarkGreen));
            }
            else
            {
                chartFM.Series.Add(CreateSeriesFMDiagram(fmDiagram, SeriesChartType.Line, Color.DarkGreen));
            }


            chartFM.ChartAreas.Add(CreateChartAreaFM());

            var msFM = new MemoryStream();
            chartFM.SaveImage(msFM);
            ViewBag.ImageFM = msFM.GetBuffer();
            #endregion
            return(View(model));
        }