예제 #1
0
        public void BenchmarkSimulation()
        {
            try
            {
                benchmarking = true;
                this.Invoke(new Action(delegate
                {
                    _gArea.ResetNodesColor();
                    tracetxt.Text = "";
                }));
                benchmarks.Clear();
                Node <string> initial = (start_node.SelectedItem as ComboBoxItem).Tag as Node <string>;
                Node <string> final   = (goal_node.SelectedItem as ComboBoxItem).Tag as Node <string>;
                initialGraph = ScreenshotGraphView();
                this.Invoke(new Action(delegate
                {
                    _gArea.ResetInitialGoal();
                    _gArea.SetInitialGoal(initial, final);
                }));
                // set event handlers
                simulation_thread = new Thread(new ThreadStart(delegate
                {
                    try
                    {
                        this.Invoke(new Action(delegate
                        {
                            buttonX2.Enabled = false;
                            buttonX1.Enabled = false;
                        }));

                        foreach (var selected_algorithm in salgos)
                        {
                            this.Invoke(new Action(delegate
                            {
                                selected_algorithm.Logged = false;
                            }));
                            selected_algorithm.OnResultFound   += Selected_algorithm_OnResultFound;
                            selected_algorithm.OnResetRequired += Selected_algorithm_OnResetRequired;

                            selected_algorithm.Initialize();
                            current_report           = new SearchReport <string>();
                            SearchResult <string> sr = null;


                            sr = selected_algorithm.Search(initial, final.Key);
                            benchmarks.Add(
                                new KeyValuePair <ISearchAlgorithm <string>, SearchReport <string> >(
                                    selected_algorithm,
                                    current_report));
                            current_report.Result = sr;
                            current_report.Timer.Start();
                            selected_algorithm.SearchClean(initial, final.Key);
                            current_report.Timer.Stop();



                            current_report.Steps.Add(new SearchStep <string>
                            {
                                StepInformation =
                                    new KeyValuePair <INode <string>, NodeVisitAction>(null, NodeVisitAction.Reset)
                            });
                            current_report.ElapsedTime          = current_report.Timer.Elapsed;
                            selected_algorithm.OnResultFound   -= Selected_algorithm_OnResultFound;
                            selected_algorithm.OnResetRequired -= Selected_algorithm_OnResetRequired;
                        }
                        this.Invoke(new Action(delegate
                        {
                            simulation_thread = null;
                            DumpToReport();
                        }));
                    }
                    catch (Exception ex)
                    {
                        this.Invoke(new Action(delegate
                        {
                            MessageBoxEx.Show(this, ex.Message, "Benchmark Simulation Process",
                                              System.Windows.Forms.MessageBoxButtons.OK,
                                              System.Windows.Forms.MessageBoxIcon.Error);
                        }));
                    }
                    this.Invoke(new Action(delegate
                    {
                        buttonX2.Enabled = true;
                        buttonX1.Enabled = true;
                        benchmarking     = false;
                        MessageBoxEx.Show(this, "Benchmark successfully completed", "Benchmark simulation",
                                          MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }));
                }));
                simulation_thread.Start();
                //simulation_thread.Join();
            }
            catch (Exception ex)
            {
                MessageBoxEx.Show(this, ex.Message, "Benchmark Simulation Execution", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
        }