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); } }
public void RunSimulation() { try { this.Invoke(new Action(delegate { _gArea.ResetNodesColor(); tracetxt.Text = ""; })); selected_algorithm = (algorithms.SelectedItem as ComboBoxItem).Tag as ISearchAlgorithm <string>; Node <string> initial = (start_node.SelectedItem as ComboBoxItem).Tag as Node <string>; Node <string> final = (goal_node.SelectedItem as ComboBoxItem).Tag as Node <string>; this.Invoke(new Action(delegate { _gArea.ResetInitialGoal(); _gArea.SetInitialGoal(initial, final); selected_algorithm.Logged = checkBoxX1.Checked; })); selected_algorithm.OnResultFound += Selected_algorithm_OnResultFound; selected_algorithm.OnResetRequired += Selected_algorithm_OnResetRequired; // set event handlers simulation_thread = new Thread(new ThreadStart(delegate { sw.Start(); try { selected_algorithm.Initialize(); var sr = selected_algorithm.Search(initial, final.Key); this.Invoke(new Action(delegate { selected_algorithm.OnResultFound -= Selected_algorithm_OnResultFound; selected_algorithm.OnResetRequired -= Selected_algorithm_OnResetRequired; buttonX1.Text = "Run"; simulation_thread = null; if (sr.Found) { _gArea.ColorizePath(sr, Brushes.Red); TracePath(sr); } this.Invoke(new Action(delegate { tracetxt.AppendText("The path cost is " + selected_algorithm.CalculateCost(sr) + Environment.NewLine); })); MessageBoxEx.Show(this, "Simulation complete", "Simulation", MessageBoxButtons.OK, MessageBoxIcon.Information); })); } catch (Exception ex) { this.Invoke(new Action(delegate { MessageBoxEx.Show(this, ex.Message, "Simulation Process", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); })); } sw.Stop(); this.Invoke(new Action(delegate { tracetxt.AppendText("Elapsed time: " + sw.Elapsed); })); })); simulation_thread.Start(); }catch (Exception ex) { MessageBoxEx.Show(this, ex.Message, "Simulation Execution", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } }