Ejemplo n.º 1
0
 public MainWindow()
 {
     InitializeComponent();
     SimulateButton.IsEnabled = true;
     StopButton.IsEnabled     = false;
     for (int i = 1; i < 4; i++)
     {
         AvgLineChart.SetSeriesVisibility(false, i, false);
     }
     cancelToken = new CancelToken(new CancellationTokenSource());
 }
Ejemplo n.º 2
0
        private async void SimulateButton_OnClick(object sender, RoutedEventArgs e)
        {
            int replications = 0;
            int skipFirst    = 0;

            SimulateButton.IsEnabled = false;
            StopButton.IsEnabled     = true;
            if (!ValidateInput(out replications, out skipFirst))
            {
                SimulateButton.IsEnabled = true;
                StopButton.IsEnabled     = false;
                return;
            }
            AvgLineChart.FreeAxisY();
            averages = new double[4];

            StopButton.Click += (o, args) =>
            {
                cancelToken.Source.Cancel();
            };
            await Task.Run(() =>
            {
                SimulationCore simulation = new NavigationSimulation();
                AvgLineChart.Clear();
                //double lastUpdate = 0;
                simulation.AverageChangedE += (average, replicationN) =>
                {
                    if (replicationN > skipFirst)
                    {
                        // This will give the total number of milliseconds from Jan 1, 00001
                        //if ((new TimeSpan(DateTime.Now.Ticks)).TotalMilliseconds - lastUpdate > 1/60d)
                        if (replications / GRAPHNUMOFDOTS > 1)
                        {
                            if (replicationN % ((replications - skipFirst) / GRAPHNUMOFDOTS) == 0)
                            {
                                for (int i = 0; i < simulation.Average.Count; i++)
                                {
                                    AvgLineChart.AddValue(replicationN, average[i], i);
                                }
                                //lastUpdate = (new TimeSpan(DateTime.Now.Ticks)).TotalMilliseconds;
                            }
                        }
                        else
                        {
                            for (int i = 0; i < simulation.Average.Count; i++)
                            {
                                AvgLineChart.AddValue(replicationN, average[i], i);
                            }
                        }
                    }
                };
                ((NavigationSimulation)simulation).InTimeChangedE += newAverages =>
                {
                    averagePercentInLimit = newAverages;
                };
                simulation.Simulate(replications, cancelToken);
                if (simulation.Average.Count >= 4)
                {
                    averages[0] = simulation.Average[0];
                    averages[1] = simulation.Average[1];
                    averages[2] = simulation.Average[2];
                    averages[3] = simulation.Average[3];
                }
            });

            AvgLineChart.CorrectAxisY();

            DurationTextBlock.Text =
                " A-B-C-D-E => " + averages[0] + " minutes\n A-F-G-E => " + averages[1] + " minutes\n A-F-H-D-E => " + averages[2] +
                " minutes\n A-F-H-C-D-E => " + averages[3] + " minutes\n On time in " + string.Format("{0,8:P4}", GetPercentageForMin());
            SimulateButton.IsEnabled = true;
            StopButton.IsEnabled     = false;

            cancelToken.Source.Dispose();
            cancelToken.Source = new CancellationTokenSource();
        }
Ejemplo n.º 3
0
 private void AFHCDECheckBox_OnUnchecked(object sender, RoutedEventArgs e)
 {
     AvgLineChart?.SetSeriesVisibility(false, 3, true);
 }
Ejemplo n.º 4
0
 private void AFHDECheckBox_OnChecked(object sender, RoutedEventArgs e)
 {
     AvgLineChart?.SetSeriesVisibility(true, 2, true);
 }