public ViewResult Example(Solver model) { ///13.05 if (model.ns < 4 || model.ns > 40) { ModelState.AddModelError("ns", "Допустимим є значення від 4 до 40"); } else if (model.mb < 2 || model.mb >= model.ns) { ModelState.AddModelError("mb", "Допустимим є значення від 2 до ns"); } else if (model.nf < model.mb * 2 || model.nf > (model.ns * 5)) { ModelState.AddModelError("nf", "Допустимим є значення від mb*2 до ns*5"); } else if (model.r < 1 || model.r > graph.vertices.Count / 4) { ModelState.AddModelError("r", "Допустимим є значення від 1 до V/4"); } else if (model.stopCount < 1 || model.stopCount > 30) { ModelState.AddModelError("stopCount", "Допустимим є значення від 1 до 30"); } if (ModelState.IsValid) { Fiduccia_Mattheyses_partitioning FM_Partitioning = new Fiduccia_Mattheyses_partitioning(); BeePartitioning beePartitioning = new BeePartitioning(); lastModel.Partition.Clear(); ViewBag.Result = lastModel.Initialize(beePartitioning.Partitioning(graph, model.ns, model.mb, model.nf, model.r, model.stopCount), FM_Partitioning.Partitioning(graph)); ViewBag.BeeSumCut = lastModel.bee_cutWeight; ViewBag.FMSumCut = lastModel.fm_cutWeight; ViewBag.VerticesCount = graph.vertices.Count; ViewBag.EdgesCount = graph.edges.Count; ViewBag.Flag = 1; lastModel.ns = model.ns; lastModel.mb = model.mb; lastModel.nf = model.nf; lastModel.r = model.r; lastModel.stopCount = model.stopCount; } else { if (lastModel.Partition.Count == 0) { lastModel.InitializeGraph(graph); } ViewBag.Result = lastModel.Partition; ViewBag.BeeSumCut = lastModel.bee_cutWeight; ViewBag.FMSumCut = lastModel.fm_cutWeight; ViewBag.VerticesCount = graph.vertices.Count; ViewBag.EdgesCount = graph.edges.Count; ViewBag.Flag = 1; } return(View("Index", model)); }
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)); }
public ViewResult Solver(Solver model) { //New 14.05 17:08 if (model.ns < 4 || model.ns > 40) { ModelState.AddModelError("ns", "Допустимим є значення від 4 до 40"); } else if (model.mb < 2 || model.mb >= model.ns) { ModelState.AddModelError("mb", "Допустимим є значення від 2 до ns"); } else if (model.nf < model.mb * 2 || model.nf > (model.ns * 5)) { ModelState.AddModelError("nf", "Допустимим є значення від mb*2 до ns*5"); } else if (model.r < 1 || model.r > graph.vertices.Count / 4) { ModelState.AddModelError("r", "Допустимим є значення від 1 до V/4"); } else if (model.stopCount < 1 || model.stopCount > 30) { ModelState.AddModelError("stopCount", "Допустимим є значення від 1 до 30"); } if (ModelState.IsValid) { Fiduccia_Mattheyses_partitioning FM_Partitioning = new Fiduccia_Mattheyses_partitioning(); BeePartitioning beePartitioning = new BeePartitioning(); lastModel.Partition.Clear(); model.edgesQuantity = lastModel.edgesQuantity; model.verticesQuantity = lastModel.verticesQuantity; lastModel.ns = model.ns; lastModel.mb = model.mb; lastModel.nf = model.nf; lastModel.r = model.r; lastModel.stopCount = model.stopCount; lastModel.fm_cutWeight = model.fm_cutWeight; lastModel.bee_cutWeight = model.bee_cutWeight; ViewBag.Result = lastModel.Initialize(beePartitioning.Partitioning(graph, model.ns, model.mb, model.nf, model.r, model.stopCount), FM_Partitioning.Partitioning(graph)); ViewBag.BeeSumCut = lastModel.bee_cutWeight; ViewBag.FMSumCut = lastModel.fm_cutWeight; ViewBag.VerticesCount = graph.vertices.Count; ViewBag.EdgesCount = graph.edges.Count; ViewBag.Flag = 2; #region Bee var beeDiagram = new List <Tuple <long, int> >(); int j = 1; foreach (var item in lastModel.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()); 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 lastModel.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()); msFM = new MemoryStream(); chartFM.SaveImage(msFM); ViewBag.ImageFM = msFM.GetBuffer(); #endregion } else { model.edgesQuantity = lastModel.edgesQuantity; model.verticesQuantity = lastModel.verticesQuantity; ViewBag.Result = lastModel.Partition; ViewBag.BeeSumCut = lastModel.bee_cutWeight; ViewBag.FMSumCut = lastModel.fm_cutWeight; ViewBag.VerticesCount = graph.vertices.Count; ViewBag.EdgesCount = graph.edges.Count; ViewBag.Flag = 2; ViewBag.ImageFM = msFM.GetBuffer(); ViewBag.ImageBee = msBee.GetBuffer(); } //New 14.05 17:08 return(View("Index", model)); }