Example #1
0
        protected override void OnLoad(EventArgs e)
        {
            NetworkSelectBox.Text = "Seleccione Red";
            NetworkSelectBox.Items.Add("Red Simple");
            NetworkSelectBox.Items.Add("Red Media");
            NetworkSelectBox.Items.Add("Red Grande");
            NetworkSelectBox.Items.Add("Red Gigante");
            NetworkSelectBox.Items.Add("Red Masiva");
            NetworkSelectBox.Items.Add("Red Gargantua");

            _formViewer = new Microsoft.Msagl.GraphViewerGdi.GViewer();

            Simulator = new InfectionSimulator(_simulationParameters);

            _formViewer.Graph = Simulator.SetCurrentNetworkSimulation("Red Simple");

            _formViewer.ToolBarIsVisible     = false;
            _formViewer.LayoutEditingEnabled = false;
            ////_formViewer.LayoutEditingEnabled = true;
            ////_formViewer.FitGraphBoundingBox();

            TextBoxAnalysis = ((RichTextBox)this.Controls.Find("AnalysisBox", true).First()).Lines;


            this.SuspendLayout();

            UpdateAnalysisTextBoxes();

            _formViewer.MouseClick += GraphPanel_MouseClick;
            _formViewer.Dock        = System.Windows.Forms.DockStyle.Fill;

            ////busco panel y agrego el viewer
            var panel = this.Controls.Find("GraphPanel", true).First();

            panel.Dock = DockStyle.Fill;
            panel.Controls.Add(_formViewer);

            InfectionChart = new Chart();
            InfectionChart.Series.Clear();

            var resultsPanel = this.Controls.Find("GraphResultsPanel", true).First();

            resultsPanel.Controls.Add(InfectionChart);
            InfectionChart.ChartAreas.Add(new ChartArea());
            InfectionChart.Legends.Add(new Legend("Infected Per Day"));


            this.ResumeLayout();
        }
Example #2
0
        private void Graficar_Infecciosidad_Click(object sender, EventArgs e)
        {
            for (int immunityDays = 12; immunityDays < 13; immunityDays += 4)
            {
                List <double> averageInfectedPerDay = new List <double>();

                Chart experimentResultChart = new Chart();

                System.Drawing.Color[] colors = { System.Drawing.Color.ForestGreen, System.Drawing.Color.Gold, System.Drawing.Color.OrangeRed, System.Drawing.Color.DeepSkyBlue, System.Drawing.Color.Black, System.Drawing.Color.Fuchsia, System.Drawing.Color.SaddleBrown, System.Drawing.Color.DimGray };

                _simulationParameters.VaccinatedRatio = 0;
                _simulationParameters.DaysOfImmunity  = immunityDays;

                for (int k = 6; k < 7; k += 1)
                {
                    _simulationParameters.InfectionChiSquaredFactor = k;

                    for (int i = 0; i < infectionTestDays; i++)
                    {
                        averageInfectedPerDay.Add(0);
                    }

                    var seriesInfected = new System.Windows.Forms.DataVisualization.Charting.Series
                    {
                        Name              = $"K = {k}",
                        Color             = colors[k - 1],
                        IsVisibleInLegend = true,
                        IsXValueIndexed   = true,
                        ChartType         = SeriesChartType.Line,
                        Font              = new Font(FontFamily.GenericMonospace, 50, System.Drawing.FontStyle.Regular),
                    };
                    //seriesInfected.Name
                    //experimentResultChart.Width = 200;
                    //experimentResultChart.Series.Titles
                    //seriesInfected.
                    experimentResultChart.Series.Add(seriesInfected);

                    var a = experimentResultChart.Series[0];

                    for (int i = 0; i < experimentsAmount; i++)
                    {
                        var testSimulator = new InfectionSimulator(_simulationParameters);
                        testSimulator.SetCurrentNetworkSimulation("Red2");
                        testSimulator.InfectRandomNode();

                        for (int j = 0; j < infectionTestDays; j++)
                        {
                            testSimulator.RunIteration();
                        }

                        var iterationInfectedPerDay = testSimulator.GetInfectionAmountHistory();

                        for (int j = 0; j < infectionTestDays; j++)
                        {
                            averageInfectedPerDay[j] += iterationInfectedPerDay[j];
                        }
                    }

                    for (int j = 0; j < infectionTestDays; j++)
                    {
                        averageInfectedPerDay[j] = averageInfectedPerDay[j] / experimentsAmount;

                        experimentResultChart.Series.First(s => s.Name == $"K = {k}").Points
                        .AddXY(j, averageInfectedPerDay[j]);
                    }
                }

                //experimentResultChart.Scale(new SizeF(5, 5));
                experimentResultChart.Size = new Size(1024, 800);

                //experimentResultChart.Series[0].MarkerBorderWidth = 2000;
                var chartArea = new ChartArea();

                chartArea.AxisY.LabelAutoFitStyle  = LabelAutoFitStyles.None;
                chartArea.AxisX.LabelAutoFitStyle  = LabelAutoFitStyles.None;
                chartArea.AxisY.LabelStyle.Font    = new System.Drawing.Font("Trebuchet MS", 15.25F, System.Drawing.FontStyle.Bold);
                chartArea.AxisX.LabelStyle.Font    = new System.Drawing.Font("Trebuchet MS", 15.25F, System.Drawing.FontStyle.Bold);
                chartArea.IsSameFontSizeForAllAxes = true;

                experimentResultChart.ChartAreas.Add(chartArea);
                experimentResultChart.Legends.Add(new Legend("Infected Per Day"));

                experimentResultChart.SaveImage(Environment.CurrentDirectory + $"\\EvaluarOscilacionesK6Y{immunityDays}DiasDeInmunidad.png", ChartImageFormat.Png);
            }

            MessageBox.Show("Se terminaron de guardar los resultados obtenidos");
        }